operation

package
v0.43.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2025 License: AGPL-3.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrefixKeyPart added in v0.41.0

func AppendPrefixKeyPart(buf []byte, v any) []byte

AppendPrefixKeyPart appends v in binary prefix format to buf. NOTE: this function needs to be in sync with prefixKeyPartLength.

func BlockExists added in v0.43.0

func BlockExists(r storage.Reader, blockID flow.Identifier) (bool, error)

BlockExists checks whether the block exists in the database. No errors are expected during normal operation.

func BootstrapClusterFinalizedHeight added in v0.43.3

func BootstrapClusterFinalizedHeight(lctx lockctx.Proof, rw storage.ReaderBatchWriter, clusterID flow.ChainID, number uint64) error

BootstrapClusterFinalizedHeight initializes the latest finalized cluster block height for the given cluster.

CAUTION:

  • This function is intended to be called during bootstrapping only. It expects that the height of the latest known finalized cluster block has not yet been persisted.
  • Confirming that no value is already stored and the subsequent write must be atomic to prevent data corruption. Therefore, the caller must acquire the storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed.

No error returns expected during normal operations.

func CommonPrefix added in v0.42.0

func CommonPrefix(startPrefix, endPrefix []byte) []byte

CommonPrefix returns common prefix of startPrefix and endPrefix. The common prefix is used to narrow down the SSTables that BadgerDB's iterator picks up.

func EncodeKeyPart

func EncodeKeyPart(v interface{}) []byte

EncodeKeyPart encodes a value to be used as a part of a key to be stored in storage.

func ExistChunkLocator added in v0.39.1

func ExistChunkLocator(r storage.Reader, locatorID flow.Identifier) (bool, error)

func ExistExecutionResult added in v0.39.4

func ExistExecutionResult(r storage.Reader, blockID flow.Identifier) (bool, error)

ExistExecutionResult checks if the execution node has its OWN Execution Result for the specified block. No errors are expected during normal operation.

func Exists

func Exists(key []byte, keyExists *bool) func(storage.Reader) error

func FinalizeClusterBlock added in v0.43.3

func FinalizeClusterBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier) error

FinalizeClusterBlock finalizes a block in cluster consensus.

func FindHeaders added in v0.43.0

func FindHeaders(r storage.Reader, filter func(header *flow.Header) bool, found *[]flow.Header) error

FindHeaders iterates through all headers, calling `filter` on each, and adding them to the `found` slice if `filter` returned true

func FindHighestAtOrBelow

func FindHighestAtOrBelow(prefix []byte, height uint64, entity interface{}) func(storage.Reader) error

func FindHighestAtOrBelowByPrefix

func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity any) (errToReturn error)

FindHighestAtOrBelowByPrefix is for database entries that are indexed by block height. It is suitable to search keys with the format prefix` + `height` (where "+" denotes concatenation of binary strings). The height is encoded as Big-Endian (entries with numerically smaller height have lexicographically smaller key). The function finds the *highest* key with the given prefix and height equal to or below the given height.

func GetBlockIDsByStatus added in v0.39.2

func GetBlockIDsByStatus(r storage.Reader, blockIDs *[]flow.Identifier,
	targetUploadStatus bool) error

GetBlockIDsByStatus returns all IDs of stored ComputationResult instances.

func GetComputationResultUploadStatus added in v0.39.2

func GetComputationResultUploadStatus(r storage.Reader, blockID flow.Identifier,
	wasUploadCompleted *bool) error

GetComputationResult returns stored ComputationResult instance with given ID.

func HasExecutionForkEvidence added in v0.42.1

func HasExecutionForkEvidence(r storage.Reader) (bool, error)

HasExecutionForkEvidence checks if conflicting seals record exists in the database. No errors are expected during normal operations.

func IndexBlockContainingCollectionGuarantee added in v0.43.0

func IndexBlockContainingCollectionGuarantee(w storage.Writer, collID flow.Identifier, blockID flow.Identifier) error

IndexBlockContainingCollectionGuarantee produces a mapping from the ID of a flow.CollectionGuarantee to the block ID containing this guarantee.

CAUTION:

  • The caller must acquire the lock ??? and hold it until the database write has been committed. TODO: USE LOCK, we want to protect this mapping from accidental overwrites (because the key is not derived from the value via a collision-resistant hash)
  • A collection can be included in multiple *unfinalized* blocks. However, the implementation assumes a one-to-one map from collection ID to a *single* block ID. This holds for FINALIZED BLOCKS ONLY *and* only in the ABSENCE of BYZANTINE collector CLUSTERS (which the mature protocol must tolerate). Hence, this function should be treated as a temporary solution, which requires generalization (one-to-many mapping) for soft finality and the mature protocol.

Expected errors during normal operations: TODO: return storage.ErrAlreadyExists or storage.ErrDataMismatch

func IndexCertifiedBlockByView added in v0.43.0

func IndexCertifiedBlockByView(lctx lockctx.Proof, rw storage.ReaderBatchWriter, view uint64, blockID flow.Identifier) error

IndexCertifiedBlockByView indexes a CERTIFIED block by its view. HotStuff guarantees that there is at most one certified block per view. Note that this does not hold for uncertified proposals, as a byzantine leader might produce multiple proposals for the same view.

CAUTION: The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.

Hence, only certified blocks (i.e. blocks that have received a QC) can be indexed! Returns storage.ErrAlreadyExists if an ID has already been finalized for this view. No other errors are expected during normal operation.

func IndexChunkDataPackByChunkID added in v0.43.3

func IndexChunkDataPackByChunkID(lctx lockctx.Proof, rw storage.ReaderBatchWriter, chunkID flow.Identifier, chunkDataPackID flow.Identifier) error

IndexChunkDataPackByChunkID inserts a mapping from chunk ID to stored chunk data pack ID. It requires the storage.LockIndexChunkDataPackByChunkID lock to be acquired by the caller and held until the write batch has been committed. Returns storage.ErrDataMismatch if a different chunk data pack ID already exists for the given chunk ID.

func IndexClusterBlockByReferenceHeight added in v0.43.0

func IndexClusterBlockByReferenceHeight(lctx lockctx.Proof, w storage.Writer, refHeight uint64, clusterBlockID flow.Identifier) error

IndexClusterBlockByReferenceHeight indexes a cluster block ID by its reference block height. The cluster block ID is included in the key for more efficient traversal. Only finalized cluster blocks should be included in this index. The key looks like: <prefix 0:1><ref_height 1:9><cluster_block_id 9:41>

func IndexClusterBlockHeight added in v0.43.0

func IndexClusterBlockHeight(lctx lockctx.Proof, rw storage.ReaderBatchWriter, clusterID flow.ChainID, height uint64, blockID flow.Identifier) error

IndexClusterBlockHeight indexes a cluster block ID by the cluster ID and block height. The function ensures data integrity by first checking if a block ID already exists for the given cluster and height, and rejecting overwrites with different values. This function is idempotent, i.e. repeated calls with the *initially* indexed value are no-ops.

CAUTION:

  • Confirming that no value is already stored and the subsequent write must be atomic to prevent data corruption. The caller must acquire the storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed.

Expected error returns during normal operations:

func IndexCollectionByTransaction added in v0.43.0

func IndexCollectionByTransaction(lctx lockctx.Proof, w storage.Writer, txID flow.Identifier, collectionID flow.Identifier) error

IndexCollectionByTransaction indexes the given collection ID, keyed by the transaction ID.

CAUTION:

  • The caller must acquire the storage.LockInsertCollection and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

WARNING, this index is NOT BFT in its current form: Honest clusters ensure a transaction can only belong to one collection. However, in rare cases, the collector clusters can exceed byzantine thresholds -- making it possible to produce multiple finalized collections (aka guaranteed collections) containing the same transaction repeatedly. TODO: eventually we need to handle Byzantine clusters

No errors are expected during normal operation.

func IndexCollectionPayload added in v0.39.4

func IndexCollectionPayload(lctx lockctx.Proof, w storage.Writer, clusterBlockID flow.Identifier, txIDs []flow.Identifier) error

IndexCollectionPayload populates the map from a cluster block ID to the batch of transactions it contains.

CAUTION:

  • The caller must acquire the storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexEpochProtocolState added in v0.43.0

func IndexEpochProtocolState(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, epochProtocolStateEntryID flow.Identifier) error

IndexEpochProtocolState indexes an epoch protocol state entry by block ID.

CAUTION:

  • The caller must acquire the lock storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY within this write operation. Currently it's done by operation.InsertHeader where it performs a check to ensure the blockID is new, therefore any data indexed by this blockID is new as well.

No error returns are expected during normal operation.

func IndexExecutionReceipts added in v0.39.4

func IndexExecutionReceipts(w storage.Writer, blockID, receiptID flow.Identifier) error

IndexExecutionReceipts adds the given execution receipts to the set of all known receipts for the given block. It produces a mapping from block ID to the set of all known receipts for that block. One block could have multiple receipts, even if they are from the same executor.

This method is idempotent, and can be called repeatedly with the same block ID and receipt ID, without the risk of data corruption.

No errors are expected during normal operation.

func IndexExecutionResult added in v0.39.4

func IndexExecutionResult(w storage.Writer, blockID flow.Identifier, resultID flow.Identifier) error

IndexExecutionResult indexes the Execution Node's OWN Execution Result by the executed block's ID.

CAUTION:

  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption.

TODO: USE LOCK, we want to protect this mapping from accidental overwrites (because the key is not derived from the value via a collision-resistant hash)

No errors are expected during normal operation.

func IndexFinalizedBlockByHeight added in v0.43.0

func IndexFinalizedBlockByHeight(lctx lockctx.Proof, rw storage.ReaderBatchWriter, height uint64, blockID flow.Identifier) error

IndexFinalizedBlockByHeight indexes a block by its height. It must ONLY be called on FINALIZED BLOCKS.

CAUTION: The caller must acquire the storage.LockFinalizeBlock and hold it until the database write has been committed.

This function guarantees that the index is only inserted once for each height. We return storage.ErrAlreadyExists if an entry for the given height already exists in the database. No other errors are expected during normal operation.

func IndexFinalizedSealByBlockID added in v0.43.0

func IndexFinalizedSealByBlockID(w storage.Writer, sealedBlockID flow.Identifier, sealID flow.Identifier) error

IndexFinalizedSealByBlockID indexes the _finalized_ seal by the sealed block ID. Example: A <- B <- C(SealA) when block C is finalized, we create the index `A.ID->SealA.ID`

CAUTION:

  • The caller must acquire the storage.LockFinalizeBlock and hold it until the database write has been committed. TODO: add lock proof as input and check for holding the lock in the implementation
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexGuarantee added in v0.43.0

func IndexGuarantee(lctx lockctx.Proof, rw storage.ReaderBatchWriter, collectionID flow.Identifier, guaranteeID flow.Identifier) error

IndexGuarantee inserts a flow.CollectionGuarantee into the database, keyed by the collection ID.

Expected errors during normal operations:

func IndexLatestSealAtBlock added in v0.43.0

func IndexLatestSealAtBlock(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, sealID flow.Identifier) error

IndexLatestSealAtBlock persists the highest seal that was included in the fork with head blockID. Frequently, the highest seal included in this block's payload. However, if there are no seals in this block, sealID should reference the highest seal in blockID's ancestors.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexNewBlock added in v0.43.3

func IndexNewBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, parentID flow.Identifier) error

IndexNewBlock populates the parent-child index for block, by adding the given blockID to the set of children of its parent.

CAUTION:

  • This function should only be used for KNOWN BLOCKs (neither existence of the block nor its parent is verified here)
  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.

Expected error returns during normal operations:

func IndexNewClusterBlock added in v0.43.3

func IndexNewClusterBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, parentID flow.Identifier) error

IndexNewClusterBlock populates the parent-child index for cluster blocks, aka collections, by adding the given blockID to the set of children of its parent.

CAUTION:

  • This function should only be used for KNOWN BLOCKs (neither existence of the block nor its parent is verified here)
  • The caller must acquire the storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed.

Expected error returns during normal operations:

func IndexOwnExecutionReceipt added in v0.39.4

func IndexOwnExecutionReceipt(w storage.Writer, blockID flow.Identifier, receiptID flow.Identifier) error

IndexOwnExecutionReceipt indexes the Execution Node's OWN execution receipt by the executed block ID.

CAUTION:

  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The caller is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexPayloadGuarantees added in v0.43.0

func IndexPayloadGuarantees(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, guarIDs []flow.Identifier) error

IndexPayloadGuarantees indexes the list of collection guarantees that were included in the specified block, keyed by the block ID. It produces a mapping from block ID to the list of collection guarantees contained in the block's payload. The collection guarantees are represented by their respective IDs.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors expected during normal operations.

func IndexPayloadProtocolStateID added in v0.43.0

func IndexPayloadProtocolStateID(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, stateID flow.Identifier) error

IndexPayloadProtocolStateID indexes the given Protocol State ID by the block ID. The Protocol State ID represents the configuration, which the block proposes to become active *after* the block's certification. Every block states the ID of the Protocol State it proposes as part of the payload.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexPayloadReceipts added in v0.43.0

func IndexPayloadReceipts(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, receiptIDs []flow.Identifier) error

IndexPayloadReceipts indexes the list of Execution Receipts that were included in the specified block by the block ID. It produces a mapping from block ID to the list of Receipts contained in the block's payload. Execution Receipts are represented by their respective IDs.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexPayloadResults added in v0.43.0

func IndexPayloadResults(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, resultIDs []flow.Identifier) error

IndexPayloadResults indexes the list of Execution Results that were included in the specified block by the block ID. It produces a mapping from block ID to the list of Results contained in the block's payload. Execution Results are represented by their respective IDs.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexPayloadSeals added in v0.43.0

func IndexPayloadSeals(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, sealIDs []flow.Identifier) error

IndexPayloadSeals indexes the list of Seals that were included in the specified block by the block ID. It produces a mapping from block ID to the list of seals contained in the block's payload. The seals are represented by their respective IDs.

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors are expected during normal operation.

func IndexProtocolKVStore added in v0.43.0

func IndexProtocolKVStore(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, protocolKVStoreID flow.Identifier) error

IndexProtocolKVStore indexes a protocol KV store by block ID.

CAUTION:

  • The caller must acquire the lock storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY within this write operation. Currently it's done by operation.InsertHeader where it performs a check to ensure the blockID is new, therefore any data indexed by this blockID is new as well.

Expected error returns during normal operations:

func IndexReferenceBlockByClusterBlock added in v0.43.0

func IndexReferenceBlockByClusterBlock(lctx lockctx.Proof, w storage.Writer, clusterBlockID, refID flow.Identifier) error

IndexReferenceBlockByClusterBlock updates the reference block ID for the given cluster block ID. While each cluster block specifies a reference block in its payload, we maintain this additional lookup for performance reasons.

func IndexScheduledTransactionBlockID added in v0.43.3

func IndexScheduledTransactionBlockID(lctx lockctx.Proof, rw storage.ReaderBatchWriter, txID flow.Identifier, blockID flow.Identifier) error

IndexScheduledTransactionBlockID indexes the scheduled transaction's block ID by its transaction ID.

Expected error returns during normal operation:

func IndexScheduledTransactionID added in v0.43.3

func IndexScheduledTransactionID(lctx lockctx.Proof, rw storage.ReaderBatchWriter, scheduledTxID uint64, txID flow.Identifier) error

IndexScheduledTransactionID indexes the scheduled transaction's transaction ID by its scheduled transaction ID.

Expected error returns during normal operation:

func IndexStateCommitment added in v0.39.4

func IndexStateCommitment(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, commit flow.StateCommitment) error

IndexStateCommitment indexes a state commitment by the block ID whose execution results in that state. The function ensures data integrity by first checking if a commitment already exists for the given block and rejecting overwrites with different values. This function is idempotent, i.e. repeated calls with the *initially* indexed value are no-ops.

CAUTION:

  • Confirming that no value is already stored and the subsequent write must be atomic to prevent data corruption. The caller must acquire the storage.LockInsertOwnReceipt and hold it until the database write has been committed.

Expected error returns during normal operations:

func IndexTransactionResult added in v0.39.4

func IndexTransactionResult(w storage.Writer, blockID flow.Identifier, txIndex uint32, transactionResult *flow.TransactionResult) error

func IndexVersionBeaconByHeight added in v0.39.2

func IndexVersionBeaconByHeight(
	w storage.Writer,
	beacon *flow.SealedVersionBeacon,
) error

IndexVersionBeaconByHeight stores a sealed version beacon indexed by flow.SealedVersionBeacon.SealHeight.

No errors are expected during normal operation.

func InsertAndIndexLightTransactionResults added in v0.43.3

func InsertAndIndexLightTransactionResults(
	lctx lockctx.Proof, rw storage.ReaderBatchWriter,
	blockID flow.Identifier,
	transactionResults []flow.LightTransactionResult,
) error

InsertAndIndexLightTransactionResults persists and indexes all transaction results (light representation) for the given blockID as part of the provided batch. The caller must acquire storage.LockInsertLightTransactionResult and hold it until the write batch has been committed. It returns storage.ErrAlreadyExists if light transaction results for the block already exist.

func InsertAndIndexResultApproval added in v0.43.0

func InsertAndIndexResultApproval(approval *flow.ResultApproval) func(lctx lockctx.Proof, rw storage.ReaderBatchWriter) error

InsertAndIndexResultApproval atomically performs the following storage operations:

  1. Store ResultApproval by its ID (in this step, accidental overwrites with inconsistent values are prevented by using a collision-resistant hash to derive the key from the value)
  2. Index approval by the executed chunk, specifically the key pair (ExecutionResultID, chunk index). - first, we ensure that no _different_ approval has already been indexed for the same key pair - only if the prior check succeeds, we write the index to the database

CAUTION:

  • In general, the Flow protocol requires multiple approvals for the same chunk from different verification nodes. In other words, there are multiple different approvals for the same chunk. Therefore, this index Executed Chunk ➜ ResultApproval ID is *only safe* to be used by Verification Nodes for tracking their own approvals (for the same ExecutionResult, a Verifier will always produce the same approval)
  • In order to make sure only one approval is indexed for the chunk, _all calls_ to `InsertAndIndexResultApproval` must be synchronized by the higher-logic. Currently, we have the lockctx.Proof to prove the higher logic is holding the lock inserting the approval after checking that the approval is not already indexed.

Expected error returns:

  • `storage.ErrDataMismatch` if a *different* approval for the same key pair (ExecutionResultID, chunk index) is already indexed

func InsertAndIndexTransactionResultErrorMessages added in v0.43.3

func InsertAndIndexTransactionResultErrorMessages(
	lctx lockctx.Proof, rw storage.ReaderBatchWriter,
	blockID flow.Identifier,
	transactionResultErrorMessages []flow.TransactionResultErrorMessage,
) error

InsertAndIndexTransactionResultErrorMessages persists and indexes all transaction result error messages for the given blockID as part of the provided batch. The caller must acquire storage.LockInsertTransactionResultErrMessage and hold it until the write batch has been committed. It returns storage.ErrAlreadyExists if tx result error messages for the block already exist.

func InsertChunkDataPack

func InsertChunkDataPack(rw storage.ReaderBatchWriter, storeChunkDataPackID flow.Identifier, c *storage.StoredChunkDataPack) error

InsertChunkDataPack inserts a storage.StoredChunkDataPack into the database, keyed by its own ID.

CAUTION: The caller must ensure `storeChunkDataPackID` is the same as `c.ID()`, ie. a collision-resistant hash of the chunk data pack! This method silently overrides existing data, which is safe only if for the same key, we always write the same value.

No error returns expected during normal operations.

func InsertChunkLocator added in v0.39.1

func InsertChunkLocator(w storage.Writer, locator *chunks.Locator) error

func InsertClusterBlock added in v0.43.3

func InsertClusterBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, proposal *cluster.Proposal) error

InsertClusterBlock inserts a cluster consensus block, updating all associated indexes.

CAUTION:

  • The caller must acquire the lock storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed. This lock allows `InsertClusterBlock` to verify that this block has not yet been indexed. In order to protect against accidental mutation of existing data, this read and subsequent writes must be performed as one atomic operation. Hence, the requirement to hold the lock until the write is committed.

We return storage.ErrAlreadyExists if the block has already been persisted before, i.e. we only insert a block once. This error allows the caller to detect duplicate inserts. No other errors are expected during normal operation.

func InsertClusterPayload added in v0.43.3

func InsertClusterPayload(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, payload *cluster.Payload) error

InsertClusterPayload inserts the payload for a cluster block. It inserts both the collection and all constituent transactions, allowing duplicates.

func InsertEpochCommit added in v0.43.0

func InsertEpochCommit(w storage.Writer, eventID flow.Identifier, event *flow.EpochCommit) error

func InsertEpochFirstHeight added in v0.43.0

func InsertEpochFirstHeight(lctx lockctx.Proof, rw storage.ReaderBatchWriter, epoch, height uint64) error

InsertEpochFirstHeight inserts the height of the first block in the given epoch. The first block of an epoch E is the finalized block with view >= E.FirstView. Although we don't store the final height of an epoch, it can be inferred from this index. The caller must hold storage.LockFinalizeBlock. This function enforces each index is written exactly once. Returns storage.ErrAlreadyExists if the height has already been indexed.

func InsertEpochProtocolState added in v0.43.0

func InsertEpochProtocolState(w storage.Writer, entryID flow.Identifier, entry *flow.MinEpochStateEntry) error

InsertEpochProtocolState inserts an epoch protocol state entry by ID. Error returns:

  • generic error in case of unexpected failure from the database layer or encoding failure.

func InsertEpochSetup added in v0.43.0

func InsertEpochSetup(w storage.Writer, eventID flow.Identifier, event *flow.EpochSetup) error

func InsertEvent added in v0.39.4

func InsertEvent(w storage.Writer, blockID flow.Identifier, event flow.Event) error

func InsertExecutionForkEvidence added in v0.42.1

func InsertExecutionForkEvidence(lctx lockctx.Proof, rw storage.ReaderBatchWriter, conflictingSeals []*flow.IncorporatedResultSeal) error

InsertExecutionForkEvidence upserts conflicting seals to the database. If a record already exists, it is NOT overwritten, the new record is ignored. The caller must hold the storage.LockInsertExecutionForkEvidence lock. No errors are expected during normal operations.

func InsertExecutionReceiptStub added in v0.43.0

func InsertExecutionReceiptStub(w storage.Writer, receiptID flow.Identifier, meta *flow.ExecutionReceiptStub) error

InsertExecutionReceiptStub inserts a flow.ExecutionReceiptStub into the database, keyed by its ID.

CAUTION: The caller must ensure receiptID is a collision-resistant hash of the provided flow.ExecutionReceiptMeta! This method silently overrides existing data, which is safe only if for the same key, we always write the same value.

func InsertExecutionResult added in v0.39.4

func InsertExecutionResult(w storage.Writer, result *flow.ExecutionResult) error

InsertExecutionResult inserts a flow.ExecutionResult into the storage, keyed by its ID.

If the result already exists, it will be overwritten. Note that here, the key (result ID) is derived from the value (result) via a collision-resistant hash function. Hence, unchecked overwrites pose no risk of data corruption, because for the same key, we expect the same value.

No errors are expected during normal operation.

func InsertExecutionStateInteractions added in v0.39.4

func InsertExecutionStateInteractions(
	w storage.Writer,
	blockID flow.Identifier,
	executionSnapshots []*snapshot.ExecutionSnapshot,
) error

func InsertGuarantee added in v0.43.0

func InsertGuarantee(w storage.Writer, guaranteeID flow.Identifier, guarantee *flow.CollectionGuarantee) error

InsertGuarantee inserts a collection guarantee by ID.

CAUTION: The caller must ensure guaranteeID is a collision-resistant hash of the provided guarantee! This method silently overrides existing data, which is safe only if for the same key, we always write the same value.

No errors expected during normal operations.

func InsertHeader added in v0.43.0

func InsertHeader(lctx lockctx.Proof, rw storage.ReaderBatchWriter, headerID flow.Identifier, header *flow.Header) error

InsertHeader inserts a block header into the database.

CAUTION:

  • The caller must ensure that headerID is a collision-resistant hash of the provided header! Otherwise, data corruption may occur.
  • The caller must acquire one (but not both) of the following locks and hold it until the database write has been committed: either storage.LockInsertBlock or storage.LockInsertOrFinalizeClusterBlock.

It returns storage.ErrAlreadyExists if the header already exists, i.e. we only insert a new header once. This error allows the caller to detect duplicate inserts. If the header is stored along with other parts of the block in the same batch, similar duplication checks can be skipped for storing other parts of the block. No other errors are expected during normal operation.

func InsertIndex added in v0.43.3

func InsertIndex(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, index *flow.Index) error

InsertIndex persists the given index keyed by the block ID

CAUTION:

  • The caller must acquire the storage.LockInsertBlock and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): This method silently overrides existing data without any sanity checks whether data for the same key already exits. Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation.

No errors expected during normal operations.

func InsertInstanceParams added in v0.43.0

func InsertInstanceParams(lctx lockctx.Proof, rw storage.ReaderBatchWriter, params flow.VersionedInstanceParams) error

InsertInstanceParams stores the consolidated instance params under a single key.

CAUTION:

  • This function is intended to be called exactly once during bootstrapping. Overwrites are prevented by an explicit existence check; if data is already present, error is returned.
  • To guarantee atomicity of existence-check plus database write, we require the caller to acquire the storage.LockBootstrapping lock and hold it until the database write has been committed.

Expected errors during normal operations:

func InsertJobAtIndex added in v0.39.1

func InsertJobAtIndex(w storage.Writer, queue string, index uint64, entity flow.Identifier) error

InsertJobAtIndex insert an entity ID at the given index

func InsertProposalSignature added in v0.43.0

func InsertProposalSignature(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, sig *[]byte) error

InsertProposalSignature inserts a proposal signature by block ID.

CAUTION:

  • The caller must acquire either the lock storage.LockInsertBlock or storage.LockInsertOrFinalizeClusterBlock (but not both) and hold it until the database write has been committed.
  • OVERWRITES existing data (potential for data corruption): The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere ATOMICALLY with this write operation. It is intended that this function is called only for new blocks, i.e. no signature was previously persisted for it.

No errors are expected during normal operation.

func InsertProtocolKVStore added in v0.43.0

func InsertProtocolKVStore(rw storage.ReaderBatchWriter, protocolKVStoreID flow.Identifier, kvStore *flow.PSKeyValueStoreData) error

InsertProtocolKVStore inserts a protocol KV store by protocol kv store ID. This function can be called, and does not require the caller to hold any lock proof, but the caller must ensure the protocolKVStoreID is the hash of the given kvStore, This is currently true, see makeVersionedModelID in state/protocol/protocol_state/kvstore/models.go No expected error returns during normal operations.

func InsertQuorumCertificate added in v0.43.0

func InsertQuorumCertificate(lctx lockctx.Proof, rw storage.ReaderBatchWriter, qc *flow.QuorumCertificate) error

InsertQuorumCertificate atomically performs the following storage operations for the given QuorumCertificate [QC]:

  1. Check if a QC certifying the same block is already stored.
  2. Only if no QC exists for the block, append the storage operations for indexing the QC by the block ID it certifies.

CAUTION:

  • For the same block, different QCs can easily be constructed by selecting different sub-sets of the received votes. In most cases, it is only important that a block has been certified, but it is irrelevant who specifically contributed to the QC. Therefore, we only store the first QC.
  • In order to make sure only one QC is stored per block, _all calls_ to `InsertQuorumCertificate` must be synchronized by the higher-logic. Currently, we have the lockctx.Proof to prove the higher logic is holding the storage.LockInsertBlock when inserting the QC after checking that no QC is already stored.

Expected error returns:

func InsertSeal added in v0.43.0

func InsertSeal(w storage.Writer, sealID flow.Identifier, seal *flow.Seal) error

InsertSeal inserts a flow.Seal into the database, keyed by its ID.

CAUTION: The caller must ensure sealID is a collision-resistant hash of the provided seal! This method silently overrides existing data, which is safe only if for the same key, we always write the same value.

No errors are expected during normal operation.

func InsertServiceEvent added in v0.39.4

func InsertServiceEvent(w storage.Writer, blockID flow.Identifier, event flow.Event) error

func InsertTransactionResult added in v0.39.4

func InsertTransactionResult(w storage.Writer, blockID flow.Identifier, transactionResult *flow.TransactionResult) error

func Iterate

func Iterate(startPrefix []byte, endPrefix []byte, check func(key []byte) error) func(storage.Reader) error

func IterateKeys

func IterateKeys(r storage.Reader, startPrefix []byte, endPrefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) (errToReturn error)

IterateKeys will iterate over all entries in the database, where the key starts with a prefixes in the range [startPrefix, endPrefix] (both inclusive). No errors expected during normal operations.

func IterateKeysByPrefixRange

func IterateKeysByPrefixRange(r storage.Reader, startPrefix []byte, endPrefix []byte, check func(key []byte) error) error

IterateKeysByPrefixRange will iterate over all entries in the database, where the key starts with a prefixes in the range [startPrefix, endPrefix] (both inclusive). We require that startPrefix <= endPrefix (otherwise this function errors). On every such key, the `check` function is called. If `check` errors, iteration is aborted. In other words, error returned by the iteration functions will be propagated to the caller. No errors expected during normal operations.

func KeyExists

func KeyExists(r storage.Reader, key []byte) (exist bool, errToReturn error)

KeyExists returns true if a key exists in the database. When this returned function is executed (and only then), it will write into the `keyExists` whether the key exists. No errors are expected during normal operation.

func LookupBlockContainingCollectionGuarantee added in v0.43.0

func LookupBlockContainingCollectionGuarantee(r storage.Reader, collID flow.Identifier, blockID *flow.Identifier) error

LookupBlockContainingCollectionGuarantee retrieves the block containing the flow.CollectionGuarantee with the given ID.

CAUTION: A collection can be included in multiple *unfinalized* blocks. However, the implementation assumes a one-to-one map from collection ID to a *single* block ID. This holds for FINALIZED BLOCKS ONLY *and* only in the ABSENCE of BYZANTINE collector CLUSTERS (which the mature protocol must tolerate). Hence, this function should be treated as a temporary solution, which requires generalization (one-to-many mapping) for soft finality and the mature protocol.

Expected errors during normal operations:

func LookupBlockHeight added in v0.43.0

func LookupBlockHeight(r storage.Reader, height uint64, blockID *flow.Identifier) error

LookupBlockHeight retrieves finalized blocks by height. Expected errors during normal operations:

func LookupBySealedBlockID added in v0.43.0

func LookupBySealedBlockID(r storage.Reader, blockID flow.Identifier, sealID *flow.Identifier) error

LookupBySealedBlockID returns the finalized seal for the specified FINALIZED block ID. In order for a block to have a seal in a finalized block, it must itself be finalized. Hence, this function only works for finalized blocks. However, note that there might be finalized for which no seal exits (or the block containing the seal might not yet be finalized).

Expected errors during normal operations:

func LookupCertifiedBlockByView added in v0.43.0

func LookupCertifiedBlockByView(r storage.Reader, view uint64, blockID *flow.Identifier) error

LookupCertifiedBlockByView retrieves the certified block by view. (Certified blocks are blocks that have received QC.) Expected errors during normal operations:

func LookupClusterBlockHeight added in v0.43.0

func LookupClusterBlockHeight(r storage.Reader, clusterID flow.ChainID, height uint64, blockID *flow.Identifier) error

LookupClusterBlockHeight retrieves the ID of a finalized cluster block at the given height produced by the specified cluster. Note that only finalized cluster blocks are indexed by height to guarantee uniqueness.

Expected error returns during normal operations:

  • storage.ErrNotFound if no finalized block from the specified cluster is known at the given height

func LookupClusterBlocksByReferenceHeightRange added in v0.43.0

func LookupClusterBlocksByReferenceHeightRange(lctx lockctx.Proof, r storage.Reader, start, end uint64, clusterBlockIDs *[]flow.Identifier) error

LookupClusterBlocksByReferenceHeightRange traverses the ref_height->cluster_block index and returns any finalized cluster blocks which have a reference block with height in the given range. This is used to avoid including duplicate transaction when building or validating a new collection.

func LookupCollectionByTransaction added in v0.41.0

func LookupCollectionByTransaction(r storage.Reader, txID flow.Identifier, collectionID *flow.Identifier) error

LookupCollectionByTransaction retrieves the collection ID for the collection that contains the specified transaction. For every known transaction, this index should be populated.

WARNING, this index is NOT BFT in its current form: Honest clusters ensure a transaction can only belong to one collection. However, in rare cases, the collector clusters can exceed byzantine thresholds -- making it possible to produce multiple finalized collections (aka guaranteed collections) containing the same transaction repeatedly.

Expected errors during normal operations:

func LookupCollectionPayload added in v0.39.4

func LookupCollectionPayload(r storage.Reader, clusterBlockID flow.Identifier, txIDs *[]flow.Identifier) error

LookupCollectionPayload retrieves the list of transaction IDs that constitute the payload of the specified cluster block. For every known cluster block, this index should be populated.

Expected errors during normal operations:

func LookupEpochProtocolState added in v0.43.0

func LookupEpochProtocolState(r storage.Reader, blockID flow.Identifier, epochProtocolStateEntryID *flow.Identifier) error

LookupEpochProtocolState finds an epoch protocol state entry ID by block ID. Error returns:

  • storage.ErrNotFound if the key does not exist in the database

func LookupEventsByBlockID added in v0.39.4

func LookupEventsByBlockID(r storage.Reader, blockID flow.Identifier, events *[]flow.Event) error

func LookupEventsByBlockIDEventType added in v0.39.4

func LookupEventsByBlockIDEventType(r storage.Reader, blockID flow.Identifier, eventType flow.EventType, events *[]flow.Event) error

func LookupExecutionReceipts added in v0.39.4

func LookupExecutionReceipts(r storage.Reader, blockID flow.Identifier, receiptIDs *[]flow.Identifier) error

LookupExecutionReceipts retrieves the set of all execution receipts for the specified block. For every known block (at or above the root block height), this index should be populated with all known receipts for that block.

Expected errors during normal operations:

func LookupExecutionResult added in v0.39.4

func LookupExecutionResult(r storage.Reader, blockID flow.Identifier, resultID *flow.Identifier) error

LookupExecutionResult retrieves the Execution Node's OWN Execution Result ID for the specified block. Intended for Execution Node only. For every block executed by this node, this index should be populated.

Expected errors during normal operations:

func LookupGuarantee added in v0.43.0

func LookupGuarantee(r storage.Reader, collectionID flow.Identifier, guaranteeID *flow.Identifier) error

LookupGuarantee finds collection guarantee ID by collection ID. Error returns:

  • storage.ErrNotFound if the key does not exist in the database
  • All other errors have to be treated as unexpected failures from the database layer.

func LookupLastVersionBeaconByHeight added in v0.39.2

func LookupLastVersionBeaconByHeight(
	r storage.Reader,
	maxHeight uint64,
	versionBeacon *flow.SealedVersionBeacon,
) error

Returns storage.ErrNotFound if no version beacon exists at or below the given height.

func LookupLatestSealAtBlock added in v0.43.0

func LookupLatestSealAtBlock(r storage.Reader, blockID flow.Identifier, sealID *flow.Identifier) error

LookupLatestSealAtBlock finds the highest seal that was included in the fork up to (and including) blockID. Frequently, the highest seal included in this block's payload. However, if there are no seals in this block, sealID should reference the highest seal in blockID's ancestors.

Expected errors during normal operations:

func LookupLightTransactionResultsByBlockIDUsingIndex added in v0.39.4

func LookupLightTransactionResultsByBlockIDUsingIndex(r storage.Reader, blockID flow.Identifier, txResults *[]flow.LightTransactionResult) error

LookupLightTransactionResultsByBlockIDUsingIndex retrieves all tx results for the specified block. CAUTION: this function returns the empty list in case for block IDs without known results. No error returns are expected during normal operations.

func LookupOwnExecutionReceipt added in v0.39.4

func LookupOwnExecutionReceipt(r storage.Reader, blockID flow.Identifier, receiptID *flow.Identifier) error

LookupOwnExecutionReceipt retrieves the Execution Node's OWN execution receipt ID for the specified block. Intended for Execution Node only. For every block executed by this node, this index should be populated.

Expected errors during normal operations:

func LookupPayloadGuarantees added in v0.43.0

func LookupPayloadGuarantees(r storage.Reader, blockID flow.Identifier, guarIDs *[]flow.Identifier) error

LookupPayloadGuarantees retrieves the list of guarantee IDs that were included in the payload of the specified block. For every known block (at or above the root block height), this index should be populated.

Expected errors during normal operations:

  • storage.ErrNotFound if `blockID` does not refer to a known block
  • All other errors have to be treated as unexpected failures from the database layer.

func LookupPayloadProtocolStateID added in v0.43.0

func LookupPayloadProtocolStateID(r storage.Reader, blockID flow.Identifier, stateID *flow.Identifier) error

LookupPayloadProtocolStateID retrieves the Protocol State ID for the specified block. The Protocol State ID represents the configuration, which the block proposes to become active *after* the block's certification. For every known block (at or above the root block height), the protocol state at the end of the block should be specified in the payload, and hence be indexed. Expected errors during normal operations:

func LookupPayloadReceipts added in v0.43.0

func LookupPayloadReceipts(r storage.Reader, blockID flow.Identifier, receiptIDs *[]flow.Identifier) error

LookupPayloadReceipts retrieves the list of Execution Receipts that were included in the payload of the specified block. For every known block (at or above the root block height), this index should be populated. Expected errors during normal operations:

func LookupPayloadResults added in v0.43.0

func LookupPayloadResults(r storage.Reader, blockID flow.Identifier, resultIDs *[]flow.Identifier) error

LookupPayloadResults retrieves the list of Execution Results that were included in the payload of the specified block. For every known block (at or above the root block height), this index should be populated. Expected errors during normal operations:

func LookupPayloadSeals added in v0.43.0

func LookupPayloadSeals(r storage.Reader, blockID flow.Identifier, sealIDs *[]flow.Identifier) error

LookupPayloadSeals retrieves the list of Seals that were included in the payload of the specified block. For every known block (at or above the root block height), this index should be populated.

Expected errors during normal operations:

func LookupProtocolKVStore added in v0.43.0

func LookupProtocolKVStore(r storage.Reader, blockID flow.Identifier, protocolKVStoreID *flow.Identifier) error

LookupProtocolKVStore finds protocol KV store ID by block ID. Expected error returns during normal operations:

func LookupReferenceBlockByClusterBlock added in v0.43.0

func LookupReferenceBlockByClusterBlock(r storage.Reader, clusterBlockID flow.Identifier, refID *flow.Identifier) error

LookupReferenceBlockByClusterBlock looks up the reference block ID for the given cluster block ID. While each cluster block specifies a reference block in its payload, we maintain this additional lookup for performance reasons.

func LookupResultApproval

func LookupResultApproval(r storage.Reader, resultID flow.Identifier, chunkIndex uint64, approvalID *flow.Identifier) error

LookupResultApproval finds a ResultApproval by result ID and chunk index. Returns `storage.ErrNotFound` if no Approval for the given key (resultID, chunkIndex) has been stored.

NOTE that the Flow protocol requires multiple approvals for the same chunk from different verification nodes. In other words, there are multiple different approvals for the same chunk. Therefore, the index Executed Chunk ➜ ResultApproval ID (queried here) is *only safe* to be used by Verification Nodes for tracking their own approvals (for the same ExecutionResult, a Verifier will always produce the same approval)

func LookupServiceEventsByBlockID added in v0.39.4

func LookupServiceEventsByBlockID(r storage.Reader, blockID flow.Identifier, events *[]flow.Event) error

func LookupStateCommitment added in v0.39.4

func LookupStateCommitment(r storage.Reader, blockID flow.Identifier, commit *flow.StateCommitment) error

LookupStateCommitment retrieves a state commitment by the block ID whose execution results in that state. Expected error returns during normal operations:

func LookupTransactionResultErrorMessagesByBlockIDUsingIndex added in v0.39.4

func LookupTransactionResultErrorMessagesByBlockIDUsingIndex(r storage.Reader, blockID flow.Identifier, txResultErrorMessages *[]flow.TransactionResultErrorMessage) error

LookupTransactionResultErrorMessagesByBlockIDUsingIndex retrieves the transaction result error messages of all failed transactions for the specified block. CAUTION: This method returns an empty slice if transaction results/errors for the block are not indexed yet OR if the block does not have any errors. No error returns are expected during normal operations.

func LookupTransactionResultsByBlockIDUsingIndex added in v0.39.4

func LookupTransactionResultsByBlockIDUsingIndex(r storage.Reader, blockID flow.Identifier, txResults *[]flow.TransactionResult) error

LookupTransactionResultsByBlockIDUsingIndex retrieves all tx results for a block, by using tx_index index. This correctly handles cases of duplicate transactions within block.

func MakePrefix

func MakePrefix(code byte, keys ...any) []byte

func NewMultiDBStore added in v0.41.0

func NewMultiDBStore(rwStore storage.DB, rStore storage.DB) storage.DB

NewMultiDBStore returns a DB store that consists of a primary read-and-write store, and a secondary read-only store.

func NewMultiIterator added in v0.41.0

func NewMultiIterator(iterators ...storage.Iterator) (storage.Iterator, error)

NewMultiIterator returns an Iterator that is a logical concatenation of multiple iterators in the provided sequence. The returned iterator iterates items in the first iterator, and then iterates items in the second iterator, etc. NewMultiIterator panics if 0 iterators are provided.

func NewMultiReader added in v0.41.0

func NewMultiReader(readers ...storage.Reader) storage.Reader

NewMultiReader returns a Reader that consists of multiple readers in the provided order. Readers are read sequentially until - a reader succeeds or - a reader returns an error that is not ErrNotFound If all readers return ErrNotFound, Reader.Get will return ErrNotFound. NewMultiReader panics if 0 readers are provided.

func NewMultiSeeker added in v0.41.0

func NewMultiSeeker(seekers ...storage.Seeker) storage.Seeker

NewMultiSeeker returns a Seeker that consists of multiple seekers in the provided order. NewMultiSeeker panics if 0 seekers are provided.

func PersistNodeDisallowList added in v0.41.0

func PersistNodeDisallowList(w storage.Writer, disallowList map[flow.Identifier]struct{}) error

PersistNodeDisallowList writes the set of disallowed nodes IDs into the database. If an entry already exists, it is overwritten; otherwise a new entry is created. No errors are expected during normal operations.

TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only

func PrintStats added in v0.40.0

func PrintStats(log zerolog.Logger, stats map[byte]Stats)

PrintStats logs the statistics for each prefix in ascending order. Each prefix is shown in hex, along with count, min, max, total, and average sizes.

func PurgeNodeDisallowList added in v0.41.0

func PurgeNodeDisallowList(w storage.Writer) error

PurgeNodeDisallowList removes the set of disallowed nodes IDs from the database. If no corresponding entry exists, this function is a no-op. No errors are expected during normal operations.

TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only

func Remove

func Remove(key []byte) func(storage.Writer) error

func RemoveByKey

func RemoveByKey(w storage.Writer, key []byte) error

RemoveByKey removes the entity with the given key, if it exists. If it doesn't exist, this is a no-op. Error returns: * generic error in case of unexpected database error

func RemoveByKeyPrefix

func RemoveByKeyPrefix(reader storage.Reader, w storage.Writer, prefix []byte) error

RemoveByKeyPrefix removes all keys with the given prefix Error returns: * generic error in case of unexpected database error

func RemoveByKeyRange

func RemoveByKeyRange(reader storage.Reader, w storage.Writer, startPrefix []byte, endPrefix []byte) error

RemoveByKeyRange removes all keys with a prefix that falls within the range [start, end], both inclusive. It returns error if endPrefix < startPrefix no other errors are expected during normal operation

func RemoveByPrefix

func RemoveByPrefix(reader storage.Reader, key []byte) func(storage.Writer) error

func RemoveByRange

func RemoveByRange(reader storage.Reader, startPrefix []byte, endPrefix []byte) func(storage.Writer) error

func RemoveChunkDataPack

func RemoveChunkDataPack(w storage.Writer, chunkDataPackID flow.Identifier) error

RemoveChunkDataPack removes the chunk data pack with the given stored chunk data pack ID. Non-existing keys are no-ops. Any errors are exceptions.

func RemoveChunkDataPackID added in v0.43.3

func RemoveChunkDataPackID(w storage.Writer, chunkID flow.Identifier) error

RemoveChunkDataPackID removes the mapping from chunk ID to stored chunk data pack ID. Non-existing keys are no-ops. Any errors are exceptions.

func RemoveCollection added in v0.39.4

func RemoveCollection(w storage.Writer, collID flow.Identifier) error

RemoveCollection removes a collection from the storage. CAUTION: this is for recovery purposes only, and should not be used during normal operations! It returns nil if the collection does not exist. No errors are expected during normal operation.

func RemoveCollectionPayloadIndices added in v0.41.0

func RemoveCollectionPayloadIndices(w storage.Writer, collID flow.Identifier) error

RemoveCollectionPayloadIndices removes a collection id indexed by a block id. CAUTION: this is for recovery purposes only, and should not be used during normal operations! It returns nil if the collection does not exist. No errors are expected during normal operation.

func RemoveCollectionTransactionIndices added in v0.41.0

func RemoveCollectionTransactionIndices(w storage.Writer, txID flow.Identifier) error

RemoveCollectionByTransactionIndex removes an entry in the index from transaction ID to collection containing the transaction. CAUTION: this is for recovery purposes only, and should not be used during normal operations! It returns nil if the collection does not exist. No errors are expected during normal operation.

func RemoveComputationResultUploadStatus added in v0.39.2

func RemoveComputationResultUploadStatus(
	w storage.Writer,
	blockID flow.Identifier) error

RemoveComputationResult removes an instance of ComputationResult with given ID.

func RemoveEventsByBlockID added in v0.39.4

func RemoveEventsByBlockID(r storage.Reader, w storage.Writer, blockID flow.Identifier) error

func RemoveExecutionForkEvidence added in v0.43.0

func RemoveExecutionForkEvidence(w storage.Writer) error

RemoveExecutionForkEvidence deletes conflicting seals record from the database. No errors are expected during normal operations.

func RemoveExecutionResultIndex added in v0.39.4

func RemoveExecutionResultIndex(w storage.Writer, blockID flow.Identifier) error

RemoveExecutionResultIndex removes Execution Node's OWN Execution Result for the given blockID. CAUTION: this is for recovery purposes only, and should not be used during normal operations It returns nil if the collection does not exist. No errors are expected during normal operation.

func RemoveOwnExecutionReceipt added in v0.39.4

func RemoveOwnExecutionReceipt(w storage.Writer, blockID flow.Identifier) error

RemoveOwnExecutionReceipt removes the Execution Node's OWN execution receipt index for the given block ID. CAUTION: this is for recovery purposes only, and should not be used during normal operations! It returns nil if the collection does not exist.

No errors are expected during normal operation.

func RemoveServiceEventsByBlockID added in v0.39.4

func RemoveServiceEventsByBlockID(r storage.Reader, w storage.Writer, blockID flow.Identifier) error

func RemoveStateCommitment added in v0.39.4

func RemoveStateCommitment(w storage.Writer, blockID flow.Identifier) error

RemoveStateCommitment removes the state commitment by block ID CAUTION: this is for recovery purposes only, and should not be used during normal operations! It returns nil if no execution result for the given blockID was previously indexed. No errors are expected during normal operation.

func RemoveTransaction added in v0.41.0

func RemoveTransaction(r storage.Writer, txID flow.Identifier) error

RemoveTransaction removes a transaction by ID.

func RemoveTransactionResultsByBlockID added in v0.39.4

func RemoveTransactionResultsByBlockID(blockID flow.Identifier, rw storage.ReaderBatchWriter) error

RemoveTransactionResultsByBlockID removes transaction results for the given blockID in a provided batch. No errors are expected during normal operation, but it may return generic error if badger fails to process request

func Retrieve

func Retrieve(key []byte, entity interface{}) func(storage.Reader) error

func RetrieveBlockChildren added in v0.43.0

func RetrieveBlockChildren(r storage.Reader, blockID flow.Identifier, childrenIDs *flow.IdentifierList) error

RetrieveBlockChildren retrieves the list of child block IDs for the specified parent block.

No error returns expected during normal operations. It returns storage.ErrNotFound if the block has no children. Note, this would mean either the block does not exist or the block exists but has no children. The caller has to check if the block exists by other means if needed.

func RetrieveBlockIDByScheduledTransactionID added in v0.43.3

func RetrieveBlockIDByScheduledTransactionID(r storage.Reader, txID flow.Identifier, blockID *flow.Identifier) error

RetrieveBlockIDByScheduledTransactionID retrieves the block ID of the scheduled transaction by its transaction ID.

Expected error returns during normal operation:

func RetrieveByKey

func RetrieveByKey(r storage.Reader, key []byte, entity any) (errToReturn error)

RetrieveByKey will retrieve the binary data under the given key from the database and decode it into the given entity. The provided entity needs to be a pointer to an initialized entity of the correct type. Error returns:

  • storage.ErrNotFound if the key does not exist in the database
  • generic error in case of unexpected failure from the database layer, or failure to decode an existing database value

func RetrieveChunkDataPack

func RetrieveChunkDataPack(r storage.Reader, storeChunkDataPackID flow.Identifier, c *storage.StoredChunkDataPack) error

RetrieveChunkDataPack retrieves a chunk data pack by stored chunk data pack ID. It returns storage.ErrNotFound if no chunk data pack with the given ID is known.

func RetrieveChunkDataPackID added in v0.43.3

func RetrieveChunkDataPackID(r storage.Reader, chunkID flow.Identifier, chunkDataPackID *flow.Identifier) error

RetrieveChunkDataPackID retrieves the stored chunk data pack ID for a given chunk ID. Returns storage.ErrNotFound if no chunk data pack has been indexed as result for the given chunk ID.

func RetrieveChunkLocator added in v0.39.1

func RetrieveChunkLocator(r storage.Reader, locatorID flow.Identifier, locator *chunks.Locator) error

func RetrieveClusterBlock added in v0.43.3

func RetrieveClusterBlock(r storage.Reader, blockID flow.Identifier, block *cluster.Block) error

RetrieveClusterBlock retrieves a cluster consensus block by block ID.

func RetrieveClusterFinalizedHeight added in v0.43.0

func RetrieveClusterFinalizedHeight(r storage.Reader, clusterID flow.ChainID, height *uint64) error

RetrieveClusterFinalizedHeight retrieves the latest finalized cluster block height of the given cluster. For collector nodes in the specified cluster, this value should always exist (after bootstrapping). However, other nodes outside the cluster typically do not track the latest finalized heights for the different collector clusters.

Expected error returns during normal operations:

  • storage.ErrNotFound if the latest finalized height for the specified cluster is not present in the database

func RetrieveClusterPayload added in v0.43.3

func RetrieveClusterPayload(r storage.Reader, blockID flow.Identifier, payload *cluster.Payload) error

RetrieveClusterPayload retrieves a cluster consensus block payload by block ID.

func RetrieveCollection added in v0.39.4

func RetrieveCollection(r storage.Reader, collID flow.Identifier, collection *flow.LightCollection) error

RetrieveCollection retrieves a flow.LightCollection by its ID.

Expected errors during normal operations:

func RetrieveEpochCommit added in v0.43.0

func RetrieveEpochCommit(r storage.Reader, eventID flow.Identifier, event *flow.EpochCommit) error

func RetrieveEpochFirstHeight added in v0.43.0

func RetrieveEpochFirstHeight(r storage.Reader, epoch uint64, height *uint64) error

RetrieveEpochFirstHeight retrieves the height of the first block in the given epoch. This operation does not require any locks, because the first height of an epoch does not change once set. Returns storage.ErrNotFound if the first block of the epoch has not yet been finalized.

func RetrieveEpochLastHeight added in v0.43.0

func RetrieveEpochLastHeight(r storage.Reader, epoch uint64, height *uint64) error

RetrieveEpochLastHeight retrieves the height of the last block in the given epoch. This operation does not require any locks, because the first height of an epoch does not change once set. It's a more readable, but equivalent query to RetrieveEpochFirstHeight when interested in the last height of an epoch. Returns storage.ErrNotFound if the first block of the epoch has not yet been finalized.

func RetrieveEpochProtocolState added in v0.43.0

func RetrieveEpochProtocolState(r storage.Reader, entryID flow.Identifier, entry *flow.MinEpochStateEntry) error

RetrieveEpochProtocolState retrieves an epoch protocol state entry by ID. Error returns:

  • storage.ErrNotFound if the key does not exist in the database

func RetrieveEpochSetup added in v0.43.0

func RetrieveEpochSetup(r storage.Reader, eventID flow.Identifier, event *flow.EpochSetup) error

func RetrieveEvents added in v0.39.4

func RetrieveEvents(r storage.Reader, blockID flow.Identifier, transactionID flow.Identifier, events *[]flow.Event) error

func RetrieveExecutedBlock added in v0.39.4

func RetrieveExecutedBlock(r storage.Reader, blockID *flow.Identifier) error

func RetrieveExecutionForkEvidence added in v0.42.1

func RetrieveExecutionForkEvidence(r storage.Reader, conflictingSeals *[]*flow.IncorporatedResultSeal) error

RetrieveExecutionForkEvidence reads conflicting seals from the database. It returns `storage.ErrNotFound` error if no database record is present.

func RetrieveExecutionReceiptStub added in v0.43.0

func RetrieveExecutionReceiptStub(r storage.Reader, receiptID flow.Identifier, meta *flow.ExecutionReceiptStub) error

RetrieveExecutionReceiptStub retrieves a flow.ExecutionReceiptStub by its ID.

Expected errors during normal operations:

func RetrieveExecutionResult added in v0.39.4

func RetrieveExecutionResult(r storage.Reader, resultID flow.Identifier, result *flow.ExecutionResult) error

RetrieveExecutionResult retrieves an Execution Result by its ID. Expected errors during normal operations:

func RetrieveExecutionStateInteractions added in v0.39.4

func RetrieveExecutionStateInteractions(
	r storage.Reader,
	blockID flow.Identifier,
	executionSnapshots *[]*snapshot.ExecutionSnapshot,
) error

func RetrieveFinalizedHeight added in v0.43.0

func RetrieveFinalizedHeight(r storage.Reader, height *uint64) error

func RetrieveGuarantee added in v0.43.0

func RetrieveGuarantee(r storage.Reader, collID flow.Identifier, guarantee *flow.CollectionGuarantee) error

RetrieveGuarantee retrieves a flow.CollectionGuarantee by the collection ID. For every collection that has been guaranteed, this data should be populated.

Expected errors during normal operations:

  • storage.ErrNotFound if `collID` does not refer to a known guaranteed collection
  • All other errors have to be treated as unexpected failures from the database layer.

func RetrieveHeader added in v0.43.0

func RetrieveHeader(r storage.Reader, blockID flow.Identifier, header *flow.Header) error

RetrieveHeader retrieves the header of the block with the specified ID. Expected errors during normal operations:

  • storage.ErrNotFound if no block with the specified `blockID` is known.
  • generic error in case of unexpected failure from the database layer

func RetrieveIndex added in v0.43.3

func RetrieveIndex(r storage.Reader, blockID flow.Identifier, index *flow.Index) error

func RetrieveInstanceParams added in v0.43.0

func RetrieveInstanceParams(r storage.Reader, params *flow.VersionedInstanceParams) error

RetrieveInstanceParams retrieves the consolidated instance params from storage.

Expected errors during normal operations:

func RetrieveJobAtIndex added in v0.39.1

func RetrieveJobAtIndex(r storage.Reader, queue string, index uint64, entity *flow.Identifier) error

RetrieveJobAtIndex returns the entity at the given index

func RetrieveJobLatestIndex added in v0.39.1

func RetrieveJobLatestIndex(r storage.Reader, queue string, index *uint64) error

func RetrieveLatestFinalizedClusterHeader added in v0.43.3

func RetrieveLatestFinalizedClusterHeader(r storage.Reader, clusterID flow.ChainID, final *flow.Header) error

RetrieveLatestFinalizedClusterHeader retrieves the latest finalized cluster block header from the specified cluster.

func RetrieveLightTransactionResult added in v0.39.4

func RetrieveLightTransactionResult(r storage.Reader, blockID flow.Identifier, transactionID flow.Identifier, transactionResult *flow.LightTransactionResult) error

RetrieveLightTransactionResult retrieves the result (light representation) of the specified transaction within the specified block. Expected error returns during normal operations:

  • storage.ErrNotFound if no result of a transaction with the specified ID in `blockID` is known

func RetrieveLightTransactionResultByIndex added in v0.39.4

func RetrieveLightTransactionResultByIndex(r storage.Reader, blockID flow.Identifier, txIndex uint32, transactionResult *flow.LightTransactionResult) error

RetrieveLightTransactionResultByIndex retrieves the result (light representation) of the transaction at the given index within the specified block. Expected error returns during normal operations:

func RetrieveLivenessData added in v0.42.0

func RetrieveLivenessData(r storage.Reader, chainID flow.ChainID, livenessData *hotstuff.LivenessData) error

RetrieveSafetyData retrieves the safety data for this node. Intended for consensus participants only (consensus and collector nodes). Here, `chainID` specifies which consensus instance specifically the node participates in. For consensus and collector nodes, this value should always exist (for the correct chainID). No errors are expected during normal operation.

func RetrieveNodeDisallowList added in v0.41.0

func RetrieveNodeDisallowList(r storage.Reader, disallowList *map[flow.Identifier]struct{}) error

RetrieveNodeDisallowList reads the set of disallowed node IDs from the database. Returns `storage.ErrNotFound` error in case no respective database entry is present.

TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only

func RetrieveProcessedIndex

func RetrieveProcessedIndex(r storage.Reader, jobName string, processed *uint64) error

RetrieveProcessedIndex returns the processed index for a job consumer

func RetrieveProposalSignature added in v0.43.0

func RetrieveProposalSignature(r storage.Reader, blockID flow.Identifier, sig *[]byte) error

RetrieveProposalSignature retrieves a proposal signature by blockID. Returns storage.ErrNotFound if no proposal signature is stored for the block.

func RetrieveProtocolKVStore added in v0.43.0

func RetrieveProtocolKVStore(r storage.Reader, protocolKVStoreID flow.Identifier, kvStore *flow.PSKeyValueStoreData) error

RetrieveProtocolKVStore retrieves a protocol KV store by ID. Expected error returns during normal operations:

func RetrieveQuorumCertificate added in v0.43.0

func RetrieveQuorumCertificate(r storage.Reader, blockID flow.Identifier, qc *flow.QuorumCertificate) error

RetrieveQuorumCertificate retrieves the QuorumCertificate for the specified block. For every block that has been certified, this index should be populated.

Expected errors during normal operations:

func RetrieveResultApproval

func RetrieveResultApproval(r storage.Reader, approvalID flow.Identifier, approval *flow.ResultApproval) error

RetrieveResultApproval retrieves an approval by ID. Returns `storage.ErrNotFound` if no Approval with the given ID has been stored.

func RetrieveSafetyData added in v0.42.0

func RetrieveSafetyData(r storage.Reader, chainID flow.ChainID, safetyData *hotstuff.SafetyData) error

RetrieveSafetyData retrieves the safety data for this node. Intended for consensus participants only (consensus and collector nodes). Here, `chainID` specifies which consensus instance specifically the node participates in. For consensus and collector nodes, this value should always exist (for the correct chainID). No errors are expected during normal operation.

func RetrieveSeal added in v0.43.0

func RetrieveSeal(r storage.Reader, sealID flow.Identifier, seal *flow.Seal) error

RetrieveSeal retrieves the flow.Seal by its ID. Expected errors during normal operations:

func RetrieveSealedHeight added in v0.43.0

func RetrieveSealedHeight(r storage.Reader, height *uint64) error

func RetrieveTransaction added in v0.39.4

func RetrieveTransaction(r storage.Reader, txID flow.Identifier, tx *flow.TransactionBody) error

RetrieveTransaction retrieves a transaction by fingerprint.

func RetrieveTransactionIDByScheduledTransactionID added in v0.43.3

func RetrieveTransactionIDByScheduledTransactionID(r storage.Reader, scheduledTxID uint64, txID *flow.Identifier) error

RetrieveTransactionIDByScheduledTransactionID retrieves the transaction ID of the scheduled transaction by its scheduled transaction ID.

Expected error returns during normal operation:

func RetrieveTransactionResult added in v0.39.4

func RetrieveTransactionResult(r storage.Reader, blockID flow.Identifier, transactionID flow.Identifier, transactionResult *flow.TransactionResult) error

func RetrieveTransactionResultByIndex added in v0.39.4

func RetrieveTransactionResultByIndex(r storage.Reader, blockID flow.Identifier, txIndex uint32, transactionResult *flow.TransactionResult) error

func RetrieveTransactionResultErrorMessage added in v0.39.4

func RetrieveTransactionResultErrorMessage(r storage.Reader, blockID flow.Identifier, transactionID flow.Identifier, transactionResultErrorMessage *flow.TransactionResultErrorMessage) error

RetrieveTransactionResultErrorMessage retrieves a transaction result error message of the specified transaction within the specified block. Expected error returns during normal operations:

  • storage.ErrNotFound if no result error message of a transaction with the specified ID in `blockID` is known

func RetrieveTransactionResultErrorMessageByIndex added in v0.39.4

func RetrieveTransactionResultErrorMessageByIndex(r storage.Reader, blockID flow.Identifier, txIndex uint32, transactionResultErrorMessage *flow.TransactionResultErrorMessage) error

RetrieveTransactionResultErrorMessageByIndex retrieves the transaction result error message of the transaction at the given index within the specified block. Expected error returns during normal operations:

func SetJobLatestIndex added in v0.39.1

func SetJobLatestIndex(w storage.Writer, queue string, index uint64) error

func SetProcessedIndex

func SetProcessedIndex(w storage.Writer, jobName string, processed uint64) error

SetProcessedIndex updates the processed index for a job consumer with given index

func SummarizeKeysByFirstByteConcurrent added in v0.40.0

func SummarizeKeysByFirstByteConcurrent(log zerolog.Logger, r storage.Reader, nWorker int) (map[byte]Stats, error)

SummarizeKeysByFirstByteConcurrent iterates over all prefixes [0x00..0xFF] in parallel using nWorker goroutines. Each worker handles one prefix at a time until all are processed.

The storage.Reader must be able to create multiple iterators concurrently.

func TransactionResultErrorMessagesExists added in v0.39.4

func TransactionResultErrorMessagesExists(r storage.Reader, blockID flow.Identifier, blockExists *bool) error

TransactionResultErrorMessagesExists checks whether tx result error messages exist in the database. No error returns are expected during normal operations.

func Traverse

func Traverse(prefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) func(storage.Reader) error

func TraverseByPrefix

func TraverseByPrefix(r storage.Reader, prefix []byte, iterFunc IterationFunc, opt storage.IteratorOption) error

TraverseByPrefix will iterate over all keys with the given prefix error returned by the iteration functions will be propagated to the caller. No other errors are expected during normal operation.

func UpdateClusterFinalizedHeight added in v0.43.3

func UpdateClusterFinalizedHeight(lctx lockctx.Proof, rw storage.ReaderBatchWriter, clusterID flow.ChainID, latestFinalizedHeight uint64) error

UpdateClusterFinalizedHeight updates (overwrites!) the latest finalized cluster block height for the given cluster.

CAUTION:

  • This function is intended for normal operations after bootstrapping. It expects that the height of the latest known finalized cluster block has already been persisted. This function guarantees that the height is updated sequentially, i.e. the new height is equal to the old height plus one. Otherwise, an exception is returned.
  • Reading the current height value, checking that it increases sequentially, and writing the new value must happen in one atomic operation to prevent data corruption. Hence, the caller must acquire storage.LockInsertOrFinalizeClusterBlock and hold it until the database write has been committed.

No error returns expected during normal operations.

func UpdateExecutedBlock added in v0.39.4

func UpdateExecutedBlock(w storage.Writer, blockID flow.Identifier) error

UpdateExecutedBlock updates the pointer to the Execution Node's OWN highest executed block. We overwrite the block ID of the most recently executed block, regardless of whether this block may later be orphaned or is already orphaned.

## Usage Context

  • The stored "last executed block" may reference a block on a fork that is later orphaned.
  • This is acceptable and expected: the index is intended for reporting execution metrics and for optimizing the loading of unexecuted blocks on node startup.
  • On startup, the Execution Node may use the latest executed block as a hint on where to restart the execution. It MUST traverse from the last executed in the direction of decreasing height. It will eventually reach a block with a finalized seal. From this block, the Execution Node should restart its execution and cover _all_ descendants (that are not orphaned). Thereby, we guarantee that even if the stored block is on a fork, we eventually also cover blocks are finalized or and the most recent still unfinalized blocks.
  • If the block referenced as "highest executed block" is not on the canonical chain, the Execution Node may (re-)execute some blocks unnecessarily, but this does not affect correctness.

## Limitations & Edge Cases - The value is not guaranteed to be on the finalized chain. - Forks of arbitrary length may occur; the stored block may be on any such fork.

## Correct Usage - Use for metrics (e.g., reporting latest executed block height). - Use for optimizing block execution on startup (as a performance hint).

## Incorrect Usage - Do not use as a source of truth for canonical chain state. - Do not disregard blocks with lower heights as not needing execution.

See project documentation in `engine/execution/ingestion/loader/unexecuted_loader.go` for details on startup traversal logic.

func Upsert

func Upsert(key []byte, val interface{}) func(storage.Writer) error

func UpsertByKey

func UpsertByKey(w storage.Writer, key []byte, val interface{}) error

UpsertByKey will encode the given entity using msgpack and will insert the resulting binary data under the provided key. If the key already exists, the value will be overwritten. Error returns:

  • generic error in case of unexpected failure from the database layer or encoding failure.

func UpsertCollection added in v0.39.4

func UpsertCollection(w storage.Writer, collection *flow.LightCollection) error

UpsertCollection inserts a flow.LightCollection into the storage, keyed by its ID.

If the collection already exists, it will be overwritten. Note that here, the key (collection ID) is derived from the value (collection) via a collision-resistant hash function. Hence, unchecked overwrites pose no risk of data corruption, because for the same key, we expect the same value.

No errors are expected during normal operation.

func UpsertComputationResultUploadStatus added in v0.39.2

func UpsertComputationResultUploadStatus(w storage.Writer, blockID flow.Identifier,
	wasUploadCompleted bool) error

UpsertComputationResult upserts given existing instance of ComputationResult in local BadgerDB.

func UpsertFinalizedHeight added in v0.43.0

func UpsertFinalizedHeight(lctx lockctx.Proof, w storage.Writer, height uint64) error

UpsertFinalizedHeight upserts the finalized height index, overwriting the current value. Updates to this index must strictly increase the finalized height. To enforce this, the caller must check the current finalized height while holding storage.LockFinalizeBlock.

func UpsertLivenessData added in v0.42.0

func UpsertLivenessData(lctx lockctx.Proof, rw storage.ReaderBatchWriter, chainID flow.ChainID, livenessData *hotstuff.LivenessData) error

UpsertLivenessData inserts or updates the given liveness data for this node. Intended for consensus participants only (consensus and collector nodes). Here, `chainID` specifies which consensus instance specifically the node participates in.

No errors are expected during normal operation.

func UpsertSafetyData added in v0.42.0

func UpsertSafetyData(lctx lockctx.Proof, rw storage.ReaderBatchWriter, chainID flow.ChainID, safetyData *hotstuff.SafetyData) error

UpsertSafetyData inserts or updates the given safety data for this node. Intended for consensus participants only (consensus and collector nodes). Here, `chainID` specifies which consensus instance specifically the node participates in.

No errors are expected during normal operation.

func UpsertSealedHeight added in v0.43.0

func UpsertSealedHeight(lctx lockctx.Proof, w storage.Writer, height uint64) error

UpsertSealedHeight upserts the latest sealed height, OVERWRITING the current value. Updates to this index must strictly increase the sealed height. To enforce this, the caller must check the current sealed height while holding storage.LockFinalizeBlock.

func UpsertTransaction added in v0.39.4

func UpsertTransaction(w storage.Writer, txID flow.Identifier, tx *flow.TransactionBody) error

UpsertTransaction inserts a transaction keyed by transaction fingerprint. It overwrites any existing transaction, which is ok because tx is unique by its ID

func Upserting added in v0.43.0

func Upserting(key []byte, val interface{}) func(storage.Writer) error

Upserting returns a functor, whose execution will append the given key-value-pair to the provided storage writer (typically a pending batch of database writes).

Types

type Callbacks

type Callbacks struct {
	// contains filtered or unexported fields
}

Callbacks represents a collection of callbacks to be executed. Callbacks are not concurrent safe. Since Callbacks is only used in ReaderBatchWriter, which isn't concurrent safe, there isn't a need to add locking overhead to Callbacks.

func NewCallbacks added in v0.41.0

func NewCallbacks() *Callbacks

func (*Callbacks) AddCallback

func (b *Callbacks) AddCallback(callback func(error))

func (*Callbacks) NotifyCallbacks

func (b *Callbacks) NotifyCallbacks(err error)

type IterationFunc

type IterationFunc func(keyCopy []byte, getValue func(destVal any) error) (bail bool, err error)

IterationFunc is a callback function that will be called on each key-value pair during the iteration. The key is copied and passed to the function, so key can be modified or retained after iteration. The `getValue` function can be called to retrieve the value of the current key and decode value into destVal object. The caller can return (true, nil) to stop the iteration early.

func KeyOnlyIterateFunc

func KeyOnlyIterateFunc(fn func(key []byte) error) IterationFunc

KeyOnlyIterateFunc returns an IterationFunc that only iterates over keys

type Stats added in v0.40.0

type Stats struct {
	Count       int     `json:"count"`
	MinSize     int     `json:"min_size"`
	MaxSize     int     `json:"max_size"`
	TotalSize   int     `json:"total_size"`
	AverageSize float64 `json:"avg_size"`
}

Stats holds statistics for a single prefix group.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL