storage

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("Not Found")
	ErrLayerNotFound      = errors.New("Block Not Found")
	ErrWriteToReadOnly    = errors.New("attempted write to read-only transaction")
	ErrUnknownStorageType = errors.New("unknown storage type")
)
View Source
var EmptyHash = types.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")

Functions

This section is empty.

Types

type Initializer added in v1.2.0

type Initializer interface {
	SetBlockData(hash, parentHash types.Hash, number uint64, weight *big.Int)
	AddData(key, value []byte)
	Close()
}

type KeyValue

type KeyValue struct {
	Key   []byte `avro:"key"`
	Value []byte `avro:"value"`
}

func (KeyValue) String

func (kv KeyValue) String() string

type NullWaiter added in v1.3.0

type NullWaiter struct{}

func (NullWaiter) WaitForHash added in v1.3.0

func (NullWaiter) WaitForHash(types.Hash, time.Duration)

func (NullWaiter) WaitForNumber added in v1.3.0

func (NullWaiter) WaitForNumber(int64, time.Duration)

type Storage

type Storage interface {
	// View returns a transaction for interfacing with the layer indicated by the
	// specified hash.
	View(types.Hash, func(Transaction) error) error
	// AddBlock adds a new block to the storage engine. An error will be returned
	// if the parent specified does not exist. If `weight` exceeds the weight of
	// any previously handled block, this block will be returned in future calls
	// to `LatestHash()`. `blockData` and `stateUpdates` will be tracked against
	// this block and eventually persisted. The `resumption` byte string will be
	// provided by the information source, so that backups recovering from this
	// storage engine can determine where to resume from.
	AddBlock(hash, parentHash types.Hash, number uint64, weight *big.Int, updates []KeyValue, deletes [][]byte, resumption []byte) error

	// LatestHash returns the block with the highest weight added through AddBlock
	LatestHash() types.Hash

	// NumberToHash will convert a number to a hash within the range of blocks
	// that can be queried by this Storage interface
	NumberToHash(uint64) (types.Hash, error)

	// Roll back the storage engine to the specified block number in its history
	Rollback(uint64) error

	// LatestBlock returns the hash, height, weight, and resumption token of the
	// latest block
	LatestBlock() (types.Hash, uint64, *big.Int, []byte)

	// Close cleanly shuts down the storage interface.
	Close() error

	RegisterWaiter(Waiter, time.Duration)

	// Vacuum frees space in the database. `rollback` indicates the number of
	// deltas to retain to support rollbacks, while gcTime is the an approximate
	// amount of time to spend on database level compaction.
	Vacuum(rollback uint64, gcTime time.Duration)
}

type Transaction

type Transaction interface {
	// Get returns the data stored at a given key.
	Get([]byte) ([]byte, error)
	// ZeroCopyGet invokes the provided closure with the data stored at the given
	// key. The data should not be modified, and should not be accessed outside
	// the closure without being copied.
	ZeroCopyGet([]byte, func([]byte) error) error
	// NumberToHash returns a block hash given a block number. This may or may
	// not be able to go back to the genesis block, but likely goes back further
	// than Storage.NumberToHash
	NumberToHash(uint64) types.Hash
	// HashToNumber returns the block number corresponding to the given hash.
	// This may or may not be able to go back to the genesis block.
	HashToNumber(types.Hash) uint64
}

type Waiter added in v1.3.0

type Waiter interface {
	WaitForHash(types.Hash, time.Duration)
	WaitForNumber(int64, time.Duration)
}

Directories

Path Synopsis
cmd
db
mem

Jump to

Keyboard shortcuts

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