storage

package
v1.0.0-M3 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package storage defines the interface and implementations for interacting with persistent chain state.

Index

Constants

View Source
const (
	BlockIndexStoreName        = "blockIndex"
	BlockStoreName             = "blocks"
	CollectionStoreName        = "collections"
	TransactionStoreName       = "transactions"
	TransactionResultStoreName = "transactionResults"
	EventStoreName             = "events"
	LedgerStoreName            = "ledger"
)

Variables

View Source
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 DataGetter interface {
	GetBytes(ctx context.Context, store string, key []byte) ([]byte, error)
	GetBytesAtVersion(ctx context.Context, store string, key []byte, version uint64) ([]byte, error)
}

type DataSetter added in v0.40.0

type DataSetter interface {
	SetBytes(ctx context.Context, store string, key []byte, value []byte) error
	SetBytesWithVersion(ctx context.Context, store string, key []byte, value []byte, version uint64) error
}

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) 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) 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 (s *DefaultStore) BlockByHeight(ctx context.Context, blockHeight uint64) (block *flowgo.Block, err error)

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) 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,
) error

func (*DefaultStore) EventsByHeight added in v0.40.0

func (s *DefaultStore) EventsByHeight(ctx context.Context, blockHeight uint64, eventType string) (events []flowgo.Event, err error)

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 (s *DefaultStore) InsertEvents(ctx context.Context, blockHeight uint64, events []flowgo.Event) error

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) 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 (s *DefaultStore) LatestBlock(ctx context.Context) (block flowgo.Block, err error)

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 (s *DefaultStore) StoreBlock(ctx context.Context, block *flowgo.Block) 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 KeyGenerator interface {
	Storage(key string) string
	LatestBlock() []byte
	BlockHeight(height uint64) []byte
	Identifier(id flowgo.Identifier) []byte
}

type RollbackProvider added in v0.46.0

type RollbackProvider interface {
	RollbackToBlockHeight(height uint64) error
}

type SnapshotProvider added in v0.44.0

type SnapshotProvider interface {
	Snapshots() ([]string, error)
	CreateSnapshot(snapshotName string) error
	LoadSnapshot(snapshotName string) error
	SupportSnapshotsWithCurrentConfig() bool
}

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

	// 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,
	) error

	// CollectionByID gets the collection (transaction IDs only) with the given ID.
	CollectionByID(ctx context.Context, collectionID flowgo.Identifier) (flowgo.LightCollection, 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.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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