ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Storage.PerasCertDB.API

Contents

Synopsis

Documentation

data PerasCertDB (m ∷ TypeType) blk Source #

Constructors

PerasCertDB 

Fields

  • addCertWithArrivalTime (ValidatedPerasCert blk) → STM m (m AddPerasCertResult)

    Add a Peras certificate to the database. The STM transaction adds the certificate to the in-memory index, and the resulting m action performs tracing and might perform side-effects in implementations with on-disk storage. The AddPerasCertResult indicates whether the certificate was actually added, or if it was already present.

    NOTE: Use the join . atomically pattern to run both the transaction and the side-effects in sequence.

  • getCertIdsSTM m (Set PerasRoundNo)

    Get the set of all cert IDs currently in the database.

  • getCertsAfterPerasCertTicketNoSTM m (Map PerasCertTicketNo (m (WithArrivalTime (ValidatedPerasCert blk))))

    Get all certs with a ticket number strictly greater than the given one, in ascending order. Unlike getVotesAfter in PerasVoteDB, the resulting map contains m actions to retrieve the certificates, instead of the certificates directly. This is to allow implementation with on-disk storage to retrieve certificates from disk.

  • getWeightSnapshotSTM m (WithFingerprint (PerasWeightSnapshot blk))

    Return the Peras weights in order compare the current selection against potential candidate chains, namely the weights for blocks not older than the current immutable tip. It might contain weights for even older blocks if they have not yet been garbage-collected.

    The Fingerprint is updated every time a new certificate is added, but it stays the same when certificates are garbage-collected.

  • getLatestCertSeenSTM m (Maybe (WithArrivalTime (ValidatedPerasCert blk)))

    This field impacts voting directly because having seen a certificate is a precondition for voting in any round except for the very first one (at origin).

  • garbageCollectSlotNoSTM m (m ())

    Garbage-collect certificates whose target slot is strictly smaller than the given slot number. The STM transaction clears the relevant state from the in-memory index, and the resulting m action performs tracing and might perform side-effects in implementations with on-disk storage.

    NOTE: Use the `join . atomically` pattern to consume its output.

Instances

Instances details
NoThunks (PerasCertDB m blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

data AddPerasCertResult Source #

Instances

Instances details
Generic AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Associated Types

type Rep AddPerasCertResult 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

type Rep AddPerasCertResult = D1 ('MetaData "AddPerasCertResult" "Ouroboros.Consensus.Storage.PerasCertDB.API" "ouroboros-consensus-3.0.1.0-inplace" 'False) (C1 ('MetaCons "AddedPerasCertToDB" 'PrefixI 'False) (U1TypeType) :+: C1 ('MetaCons "PerasCertAlreadyInDB" 'PrefixI 'False) (U1TypeType))
Show AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Eq AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Ord AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

NoThunks AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

type Rep AddPerasCertResult Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

type Rep AddPerasCertResult = D1 ('MetaData "AddPerasCertResult" "Ouroboros.Consensus.Storage.PerasCertDB.API" "ouroboros-consensus-3.0.1.0-inplace" 'False) (C1 ('MetaCons "AddedPerasCertToDB" 'PrefixI 'False) (U1TypeType) :+: C1 ('MetaCons "PerasCertAlreadyInDB" 'PrefixI 'False) (U1TypeType))

data PerasCertTicketNo Source #

A sequence number, incremented every time we receive a new certificate.

Note that we will usually receive certificates monotonically by round number, so round numbers could almost fulfill the role of ticket numbers. However, in certain edge cases (while catching up, or during cooldowns), this might not be true, such as during syncing or during cooldown periods. Therefore, for robustness, we choose to maintain dedicated ticket numbers separately.

Instances

Instances details
Enum PerasCertTicketNo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Show PerasCertTicketNo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Eq PerasCertTicketNo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Ord PerasCertTicketNo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

NoThunks PerasCertTicketNo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.PerasCertDB.API

Invariants

prop_addCertThenGetCertIdsMonadSTM m ⇒ PerasCertDB m blk → WithArrivalTime (ValidatedPerasCert blk) → m Bool Source #

After adding a cert, its round number should be present in getCertIds.

prop_getCertsAfterZeroMonadSTM m ⇒ PerasCertDB m blk → m Bool Source #

getCertsAfter with ticket 0 should return all certs in the database. NOTE: this property is not purely STM.

prop_getCertsAfterMonotonicMonadSTM m ⇒ PerasCertDB m blk → PerasCertTicketNo → m Bool Source #

getCertsAfter returns strictly increasing ticket numbers.

prop_garbageCollectRemovesOldCertsMonadSTM m ⇒ PerasCertDB m blk → SlotNo → m Bool Source #

After garbage collection for slot S, no certs with target slot < S should remain. NOTE: this property is not purely STM.

prop_addCertLatestCertSeenMonotonicMonadSTM m ⇒ PerasCertDB m blk → WithArrivalTime (ValidatedPerasCert blk) → m Bool Source #

After adding a cert, the round number reported by getLatestCertSeen should be greater than or equal to its previous value.

prop_garbageCollectPreservesLatestCertSeen ∷ (MonadSTM m, StandardHash blk) ⇒ PerasCertDB m blk → SlotNo → m Bool Source #

getLatestCertSeen is not affected by garbage collection.