storage

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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) Event added in v0.40.0

func (s *DefaultKeyGenerator) Event(blockHeight uint64, txIndex, eventIndex uint32, eventType flowgo.EventType) []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
}

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,
	delta delta.Delta,
	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) InsertLedgerDelta added in v0.40.0

func (s *DefaultStore) InsertLedgerDelta(ctx context.Context, blockHeight uint64, delta delta.Delta) 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) LedgerViewByHeight added in v0.40.0

func (s *DefaultStore) LedgerViewByHeight(ctx context.Context, blockHeight uint64) *delta.View

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
	Event(blockHeight uint64, txIndex, eventIndex uint32, eventType flowgo.EventType) []byte
}

type SnapshotProvider added in v0.44.0

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

type Store

type Store interface {
	LatestBlockHeight(ctx context.Context) (uint64, error)

	// LatestBlock returns the block with the highest block height.
	LatestBlock(ctx context.Context) (flowgo.Block, error)

	// Store stores the block. 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,
		delta delta.Delta,
		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)

	// LedgerViewByHeight returns a view into the ledger state at a given block.
	LedgerViewByHeight(ctx context.Context, blockHeight uint64) *delta.View

	// 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