Documentation
¶
Overview ¶
Package storage defines the interface and implementations for interacting with persistent chain state.
Index ¶
- Constants
- Variables
- type DataGetter
- type DataSetter
- type DefaultKeyGenerator
- func (s *DefaultKeyGenerator) BlockHeight(blockHeight uint64) []byte
- func (s *DefaultKeyGenerator) ForkedBlock() []byte
- func (s *DefaultKeyGenerator) Identifier(id flowgo.Identifier) []byte
- func (s *DefaultKeyGenerator) LatestBlock() []byte
- func (s *DefaultKeyGenerator) ScheduledTransactionID(scheduledTxID uint64) []byte
- func (s *DefaultKeyGenerator) Storage(key string) string
- type DefaultStore
- func (s *DefaultStore) BlockByHeight(ctx context.Context, blockHeight uint64) (block *flowgo.Block, err error)
- func (s *DefaultStore) BlockByID(ctx context.Context, blockID flowgo.Identifier) (block *flowgo.Block, err error)
- func (s *DefaultStore) BlockIDByScheduledTransactionID(ctx context.Context, scheduledTxID uint64) (flowgo.Identifier, error)
- func (s *DefaultStore) CollectionByID(ctx context.Context, colID flowgo.Identifier) (col flowgo.LightCollection, err error)
- func (s *DefaultStore) CommitBlock(ctx context.Context, block flowgo.Block, collections []*flowgo.LightCollection, ...) error
- func (s *DefaultStore) EventsByHeight(ctx context.Context, blockHeight uint64, eventType string) (events []flowgo.Event, err error)
- func (s *DefaultStore) ForkedBlockHeight(ctx context.Context) (forkedBlockHeight uint64, err error)
- func (s *DefaultStore) FullCollectionByID(ctx context.Context, colID flowgo.Identifier) (col flowgo.Collection, err error)
- func (s *DefaultStore) IndexScheduledTransactionID(ctx context.Context, scheduledTxID uint64, blockID flowgo.Identifier) error
- func (s *DefaultStore) InsertCollection(ctx context.Context, col flowgo.LightCollection) error
- func (s *DefaultStore) InsertEvents(ctx context.Context, blockHeight uint64, events []flowgo.Event) error
- func (s *DefaultStore) InsertExecutionSnapshot(ctx context.Context, blockHeight uint64, ...) error
- func (s *DefaultStore) InsertTransaction(ctx context.Context, tx flowgo.TransactionBody, id flowgo.Identifier) error
- func (s *DefaultStore) InsertTransactionResult(ctx context.Context, txID flowgo.Identifier, ...) error
- func (s *DefaultStore) LatestBlock(ctx context.Context) (block flowgo.Block, err error)
- func (s *DefaultStore) LatestBlockHeight(ctx context.Context) (latestBlockHeight uint64, err error)
- func (s *DefaultStore) LedgerByHeight(ctx context.Context, blockHeight uint64) (snapshot.StorageSnapshot, error)
- func (s *DefaultStore) SetBlockHeight(height uint64) error
- func (s *DefaultStore) Start() error
- func (s *DefaultStore) Stop()
- func (s *DefaultStore) StoreBlock(ctx context.Context, block *flowgo.Block) error
- func (s *DefaultStore) StoreForkedBlockHeight(ctx context.Context, height uint64) error
- func (s *DefaultStore) StoreSystemTransactions(ctx context.Context, systemTransactions *SystemTransactions) error
- func (s *DefaultStore) SystemTransactionsForBlockID(ctx context.Context, blockID flowgo.Identifier) (*SystemTransactions, error)
- func (s *DefaultStore) TransactionByID(ctx context.Context, txID flowgo.Identifier) (tx flowgo.TransactionBody, err error)
- func (s *DefaultStore) TransactionResultByID(ctx context.Context, txID flowgo.Identifier) (result types.StorableTransactionResult, err error)
- type KeyGenerator
- type RollbackProvider
- type SnapshotProvider
- type Store
- type SystemTransactions
Constants ¶
const ( BlockIndexStoreName = "blockIndex" BlockStoreName = "blocks" SystemTransactionName = "systemTransactions" CollectionStoreName = "collections" TransactionStoreName = "transactions" TransactionResultStoreName = "transactionResults" EventStoreName = "events" LedgerStoreName = "ledger" )
Variables ¶
var ErrNotFound = errors.New("could not find entity")
ErrNotFound is an error returned when an entity cannot be found.
Functions ¶
This section is empty.
Types ¶
type DataGetter ¶ added in v0.40.0
type DataSetter ¶ added in v0.40.0
type DefaultKeyGenerator ¶ added in v0.40.0
type DefaultKeyGenerator struct{}
func (*DefaultKeyGenerator) BlockHeight ¶ added in v0.40.0
func (s *DefaultKeyGenerator) BlockHeight(blockHeight uint64) []byte
func (*DefaultKeyGenerator) ForkedBlock ¶ added in v0.62.0
func (s *DefaultKeyGenerator) ForkedBlock() []byte
func (*DefaultKeyGenerator) Identifier ¶ added in v0.40.0
func (s *DefaultKeyGenerator) Identifier(id flowgo.Identifier) []byte
func (*DefaultKeyGenerator) LatestBlock ¶ added in v0.40.0
func (s *DefaultKeyGenerator) LatestBlock() []byte
func (*DefaultKeyGenerator) ScheduledTransactionID ¶ added in v1.11.0
func (s *DefaultKeyGenerator) ScheduledTransactionID(scheduledTxID uint64) []byte
func (*DefaultKeyGenerator) Storage ¶ added in v0.40.0
func (s *DefaultKeyGenerator) Storage(key string) string
type DefaultStore ¶ added in v0.40.0
type DefaultStore struct {
KeyGenerator
DataSetter
DataGetter
CurrentHeight uint64
}
func (*DefaultStore) BlockByHeight ¶ added in v0.40.0
func (*DefaultStore) BlockByID ¶ added in v0.40.0
func (s *DefaultStore) BlockByID(ctx context.Context, blockID flowgo.Identifier) (block *flowgo.Block, err error)
func (*DefaultStore) BlockIDByScheduledTransactionID ¶ added in v1.11.0
func (s *DefaultStore) BlockIDByScheduledTransactionID(ctx context.Context, scheduledTxID uint64) (flowgo.Identifier, error)
BlockIDByScheduledTransactionID retrieves the block ID for a given scheduled transaction ID.
func (*DefaultStore) CollectionByID ¶ added in v0.40.0
func (s *DefaultStore) CollectionByID( ctx context.Context, colID flowgo.Identifier, ) ( col flowgo.LightCollection, err error, )
func (*DefaultStore) CommitBlock ¶ added in v0.40.0
func (s *DefaultStore) CommitBlock( ctx context.Context, block flowgo.Block, collections []*flowgo.LightCollection, transactions map[flowgo.Identifier]*flowgo.TransactionBody, transactionResults map[flowgo.Identifier]*types.StorableTransactionResult, executionSnapshot *snapshot.ExecutionSnapshot, events []flowgo.Event, systemTransactions *SystemTransactions, ) error
func (*DefaultStore) EventsByHeight ¶ added in v0.40.0
func (*DefaultStore) ForkedBlockHeight ¶ added in v0.62.0
func (s *DefaultStore) ForkedBlockHeight(ctx context.Context) (forkedBlockHeight uint64, err error)
ForkedBlockHeight returns the height of the block at which the chain forked from a live network. All blocks after this height were produced by the emulator.
func (*DefaultStore) FullCollectionByID ¶ added in v0.59.1
func (s *DefaultStore) FullCollectionByID( ctx context.Context, colID flowgo.Identifier, ) ( col flowgo.Collection, err error, )
func (*DefaultStore) IndexScheduledTransactionID ¶ added in v1.11.0
func (s *DefaultStore) IndexScheduledTransactionID(ctx context.Context, scheduledTxID uint64, blockID flowgo.Identifier) error
IndexScheduledTransactionID stores the global mapping from scheduled transaction ID to block ID.
func (*DefaultStore) InsertCollection ¶ added in v0.40.0
func (s *DefaultStore) InsertCollection(ctx context.Context, col flowgo.LightCollection) error
func (*DefaultStore) InsertEvents ¶ added in v0.40.0
func (*DefaultStore) InsertExecutionSnapshot ¶ added in v0.46.0
func (s *DefaultStore) InsertExecutionSnapshot( ctx context.Context, blockHeight uint64, executionSnapshot *snapshot.ExecutionSnapshot, ) error
func (*DefaultStore) InsertTransaction ¶ added in v0.40.0
func (s *DefaultStore) InsertTransaction(ctx context.Context, tx flowgo.TransactionBody, id flowgo.Identifier) error
func (*DefaultStore) InsertTransactionResult ¶ added in v0.40.0
func (s *DefaultStore) InsertTransactionResult( ctx context.Context, txID flowgo.Identifier, result types.StorableTransactionResult, ) error
func (*DefaultStore) LatestBlock ¶ added in v0.40.0
func (*DefaultStore) LatestBlockHeight ¶ added in v0.40.0
func (s *DefaultStore) LatestBlockHeight(ctx context.Context) (latestBlockHeight uint64, err error)
func (*DefaultStore) LedgerByHeight ¶ added in v0.46.0
func (s *DefaultStore) LedgerByHeight( ctx context.Context, blockHeight uint64, ) (snapshot.StorageSnapshot, error)
func (*DefaultStore) SetBlockHeight ¶ added in v0.46.0
func (s *DefaultStore) SetBlockHeight(height uint64) error
func (*DefaultStore) Start ¶ added in v0.46.0
func (s *DefaultStore) Start() error
func (*DefaultStore) Stop ¶ added in v0.46.0
func (s *DefaultStore) Stop()
func (*DefaultStore) StoreBlock ¶ added in v0.40.0
func (*DefaultStore) StoreForkedBlockHeight ¶ added in v0.62.0
func (s *DefaultStore) StoreForkedBlockHeight(ctx context.Context, height uint64) error
func (*DefaultStore) StoreSystemTransactions ¶ added in v1.11.0
func (s *DefaultStore) StoreSystemTransactions(ctx context.Context, systemTransactions *SystemTransactions) error
func (*DefaultStore) SystemTransactionsForBlockID ¶ added in v1.11.0
func (s *DefaultStore) SystemTransactionsForBlockID(ctx context.Context, blockID flowgo.Identifier) (*SystemTransactions, error)
func (*DefaultStore) TransactionByID ¶ added in v0.40.0
func (s *DefaultStore) TransactionByID( ctx context.Context, txID flowgo.Identifier, ) ( tx flowgo.TransactionBody, err error, )
func (*DefaultStore) TransactionResultByID ¶ added in v0.40.0
func (s *DefaultStore) TransactionResultByID( ctx context.Context, txID flowgo.Identifier, ) ( result types.StorableTransactionResult, err error, )
type KeyGenerator ¶ added in v0.40.0
type RollbackProvider ¶ added in v0.46.0
type SnapshotProvider ¶ added in v0.44.0
type Store ¶
type Store interface {
graceland.Routine
LatestBlockHeight(ctx context.Context) (uint64, error)
// LatestBlock returns the block with the highest block height.
LatestBlock(ctx context.Context) (flowgo.Block, error)
// StoreBlock stores the block in storage. If the exactly same block is already in a storage, return successfully
StoreBlock(ctx context.Context, block *flowgo.Block) error
// store systemtransaction in a block
StoreSystemTransactions(ctx context.Context, systemTransactions *SystemTransactions) error
// get system transactions for a block height
//
SystemTransactionsForBlockID(ctx context.Context, blockID flowgo.Identifier) (*SystemTransactions, error)
// IndexScheduledTransactionID indexes a scheduled transaction ID to its block ID (global index).
// This allows looking up which block contains a given scheduled transaction.
IndexScheduledTransactionID(ctx context.Context, scheduledTxID uint64, blockID flowgo.Identifier) error
// BlockIDByScheduledTransactionID returns the block ID for a given scheduled transaction ID.
// Returns ErrNotFound if the scheduled transaction ID is not indexed.
BlockIDByScheduledTransactionID(ctx context.Context, scheduledTxID uint64) (flowgo.Identifier, error)
// BlockByID returns the block with the given hash. It is available for
// finalized and ambiguous blocks.
BlockByID(ctx context.Context, blockID flowgo.Identifier) (*flowgo.Block, error)
// BlockByHeight returns the block at the given height. It is only available
// for finalized blocks.
BlockByHeight(ctx context.Context, height uint64) (*flowgo.Block, error)
// CommitBlock atomically saves the execution results for a block.
CommitBlock(
ctx context.Context,
block flowgo.Block,
collections []*flowgo.LightCollection,
transactions map[flowgo.Identifier]*flowgo.TransactionBody,
transactionResults map[flowgo.Identifier]*types.StorableTransactionResult,
executionSnapshot *snapshot.ExecutionSnapshot,
events []flowgo.Event,
systemSystemTransactions *SystemTransactions,
) error
// CollectionByID gets the collection (transaction IDs only) with the given ID.
CollectionByID(ctx context.Context, collectionID flowgo.Identifier) (flowgo.LightCollection, error)
// FullCollectionByID gets the full collection (including transaction bodies) with the given ID.
FullCollectionByID(ctx context.Context, collectionID flowgo.Identifier) (flowgo.Collection, error)
// TransactionByID gets the transaction with the given ID.
TransactionByID(ctx context.Context, transactionID flowgo.Identifier) (flowgo.TransactionBody, error)
// TransactionResultByID gets the transaction result with the given ID.
TransactionResultByID(ctx context.Context, transactionID flowgo.Identifier) (types.StorableTransactionResult, error)
// LedgerByHeight returns a storage snapshot into the ledger state
// at a given block.
LedgerByHeight(
ctx context.Context,
blockHeight uint64,
) (snapshot.StorageSnapshot, error)
// EventsByHeight returns the events in the block at the given height, optionally filtered by type.
EventsByHeight(ctx context.Context, blockHeight uint64, eventType string) ([]flowgo.Event, error)
}
Store defines the storage layer for persistent chain state.
This includes finalized blocks and transactions, and the resultant register states and emitted events. It does not include pending state, such as pending transactions and register states.
Implementations must distinguish between not found errors and errors with the underlying storage by returning an instance of store.ErrNotFound if a resource cannot be found.
Implementations must be safe for use by multiple goroutines.
type SystemTransactions ¶ added in v1.11.0
type SystemTransactions struct {
BlockID flowgo.Identifier
Transactions []flowgo.Identifier
ScheduledTransactionIDs map[uint64]flowgo.Identifier // maps scheduled tx ID (uint64) to transaction ID
}