storage

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DIFFICULTY is the difficulty prefix
	DIFFICULTY = []byte("d")

	// HEADER is the header prefix
	HEADER = []byte("h")

	// HEAD is the chain head prefix
	HEAD = []byte("o")

	// FORK is the entry to store forks
	FORK = []byte("f")

	// CANONICAL is the prefix for the canonical chain numbers
	CANONICAL = []byte("c")

	// BODY is the prefix for bodies
	BODY = []byte("b")

	// RECEIPTS is the prefix for receipts
	RECEIPTS = []byte("r")

	// SNAPSHOTS is the prefix for snapshots
	SNAPSHOTS = []byte("s")

	// TX_LOOKUP_PREFIX is the prefix for transaction lookups
	TX_LOOKUP_PREFIX = []byte("l")
)

Prefixes for the key-value store

View Source
var (
	HASH   = []byte("hash")
	NUMBER = []byte("number")
	EMPTY  = []byte("empty")
)

Sub-prefixes

View Source
var ErrNotFound = fmt.Errorf("not found")

Functions

func TestStorage

func TestStorage(t *testing.T, m PlaceholderStorage)

TestStorage tests a set of tests on a storage

Types

type Batch

type Batch interface {
	Delete(key []byte)
	Write() error
	Put(k []byte, v []byte)
}

type BatchWriter

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

func NewBatchWriter

func NewBatchWriter(storage Storage) *BatchWriter

func (*BatchWriter) PutBody

func (b *BatchWriter) PutBody(hash types.Hash, body *types.Body)

func (*BatchWriter) PutCanonicalHash

func (b *BatchWriter) PutCanonicalHash(n uint64, hash types.Hash)

func (*BatchWriter) PutCanonicalHeader

func (b *BatchWriter) PutCanonicalHeader(h *types.Header, diff *big.Int)

func (*BatchWriter) PutForks

func (b *BatchWriter) PutForks(forks []types.Hash)

func (*BatchWriter) PutHeadHash

func (b *BatchWriter) PutHeadHash(h types.Hash)

func (*BatchWriter) PutHeadNumber

func (b *BatchWriter) PutHeadNumber(n uint64)

func (*BatchWriter) PutHeader

func (b *BatchWriter) PutHeader(h *types.Header)

func (*BatchWriter) PutReceipts

func (b *BatchWriter) PutReceipts(hash types.Hash, receipts []*types.Receipt)

func (*BatchWriter) PutTotalDifficulty

func (b *BatchWriter) PutTotalDifficulty(hash types.Hash, diff *big.Int)

func (*BatchWriter) PutTxLookup

func (b *BatchWriter) PutTxLookup(hash types.Hash, blockHash types.Hash)

func (*BatchWriter) WriteBatch

func (b *BatchWriter) WriteBatch() error

type Factory

type Factory func(config map[string]interface{}, logger hclog.Logger) (Storage, error)

Factory is a factory method to create a blockchain storage

type Forks

type Forks []types.Hash

func (*Forks) MarshalRLPTo

func (f *Forks) MarshalRLPTo(dst []byte) []byte

MarshalRLPTo is a wrapper function for calling the type marshal implementation

func (*Forks) MarshalRLPWith

func (f *Forks) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith is the actual RLP marshal implementation for the type

func (*Forks) UnmarshalRLP

func (f *Forks) UnmarshalRLP(input []byte) error

UnmarshalRLP is a wrapper function for calling the type unmarshal implementation

func (*Forks) UnmarshalRLPFrom

func (f *Forks) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLPFrom is the actual RLP unmarshal implementation for the type

type KV

type KV interface {
	Close() error
	Get(p []byte) ([]byte, bool, error)
	NewBatch() Batch
}

KV is a key value storage interface.

KV = Key-Value

type KeyValueStorage

type KeyValueStorage struct {
	Db KV
	// contains filtered or unexported fields
}

KeyValueStorage is a generic storage for kv databases

func (*KeyValueStorage) Close

func (s *KeyValueStorage) Close() error

Close closes the connection with the db

func (*KeyValueStorage) NewBatch

func (s *KeyValueStorage) NewBatch() Batch

NewBatch creates batch used for write/update/delete operations

func (*KeyValueStorage) ReadBody

func (s *KeyValueStorage) ReadBody(hash types.Hash) (*types.Body, error)

ReadBody reads the body

func (*KeyValueStorage) ReadCanonicalHash

func (s *KeyValueStorage) ReadCanonicalHash(n uint64) (types.Hash, bool)

ReadCanonicalHash gets the hash from the number of the canonical chain

func (*KeyValueStorage) ReadForks

func (s *KeyValueStorage) ReadForks() ([]types.Hash, error)

ReadForks read the current forks

func (*KeyValueStorage) ReadHeadHash

func (s *KeyValueStorage) ReadHeadHash() (types.Hash, bool)

ReadHeadHash returns the hash of the head

func (*KeyValueStorage) ReadHeadNumber

func (s *KeyValueStorage) ReadHeadNumber() (uint64, bool)

ReadHeadNumber returns the number of the head

func (*KeyValueStorage) ReadHeader

func (s *KeyValueStorage) ReadHeader(hash types.Hash) (*types.Header, error)

ReadHeader reads the header

func (*KeyValueStorage) ReadReceipts

func (s *KeyValueStorage) ReadReceipts(hash types.Hash) ([]*types.Receipt, error)

ReadReceipts reads the receipts

func (*KeyValueStorage) ReadTotalDifficulty

func (s *KeyValueStorage) ReadTotalDifficulty(hash types.Hash) (*big.Int, bool)

ReadTotalDifficulty reads the difficulty

func (*KeyValueStorage) ReadTxLookup

func (s *KeyValueStorage) ReadTxLookup(hash types.Hash) (types.Hash, bool)

ReadTxLookup reads the block hash using the transaction hash

type MockStorage

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

func NewMockStorage

func NewMockStorage() *MockStorage

func (*MockStorage) Close

func (m *MockStorage) Close() error

func (*MockStorage) HookClose

func (m *MockStorage) HookClose(fn closeDelegate)

func (*MockStorage) HookNewBatch

func (m *MockStorage) HookNewBatch(fn newBatchDelegate)

func (*MockStorage) HookReadBody

func (m *MockStorage) HookReadBody(fn readBodyDelegate)

func (*MockStorage) HookReadCanonicalHash

func (m *MockStorage) HookReadCanonicalHash(fn readCanonicalHashDelegate)

func (*MockStorage) HookReadForks

func (m *MockStorage) HookReadForks(fn readForksDelegate)

func (*MockStorage) HookReadHeadHash

func (m *MockStorage) HookReadHeadHash(fn readHeadHashDelegate)

func (*MockStorage) HookReadHeadNumber

func (m *MockStorage) HookReadHeadNumber(fn readHeadNumberDelegate)

func (*MockStorage) HookReadHeader

func (m *MockStorage) HookReadHeader(fn readHeaderDelegate)

func (*MockStorage) HookReadReceipts

func (m *MockStorage) HookReadReceipts(fn readReceiptsDelegate)

func (*MockStorage) HookReadTotalDifficulty

func (m *MockStorage) HookReadTotalDifficulty(fn readTotalDifficultyDelegate)

func (*MockStorage) HookReadTxLookup

func (m *MockStorage) HookReadTxLookup(fn readTxLookupDelegate)

func (*MockStorage) NewBatch

func (m *MockStorage) NewBatch() Batch

func (*MockStorage) ReadBody

func (m *MockStorage) ReadBody(hash types.Hash) (*types.Body, error)

func (*MockStorage) ReadCanonicalHash

func (m *MockStorage) ReadCanonicalHash(n uint64) (types.Hash, bool)

func (*MockStorage) ReadForks

func (m *MockStorage) ReadForks() ([]types.Hash, error)

func (*MockStorage) ReadHeadHash

func (m *MockStorage) ReadHeadHash() (types.Hash, bool)

func (*MockStorage) ReadHeadNumber

func (m *MockStorage) ReadHeadNumber() (uint64, bool)

func (*MockStorage) ReadHeader

func (m *MockStorage) ReadHeader(hash types.Hash) (*types.Header, error)

func (*MockStorage) ReadReceipts

func (m *MockStorage) ReadReceipts(hash types.Hash) ([]*types.Receipt, error)

func (*MockStorage) ReadTotalDifficulty

func (m *MockStorage) ReadTotalDifficulty(hash types.Hash) (*big.Int, bool)

func (*MockStorage) ReadTxLookup

func (m *MockStorage) ReadTxLookup(hash types.Hash) (types.Hash, bool)

type PlaceholderStorage

type PlaceholderStorage func(t *testing.T) (Storage, func())

type Storage

type Storage interface {
	ReadCanonicalHash(n uint64) (types.Hash, bool)

	ReadHeadHash() (types.Hash, bool)
	ReadHeadNumber() (uint64, bool)

	ReadForks() ([]types.Hash, error)

	ReadTotalDifficulty(hash types.Hash) (*big.Int, bool)

	ReadHeader(hash types.Hash) (*types.Header, error)

	ReadBody(hash types.Hash) (*types.Body, error)

	ReadReceipts(hash types.Hash) ([]*types.Receipt, error)

	ReadTxLookup(hash types.Hash) (types.Hash, bool)

	NewBatch() Batch

	Close() error
}

Storage is a generic blockchain storage

func NewKeyValueStorage

func NewKeyValueStorage(logger hclog.Logger, db KV) Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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