operation

package
v0.41.5-unsafe-follower.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: AGPL-3.0 Imports: 22 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 BatchIndexLightTransactionResult added in v0.39.4

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

func BatchIndexTransactionResultErrorMessage added in v0.39.4

func BatchIndexTransactionResultErrorMessage(w storage.Writer, blockID flow.Identifier, transactionResultErrorMessage *flow.TransactionResultErrorMessage) error

BatchIndexTransactionResultErrorMessage indexes a transaction result error message by index within the block using a batch write.

func BatchInsertLightTransactionResult added in v0.39.4

func BatchInsertLightTransactionResult(w storage.Writer, blockID flow.Identifier, transactionResult *flow.LightTransactionResult) error

func BatchInsertTransactionResultErrorMessage added in v0.39.4

func BatchInsertTransactionResultErrorMessage(w storage.Writer, blockID flow.Identifier, transactionResultErrorMessage *flow.TransactionResultErrorMessage) error

BatchInsertTransactionResultErrorMessage inserts a transaction result error message by block ID and transaction ID into the database using a batch write.

func BatchRemoveTransactionResultsByBlockID added in v0.39.4

func BatchRemoveTransactionResultsByBlockID(blockID flow.Identifier, batch storage.ReaderBatchWriter) error

BatchRemoveTransactionResultsByBlockID 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 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 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)

func Exists

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

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 interface{}) (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 IndexBlockHeight

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

IndexBlockHeight indexes the height of a block. It must only be called on finalized blocks. This function guarantees that the index is only inserted once for each height. The caller must acquire the storage.LockFinalizeBlock lock. Returns storage.ErrAlreadyExists if an ID has already been finalized for this height.

func IndexCollectionBlock

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

IndexCollectionBlock indexes a block by a collection within that block.

func IndexCollectionPayload added in v0.39.4

func IndexCollectionPayload(w storage.Writer, blockID flow.Identifier, txIDs []flow.Identifier) error

IndexCollectionPayload will overwrite any existing index, which is acceptable because the blockID is derived from txIDs within the payload, ensuring its uniqueness.

func IndexEpochProtocolState added in v0.43.0

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

IndexEpochProtocolState indexes an epoch protocol state entry by block ID. Error returns:

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

func IndexExecutionReceipts added in v0.39.4

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

IndexExecutionReceipts inserts an execution receipt ID keyed by block ID and receipt ID. one block could have multiple receipts, even if they are from the same executor

func IndexExecutionResult added in v0.39.4

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

IndexExecutionResult inserts an execution result ID keyed by block ID

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`

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 up to (and including) blockID. In most cases, it is 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 ancestor.

func IndexOwnExecutionReceipt added in v0.39.4

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

IndexOwnExecutionReceipt inserts an execution receipt ID keyed by block ID

func IndexPayloadProtocolStateID added in v0.43.0

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

func IndexPayloadReceipts added in v0.43.0

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

func IndexPayloadResults added in v0.43.0

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

func IndexPayloadSeals added in v0.43.0

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

func IndexProtocolKVStore added in v0.43.0

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

IndexProtocolKVStore indexes a protocol KV store by block ID. Error returns:

  • storage.ErrAlreadyExists if the key already exists in the database.
  • generic error in case of unexpected failure from the database layer

func IndexResultApproval

func IndexResultApproval(lctx lockctx.Proof, w storage.Writer, resultID flow.Identifier, chunkIndex uint64, approvalID flow.Identifier) error

IndexResultApproval inserts a ResultApproval ID keyed by ExecutionResult ID and chunk index. 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 IndexResultApproval must acquire the storage.LockIndexResultApproval and check that no value already exists for the index prior to writing.

func IndexStateCommitment added in v0.39.4

func IndexStateCommitment(w storage.Writer, blockID flow.Identifier, commit flow.StateCommitment) error

IndexStateCommitment indexes a state commitment.

State commitments are keyed by the block whose execution results in the state with the given commit.

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 InsertChunkDataPack

func InsertChunkDataPack(w storage.Writer, c *storage.StoredChunkDataPack) error

InsertChunkDataPack inserts a chunk data pack keyed by chunk ID. any error are exceptions

func InsertChunkLocator added in v0.39.1

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

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(w storage.Writer, conflictingSeals []*flow.IncorporatedResultSeal) error

func InsertExecutionReceiptMeta added in v0.39.4

func InsertExecutionReceiptMeta(w storage.Writer, receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) error

InsertExecutionReceiptMeta inserts an execution receipt meta by ID.

func InsertExecutionResult added in v0.39.4

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

InsertExecutionResult inserts an execution result by ID.

func InsertExecutionStateInteractions added in v0.39.4

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

func InsertHeader added in v0.43.0

func InsertHeader(w storage.Writer, headerID flow.Identifier, header *flow.Header) error

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 InsertLastCompleteBlockHeightIfNotExists

func InsertLastCompleteBlockHeightIfNotExists(inserting *sync.Mutex, rw storage.ReaderBatchWriter, height uint64) error

TODO(7355): If we're going to use this function, we should add a managed lock for it. But it is currently only used in tests and it looks like where this was previous used was replaced by an in-memory counter: https://github.com/onflow/flow-go/blob/d27f7b74b8cf987f3120f0700cba73bb95391a21/engine/access/ingestion/engine.go#L103

func InsertLightTransactionResult added in v0.39.4

func InsertLightTransactionResult(w storage.Writer, blockID flow.Identifier, transactionResult *flow.LightTransactionResult) error

deprecated

func InsertProtocolKVStore added in v0.43.0

func InsertProtocolKVStore(w storage.Writer, protocolKVStoreID flow.Identifier, kvStore *flow.PSKeyValueStoreData) error

InsertProtocolKVStore inserts a protocol KV store by ID. Error returns:

  • storage.ErrAlreadyExists if the key already exists in the database.
  • generic error in case of unexpected failure from the database layer or encoding failure.

func InsertResultApproval

func InsertResultApproval(w storage.Writer, approval *flow.ResultApproval) error

InsertResultApproval inserts a ResultApproval by ID. The same key (`approval.ID()`) necessitates that the value (full `approval`) is also identical (otherwise, we would have a successful pre-image attack on our cryptographic hash function). Therefore, concurrent calls to this function are safe.

func InsertRootHeight

func InsertRootHeight(w storage.Writer, height uint64) error

func InsertSeal added in v0.43.0

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

func InsertSealedRootHeight

func InsertSealedRootHeight(w storage.Writer, height uint64) error

func InsertServiceEvent added in v0.39.4

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

func InsertSporkID

func InsertSporkID(w storage.Writer, sporkID flow.Identifier) error

InsertSporkID inserts the spork ID for the present spork. A single database and protocol state instance spans at most one spork, so this is inserted exactly once, when bootstrapping the state.

func InsertSporkRootBlockHeight

func InsertSporkRootBlockHeight(w storage.Writer, height uint64) error

InsertSporkRootBlockHeight inserts the spork root block height for the present spork. A single database and protocol state instance spans at most one spork, so this is inserted exactly once, when bootstrapping the state.

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 LookupBlockHeight added in v0.43.0

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

LookupBlockHeight retrieves finalized blocks by height.

func LookupBySealedBlockID added in v0.43.0

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

LookupBySealedBlockID finds the seal for the given sealed block ID.

func LookupCollectionBlock

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

LookupCollectionBlock looks up a block by a collection within that block.

func LookupCollectionByTransaction added in v0.41.0

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

LookupCollectionByTransaction looks up the collection indexed by the given transaction ID, which is the collection in which the given transaction was included. It returns storage.ErrNotFound if the collection is not found. No errors are expected during normal operaion.

func LookupCollectionPayload added in v0.39.4

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

LookupCollection looks up the collection for a given cluster payload.

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
  • generic error in case of unexpected failure from the database layer

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 finds all execution receipts by block ID

func LookupExecutionResult added in v0.39.4

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

LookupExecutionResult finds execution result ID by block

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. In most cases, it is 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 ancestor.

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 a block, but using tx_index index. This correctly handles cases of duplicate transactions within block.

func LookupOwnExecutionReceipt added in v0.39.4

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

LookupOwnExecutionReceipt finds execution receipt ID by block

func LookupPayloadGuarantees added in v0.43.0

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

func LookupPayloadProtocolStateID added in v0.43.0

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

func LookupPayloadReceipts added in v0.43.0

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

func LookupPayloadResults added in v0.43.0

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

func LookupPayloadSeals added in v0.43.0

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

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. Error returns:

  • storage.ErrNotFound if the key does not exist in the database
  • generic error in case of unexpected failure from the database layer

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 gets a state commitment keyed by block ID

State commitments are keyed by the block whose execution results in the state with the given commit.

func LookupTransactionResultErrorMessagesByBlockIDUsingIndex added in v0.39.4

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

LookupTransactionResultErrorMessagesByBlockIDUsingIndex retrieves all tx result error messages for a block, by using tx_index index. This correctly handles cases of duplicate transactions within block.

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, chunkID flow.Identifier) error

RemoveChunkDataPack removes the chunk data pack with the given chunk ID. any error 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. 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, blockID flow.Identifier) error

RemoveCollectionPayloadIndices removes a collection id indexed by a block id 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 a collection id indexed by a transaction id, created by UnsafeIndexCollectionByTransaction. 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

func RemoveExecutionResultIndex added in v0.39.4

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

RemoveExecutionResultIndex removes execution result indexed by the given blockID

func RemoveOwnExecutionReceipt added in v0.39.4

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

RemoveOwnExecutionReceipt removes own execution receipt index by blockID

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

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(r storage.Reader, w storage.Writer, blockID flow.Identifier) error

RemoveTransactionResultsByBlockID removes the transaction results for the given blockID

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 the child block ID by parent block ID

func RetrieveByKey

func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (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, chunkID flow.Identifier, c *storage.StoredChunkDataPack) error

RetrieveChunkDataPack retrieves a chunk data pack by chunk ID. it returns storage.ErrNotFound if the chunk data pack is not found

func RetrieveChunkLocator added in v0.39.1

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

func RetrieveCollection added in v0.39.4

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

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. 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. 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
  • generic error in case of unexpected failure from the database layer

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

func RetrieveExecutionReceiptMeta added in v0.39.4

func RetrieveExecutionReceiptMeta(r storage.Reader, receiptID flow.Identifier, meta *flow.ExecutionReceiptMeta) error

RetrieveExecutionReceiptMeta retrieves a execution receipt meta by ID.

func RetrieveExecutionResult added in v0.39.4

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

RetrieveExecutionResult retrieves a transaction by fingerprint.

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

func RetrieveHeader added in v0.43.0

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

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 RetrieveLastCompleteBlockHeight

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

func RetrieveLightTransactionResult added in v0.39.4

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

func RetrieveLightTransactionResultByIndex added in v0.39.4

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

func RetrieveLivenessData added in v0.42.0

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

RetrieveLivenessData retrieves liveness data from the database.

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 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. Error returns:

  • storage.ErrNotFound if the key does not exist in the database
  • generic error in case of unexpected failure from the database layer

func RetrieveQuorumCertificate added in v0.43.0

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

RetrieveQuorumCertificate retrieves a quorum certificate by blockID. Returns storage.ErrNotFound if no QC is stored for the block.

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 RetrieveRootHeight

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

func RetrieveSafetyData added in v0.42.0

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

RetrieveSafetyData retrieves safety data from the database.

func RetrieveSeal added in v0.43.0

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

func RetrieveSealedHeight added in v0.43.0

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

func RetrieveSealedRootHeight

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

func RetrieveSporkID

func RetrieveSporkID(r storage.Reader, sporkID *flow.Identifier) error

RetrieveSporkID retrieves the spork ID for the present spork.

func RetrieveSporkRootBlockHeight

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

RetrieveSporkRootBlockHeight retrieves the spork root block height for the present spork.

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 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 by block ID and transaction ID.

func RetrieveTransactionResultErrorMessageByIndex added in v0.39.4

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

RetrieveTransactionResultErrorMessageByIndex retrieves a transaction result error message by block ID and index.

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.

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

Traverse 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 UnsafeIndexCollectionByTransaction added in v0.39.4

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

UnsafeIndexCollectionByTransaction inserts a collection id keyed by a transaction id Unsafe because a transaction can belong to multiple collections, indexing collection by a transaction will overwrite the previous collection id that was indexed by the same transaction id To prevent overwritting, the caller must check if the transaction is already indexed, and make sure there is no dirty read before the writing by using locks.

func UnsafeIndexPayloadGuarantees

func UnsafeIndexPayloadGuarantees(w storage.Writer, blockID flow.Identifier, guarIDs []flow.Identifier) error

func UnsafeInsertGuarantee

func UnsafeInsertGuarantee(w storage.Writer, collID flow.Identifier, guarantee *flow.CollectionGuarantee) error

UnsafeInsertGuarantee inserts a collection guarantee into the database. It's called unsafe because it doesn't check if a different guarantee was already inserted for the same collection ID.

func UnsafeUpsertQuorumCertificate

func UnsafeUpsertQuorumCertificate(w storage.Writer, qc *flow.QuorumCertificate) error

UnsafeUpsertQuorumCertificate upserts a quorum certificate by block ID and overwrite any existing QC indexed by the same block ID.

func UpdateExecutedBlock added in v0.39.4

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

func Upsert

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

func UpsertBlockChildren added in v0.43.0

func UpsertBlockChildren(w storage.Writer, blockID flow.Identifier, childrenIDs flow.IdentifierList) error

UpsertBlockChildren insert an index to lookup the direct child of a block by its ID

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 light collection into the storage. If the collection already exists, it will be overwritten.

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 UpsertLastCompleteBlockHeight

func UpsertLastCompleteBlockHeight(w storage.Writer, height uint64) error

func UpsertLivenessData added in v0.42.0

func UpsertLivenessData(w storage.Writer, chainID flow.ChainID, livenessData *hotstuff.LivenessData) error

UpsertLivenessData upserts liveness data in the database.

func UpsertSafetyData added in v0.42.0

func UpsertSafetyData(w storage.Writer, chainID flow.ChainID, safetyData *hotstuff.SafetyData) error

UpsertSafetyData inserts safety data into the database.

func UpsertSealedHeight added in v0.43.0

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

UpsertSealedHeight upserts the sealed height index, 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

Types

type BatchLocks added in v0.41.0

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

BatchLocks is a struct that holds the locks acquired by a batch, which is used to prevent re-entrant deadlock. BatchLocks is not safe for concurrent use by multiple goroutines. Deprecated: BatchLocks exists to provide deadlock protection as a temporary measure during the course of development of the Pebble database layer -- to be replaced prior to release with a system without reliance on globally unique mutex references.

func NewBatchLocks added in v0.41.0

func NewBatchLocks() *BatchLocks

func (*BatchLocks) Lock added in v0.41.0

func (l *BatchLocks) Lock(lock *sync.Mutex, callback *Callbacks)

Lock tries to acquire a given lock on behalf of the batch.

If the batch has already acquired this lock earlier (recorded in acquiredLocks), it skips locking again to avoid unnecessary blocking, allowing the caller to proceed immediately.

If the lock has not been acquired yet, it blocks until the lock is acquired, and then records the lock in the acquiredLocks map to indicate ownership.

It also registers a callback to ensure that when the batch operation is finished, the lock is properly released and removed from acquiredLocks.

Parameters:

  • lock: The *sync.Mutex to acquire. The common usage of this lock is to prevent dirty reads so that the batch writes is writing the correct data. In other words, this Lock method is to prevent re-entrant deadlock, while this lock mutex is used to prevent dirty reads.
  • callback: A Callbacks collection to which the unlock operation is appended so that locks are safely released once the batch processing is complete.

CAUTION: Since locks are identified by pointer address, callers must ensure that no other references exist for the input lock.

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 CheckFunc

type CheckFunc func(key []byte) (bool, error)

CheckFunc is a function that checks if the value should be read and decoded. return (true, nil) to read the value and pass it to the CreateFunc and HandleFunc for decoding return (false, nil) to skip reading the value return (false, err) if running into any exception, the iteration should be stopped. when making a CheckFunc to be used in the IterationFunc to iterate over the keys, a sentinel error can be defined and checked to stop the iteration early, such as finding the first key that match certain condition. Note: the returned bool is to decide whether to read the value or not, rather than whether to stop the iteration or not.

type CreateFunc

type CreateFunc func() interface{}

CreateFunc returns a pointer to an initialized entity that we can potentially decode the next value into during a badger DB iteration.

type HandleFunc

type HandleFunc func() error

HandleFunc is a function that starts the processing of the current key-value pair during a badger iteration. It should be called after the key was checked and the entity was decoded. No errors are expected during normal operation. Any errors will halt the iteration.

type IterationFunc

type IterationFunc func() (CheckFunc, CreateFunc, HandleFunc)

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