rawdb

package
v1.13.8 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package rawdb contains a collection of low level database accessors.

Index

Constants

View Source
const (
	// ChainFreezerHeaderTable indicates the name of the freezer header table.
	ChainFreezerHeaderTable = "headers"

	// ChainFreezerHashTable indicates the name of the freezer canonical hash table.
	ChainFreezerHashTable = "hashes"

	// ChainFreezerBodiesTable indicates the name of the freezer block body table.
	ChainFreezerBodiesTable = "bodies"

	// ChainFreezerReceiptTable indicates the name of the freezer receipts table.
	ChainFreezerReceiptTable = "receipts"

	// ChainFreezerDifficultyTable indicates the name of the freezer total difficulty table.
	ChainFreezerDifficultyTable = "diffs"
)

The list of table names of chain freezer.

View Source
const HashScheme = "hashScheme"

HashScheme is the legacy hash-based state scheme with which trie nodes are stored in the disk with node hash as the database key. The advantage of this scheme is that different versions of trie nodes can be stored in disk, which is very beneficial for constructing archive nodes. The drawback is it will store different trie nodes on the same path to different locations on the disk with no data locality, and it's unfriendly for designing state pruning.

Now this scheme is still kept for backward compatibility, and it will be used for archive node and some other tries(e.g. light trie).

View Source
const PathScheme = "pathScheme"

PathScheme is the new path-based state scheme with which trie nodes are stored in the disk with node path as the database key. This scheme will only store one version of state data in the disk, which means that the state pruning operation is native. At the same time, this scheme will put adjacent trie nodes in the same area of the disk with good data locality property. But this scheme needs to rely on extra state diffs to survive deep reorg.

View Source
const PebbleEnabled = true

Pebble is unsuported on 32bit architecture

Variables

View Source
var (

	// SnapshotRootKey tracks the hash of the last snapshot.
	SnapshotRootKey = []byte("SnapshotRoot")

	SnapshotAccountPrefix = []byte("a") // SnapshotAccountPrefix + account hash -> account trie value
	SnapshotStoragePrefix = []byte("o") // SnapshotStoragePrefix + account hash + storage hash -> storage trie value
	CodePrefix            = []byte("c") // CodePrefix + code hash -> account code

	PreimagePrefix = []byte("secure-key-") // PreimagePrefix + hash -> preimage

	// BloomBitsIndexPrefix is the data table of a chain indexer to track its progress
	BloomBitsIndexPrefix = []byte("iB")

	ChtPrefix           = []byte("chtRootV2-") // ChtPrefix + chtNum (uint64 big endian) -> trie root hash
	ChtTablePrefix      = []byte("cht-")
	ChtIndexTablePrefix = []byte("chtIndexV2-")

	BloomTriePrefix      = []byte("bltRoot-") // BloomTriePrefix + bloomTrieNum (uint64 big endian) -> trie root hash
	BloomTrieTablePrefix = []byte("blt-")
	BloomTrieIndexPrefix = []byte("bltIndex-")

	CliqueSnapshotPrefix = []byte("clique-")
)

The fields below define the low level database schema prefixing.

Functions

func DeleteAccountSnapshot

func DeleteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash)

DeleteAccountSnapshot removes the snapshot entry of an account trie leaf.

func DeleteAccountTrieNode

func DeleteAccountTrieNode(db ethdb.KeyValueWriter, path []byte)

DeleteAccountTrieNode deletes the specified account trie node from the database.

func DeleteBadBlocks

func DeleteBadBlocks(db ethdb.KeyValueWriter)

DeleteBadBlocks deletes all the bad blocks from the database

func DeleteBlock

func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteBlock removes all block data associated with a hash.

func DeleteBlockWithoutNumber

func DeleteBlockWithoutNumber(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteBlockWithoutNumber removes all block data associated with a hash, except the hash to number mapping.

func DeleteBloombits

func DeleteBloombits(db ethdb.Database, bit uint, from uint64, to uint64)

DeleteBloombits removes all compressed bloom bits vector belonging to the given section range and bit index.

func DeleteBody

func DeleteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteBody removes all block body data associated with a hash.

func DeleteCanonicalHash

func DeleteCanonicalHash(db ethdb.KeyValueWriter, number uint64)

DeleteCanonicalHash removes the number to hash canonical mapping.

func DeleteCode

func DeleteCode(db ethdb.KeyValueWriter, hash common.Hash)

DeleteCode deletes the specified contract code from the database.

func DeleteHeader

func DeleteHeader(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteHeader removes all block header data associated with a hash.

func DeleteHeaderNumber

func DeleteHeaderNumber(db ethdb.KeyValueWriter, hash common.Hash)

DeleteHeaderNumber removes hash->number mapping.

func DeleteLegacyTrieNode

func DeleteLegacyTrieNode(db ethdb.KeyValueWriter, hash common.Hash)

DeleteLegacyTrieNode deletes the specified legacy trie node from database.

func DeleteReceipts

func DeleteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteReceipts removes all receipt data associated with a block hash.

func DeleteSkeletonHeader

func DeleteSkeletonHeader(db ethdb.KeyValueWriter, number uint64)

DeleteSkeletonHeader removes all block header data associated with a hash.

func DeleteSkeletonSyncStatus

func DeleteSkeletonSyncStatus(db ethdb.KeyValueWriter)

DeleteSkeletonSyncStatus deletes the serialized sync status saved at the last shutdown

func DeleteSnapshotDisabled

func DeleteSnapshotDisabled(db ethdb.KeyValueWriter)

DeleteSnapshotDisabled deletes the flag keeping the snapshot maintenance disabled.

func DeleteSnapshotGenerator

func DeleteSnapshotGenerator(db ethdb.KeyValueWriter)

DeleteSnapshotGenerator deletes the serialized snapshot generator saved at the last shutdown

func DeleteSnapshotJournal

func DeleteSnapshotJournal(db ethdb.KeyValueWriter)

DeleteSnapshotJournal deletes the serialized in-memory diff layers saved at the last shutdown

func DeleteSnapshotRecoveryNumber

func DeleteSnapshotRecoveryNumber(db ethdb.KeyValueWriter)

DeleteSnapshotRecoveryNumber deletes the block number of the last persisted snapshot layer.

func DeleteSnapshotRoot

func DeleteSnapshotRoot(db ethdb.KeyValueWriter)

DeleteSnapshotRoot deletes the hash of the block whose state is contained in the persisted snapshot. Since snapshots are not immutable, this method can be used during updates, so a crash or failure will mark the entire snapshot invalid.

func DeleteStateID

func DeleteStateID(db ethdb.KeyValueWriter, root common.Hash)

DeleteStateID deletes the specified state lookup from the database.

func DeleteStorageSnapshot

func DeleteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash common.Hash)

DeleteStorageSnapshot removes the snapshot entry of an storage trie leaf.

func DeleteStorageTrieNode

func DeleteStorageTrieNode(db ethdb.KeyValueWriter, accountHash common.Hash, path []byte)

DeleteStorageTrieNode deletes the specified storage trie node from the database.

func DeleteTd

func DeleteTd(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

DeleteTd removes all block total difficulty data associated with a hash.

func DeleteTrieJournal

func DeleteTrieJournal(db ethdb.KeyValueWriter)

DeleteTrieJournal deletes the serialized in-memory trie nodes of layers saved at the last shutdown.

func DeleteTrieNode

func DeleteTrieNode(db ethdb.KeyValueWriter, owner common.Hash, path []byte, hash common.Hash, scheme string)

DeleteTrieNode deletes the trie node from database with the provided node info and associated node hash. hashScheme-based lookup requires the following:

  • hash

pathScheme-based lookup requires the following:

  • owner
  • path

func DeleteTxLookupEntries

func DeleteTxLookupEntries(db ethdb.KeyValueWriter, hashes []common.Hash)

DeleteTxLookupEntries removes all transaction lookups for a given block.

func DeleteTxLookupEntry

func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash)

DeleteTxLookupEntry removes all transaction data associated with a hash.

func FindCommonAncestor

func FindCommonAncestor(db ethdb.Reader, a, b *types.Header) *types.Header

FindCommonAncestor returns the last common ancestor of two block headers

func HasAccountTrieNode

func HasAccountTrieNode(db ethdb.KeyValueReader, path []byte, hash common.Hash) bool

HasAccountTrieNode checks the account trie node presence with the specified node path and the associated node hash.

func HasBody

func HasBody(db ethdb.Reader, hash common.Hash, number uint64) bool

HasBody verifies the existence of a block body corresponding to the hash.

func HasCode

func HasCode(db ethdb.KeyValueReader, hash common.Hash) bool

HasCode checks if the contract code corresponding to the provided code hash is present in the db.

func HasCodeWithPrefix

func HasCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) bool

HasCodeWithPrefix checks if the contract code corresponding to the provided code hash is present in the db. This function will only check presence using the prefix-scheme.

func HasHeader

func HasHeader(db ethdb.Reader, hash common.Hash, number uint64) bool

HasHeader verifies the existence of a block header corresponding to the hash.

func HasLegacyTrieNode

func HasLegacyTrieNode(db ethdb.KeyValueReader, hash common.Hash) bool

HasLegacyTrieNode checks if the trie node with the provided hash is present in db.

func HasReceipts

func HasReceipts(db ethdb.Reader, hash common.Hash, number uint64) bool

HasReceipts verifies the existence of all the transaction receipts belonging to a block.

func HasStorageTrieNode

func HasStorageTrieNode(db ethdb.KeyValueReader, accountHash common.Hash, path []byte, hash common.Hash) bool

HasStorageTrieNode checks the storage trie node presence with the provided node path and the associated node hash.

func HasTrieNode

func HasTrieNode(db ethdb.KeyValueReader, owner common.Hash, path []byte, hash common.Hash, scheme string) bool

HasTrieNode checks the trie node presence with the provided node info and the associated node hash.

func IndexTransactions

func IndexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{})

IndexTransactions creates txlookup indices of the specified block range. The from is included while to is excluded.

This function iterates canonical chain in reverse order, it has one main advantage: We can write tx index tail flag periodically even without the whole indexing procedure is finished. So that we can resume indexing procedure next time quickly.

There is a passed channel, the whole procedure will be interrupted if any signal received.

func InitDatabaseFromFreezer

func InitDatabaseFromFreezer(db ethdb.Database)

InitDatabaseFromFreezer reinitializes an empty database from a previous batch of frozen ancient blocks. The method iterates over all the frozen blocks and injects into the database the block hash->number mappings.

func InspectDatabase

func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error

InspectDatabase traverses the entire database and checks the size of all different categories of data.

func InspectFreezerTable

func InspectFreezerTable(ancient string, freezerName string, tableName string, start, end int64) error

InspectFreezerTable dumps out the index of a specific freezer table. The passed ancient indicates the path of root ancient directory where the chain freezer can be opened. Start and end specify the range for dumping out indexes. Note this function can only be used for debugging purposes.

func IsAccountTrieNode

func IsAccountTrieNode(key []byte) (bool, []byte)

IsAccountTrieNode reports whether a provided database entry is an account trie node in path-based state scheme.

func IsCodeKey

func IsCodeKey(key []byte) (bool, []byte)

IsCodeKey reports whether the given byte slice is the key of contract code, if so return the raw code hash as well.

func IsLegacyTrieNode

func IsLegacyTrieNode(key []byte, val []byte) bool

IsLegacyTrieNode reports whether a provided database entry is a legacy trie node. The characteristics of legacy trie node are: - the key length is 32 bytes - the key is the hash of val

func IsStorageTrieNode

func IsStorageTrieNode(key []byte) (bool, common.Hash, []byte)

IsStorageTrieNode reports whether a provided database entry is a storage trie node in path-based state scheme.

func IterateStorageSnapshots

func IterateStorageSnapshots(db ethdb.Iteratee, accountHash common.Hash) ethdb.Iterator

IterateStorageSnapshots returns an iterator for walking the entire storage space of a specific account.

func NewDatabase

func NewDatabase(db ethdb.KeyValueStore) ethdb.Database

NewDatabase creates a high level database on top of a given key-value data store without a freezer moving immutable chain segments into cold storage.

func NewDatabaseWithFreezer

func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace string, readonly bool) (ethdb.Database, error)

NewDatabaseWithFreezer creates a high level database on top of a given key- value data store with a freezer moving immutable chain segments into cold storage. The passed ancient indicates the path of root ancient directory where the chain freezer can be opened.

func NewKeyLengthIterator

func NewKeyLengthIterator(it ethdb.Iterator, keyLen int) ethdb.Iterator

NewKeyLengthIterator returns a wrapped version of the iterator that will only return key-value pairs where keys with a specific key length will be returned.

func NewLevelDBDatabase

func NewLevelDBDatabase(file string, cache int, handles int, namespace string, readonly bool) (ethdb.Database, error)

NewLevelDBDatabase creates a persistent key-value database without a freezer moving immutable chain segments into cold storage.

func NewMemoryDatabase

func NewMemoryDatabase() ethdb.Database

NewMemoryDatabase creates an ephemeral in-memory key-value database without a freezer moving immutable chain segments into cold storage.

func NewMemoryDatabaseWithCap

func NewMemoryDatabaseWithCap(size int) ethdb.Database

NewMemoryDatabaseWithCap creates an ephemeral in-memory key-value database with an initial starting capacity, but without a freezer moving immutable chain segments into cold storage.

func NewPebbleDBDatabase

func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly bool) (ethdb.Database, error)

NewPebbleDBDatabase creates a persistent key-value database without a freezer moving immutable chain segments into cold storage.

func NewTable

func NewTable(db ethdb.Database, prefix string) ethdb.Database

NewTable returns a database object that prefixes all keys with a given string.

func Open

func Open(o OpenOptions) (ethdb.Database, error)

Open opens both a disk-based key-value database such as leveldb or pebble, but also integrates it with a freezer database -- if the AncientDir option has been set on the provided OpenOptions. The passed o.AncientDir indicates the path of root ancient directory where the chain freezer can be opened.

func PopUncleanShutdownMarker

func PopUncleanShutdownMarker(db ethdb.KeyValueStore)

PopUncleanShutdownMarker removes the last unclean shutdown marker

func PushUncleanShutdownMarker

func PushUncleanShutdownMarker(db ethdb.KeyValueStore) ([]uint64, uint64, error)

PushUncleanShutdownMarker appends a new unclean shutdown marker and returns the previous data - a list of timestamps - a count of how many old unclean-shutdowns have been discarded

func ReadAccountSnapshot

func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) []byte

ReadAccountSnapshot retrieves the snapshot entry of an account trie leaf.

func ReadAccountTrieNode

func ReadAccountTrieNode(db ethdb.KeyValueReader, path []byte) ([]byte, common.Hash)

ReadAccountTrieNode retrieves the account trie node and the associated node hash with the specified node path.

func ReadAllBadBlocks

func ReadAllBadBlocks(db ethdb.Reader) []*types.Block

ReadAllBadBlocks retrieves all the bad blocks in the database. All returned blocks are sorted in reverse order by number.

func ReadAllCanonicalHashes

func ReadAllCanonicalHashes(db ethdb.Iteratee, from uint64, to uint64, limit int) ([]uint64, []common.Hash)

ReadAllCanonicalHashes retrieves all canonical number and hash mappings at the certain chain range. If the accumulated entries reaches the given threshold, abort the iteration and return the semi-finish result.

func ReadAllHashes

func ReadAllHashes(db ethdb.Iteratee, number uint64) []common.Hash

ReadAllHashes retrieves all the hashes assigned to blocks at a certain heights, both canonical and reorged forks included.

func ReadBadBlock

func ReadBadBlock(db ethdb.Reader, hash common.Hash) *types.Block

ReadBadBlock retrieves the bad block with the corresponding block hash.

func ReadBlock

func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block

ReadBlock retrieves an entire block corresponding to the hash, assembling it back from the stored header and body. If either the header or body could not be retrieved nil is returned.

Note, due to concurrent download of header and block body the header and thus canonical hash can be stored in the database but the body data not (yet).

func ReadBloomBits

func ReadBloomBits(db ethdb.KeyValueReader, bit uint, section uint64, head common.Hash) ([]byte, error)

ReadBloomBits retrieves the compressed bloom bit vector belonging to the given section and bit index from the.

func ReadBody

func ReadBody(db ethdb.Reader, hash common.Hash, number uint64) *types.Body

ReadBody retrieves the block body corresponding to the hash.

func ReadBodyRLP

func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue

ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.

func ReadCanonicalBodyRLP

func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64) rlp.RawValue

ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the canonical block at number, in RLP encoding.

func ReadCanonicalHash

func ReadCanonicalHash(db ethdb.Reader, number uint64) common.Hash

ReadCanonicalHash retrieves the hash assigned to a canonical block number.

func ReadChainConfig

func ReadChainConfig(db ethdb.KeyValueReader, hash common.Hash) *params.ChainConfig

ReadChainConfig retrieves the consensus settings based on the given genesis hash.

func ReadChainMetadata

func ReadChainMetadata(db ethdb.KeyValueStore) [][]string

ReadChainMetadata returns a set of key/value pairs that contains informatin about the database chain status. This can be used for diagnostic purposes when investigating the state of the node.

func ReadCode

func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte

ReadCode retrieves the contract code of the provided code hash.

func ReadCodeWithPrefix

func ReadCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) []byte

ReadCodeWithPrefix retrieves the contract code of the provided code hash. The main difference between this function and ReadCode is this function will only check the existence with latest scheme(with prefix).

func ReadDatabaseVersion

func ReadDatabaseVersion(db ethdb.KeyValueReader) *uint64

ReadDatabaseVersion retrieves the version number of the database.

func ReadFastTxLookupLimit

func ReadFastTxLookupLimit(db ethdb.KeyValueReader) *uint64

ReadFastTxLookupLimit retrieves the tx lookup limit used in fast sync.

func ReadFinalizedBlockHash

func ReadFinalizedBlockHash(db ethdb.KeyValueReader) common.Hash

ReadFinalizedBlockHash retrieves the hash of the finalized block.

func ReadGenesisStateSpec

func ReadGenesisStateSpec(db ethdb.KeyValueReader, blockhash common.Hash) []byte

ReadGenesisStateSpec retrieves the genesis state specification based on the given genesis (block-)hash.

func ReadHeadBlock

func ReadHeadBlock(db ethdb.Reader) *types.Block

ReadHeadBlock returns the current canonical head block.

func ReadHeadBlockHash

func ReadHeadBlockHash(db ethdb.KeyValueReader) common.Hash

ReadHeadBlockHash retrieves the hash of the current canonical head block.

func ReadHeadFastBlockHash

func ReadHeadFastBlockHash(db ethdb.KeyValueReader) common.Hash

ReadHeadFastBlockHash retrieves the hash of the current fast-sync head block.

func ReadHeadHeader

func ReadHeadHeader(db ethdb.Reader) *types.Header

ReadHeadHeader returns the current canonical head header.

func ReadHeadHeaderHash

func ReadHeadHeaderHash(db ethdb.KeyValueReader) common.Hash

ReadHeadHeaderHash retrieves the hash of the current canonical head header.

func ReadHeader

func ReadHeader(db ethdb.Reader, hash common.Hash, number uint64) *types.Header

ReadHeader retrieves the block header corresponding to the hash.

func ReadHeaderNumber

func ReadHeaderNumber(db ethdb.KeyValueReader, hash common.Hash) *uint64

ReadHeaderNumber returns the header number assigned to a hash.

func ReadHeaderRLP

func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue

ReadHeaderRLP retrieves a block header in its raw RLP database encoding.

func ReadHeaderRange

func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValue

ReadHeaderRange returns the rlp-encoded headers, starting at 'number', and going backwards towards genesis. This method assumes that the caller already has placed a cap on count, to prevent DoS issues. Since this method operates in head-towards-genesis mode, it will return an empty slice in case the head ('number') is missing. Hence, the caller must ensure that the head ('number') argument is actually an existing header.

N.B: Since the input is a number, as opposed to a hash, it's implicit that this method only operates on canon headers.

func ReadLastPivotNumber

func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64

ReadLastPivotNumber retrieves the number of the last pivot block. If the node full synced, the last pivot will always be nil.

func ReadLegacyTrieNode

func ReadLegacyTrieNode(db ethdb.KeyValueReader, hash common.Hash) []byte

ReadLegacyTrieNode retrieves the legacy trie node with the given associated node hash.

func ReadLogs

func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64, config *params.ChainConfig) [][]*types.Log

ReadLogs retrieves the logs for all transactions in a block. In case receipts is not found, a nil is returned. Note: ReadLogs does not derive unstored log fields.

func ReadPersistentStateID

func ReadPersistentStateID(db ethdb.KeyValueReader) uint64

ReadPersistentStateID retrieves the id of the persistent state from the database.

func ReadPreimage

func ReadPreimage(db ethdb.KeyValueReader, hash common.Hash) []byte

ReadPreimage retrieves a single preimage of the provided hash.

func ReadRawReceipts

func ReadRawReceipts(db ethdb.Reader, hash common.Hash, number uint64) types.Receipts

ReadRawReceipts retrieves all the transaction receipts belonging to a block. The receipt metadata fields are not guaranteed to be populated, so they should not be used. Use ReadReceipts instead if the metadata is needed.

func ReadReceipt

func ReadReceipt(db ethdb.Reader, hash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64)

ReadReceipt retrieves a specific transaction receipt from the database, along with its added positional metadata.

func ReadReceipts

func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64, config *params.ChainConfig) types.Receipts

ReadReceipts retrieves all the transaction receipts belonging to a block, including its corresponding metadata fields. If it is unable to populate these metadata fields then nil is returned.

The current implementation populates these metadata fields by reading the receipts' corresponding block body, so if the block body is not found it will return nil even if the receipt itself is stored.

func ReadReceiptsRLP

func ReadReceiptsRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue

ReadReceiptsRLP retrieves all the transaction receipts belonging to a block in RLP encoding.

func ReadSkeletonHeader

func ReadSkeletonHeader(db ethdb.KeyValueReader, number uint64) *types.Header

ReadSkeletonHeader retrieves a block header from the skeleton sync store,

func ReadSkeletonSyncStatus

func ReadSkeletonSyncStatus(db ethdb.KeyValueReader) []byte

ReadSkeletonSyncStatus retrieves the serialized sync status saved at shutdown.

func ReadSnapshotDisabled

func ReadSnapshotDisabled(db ethdb.KeyValueReader) bool

ReadSnapshotDisabled retrieves if the snapshot maintenance is disabled.

func ReadSnapshotGenerator

func ReadSnapshotGenerator(db ethdb.KeyValueReader) []byte

ReadSnapshotGenerator retrieves the serialized snapshot generator saved at the last shutdown.

func ReadSnapshotJournal

func ReadSnapshotJournal(db ethdb.KeyValueReader) []byte

ReadSnapshotJournal retrieves the serialized in-memory diff layers saved at the last shutdown. The blob is expected to be max a few 10s of megabytes.

func ReadSnapshotRecoveryNumber

func ReadSnapshotRecoveryNumber(db ethdb.KeyValueReader) *uint64

ReadSnapshotRecoveryNumber retrieves the block number of the last persisted snapshot layer.

func ReadSnapshotRoot

func ReadSnapshotRoot(db ethdb.KeyValueReader) common.Hash

ReadSnapshotRoot retrieves the root of the block whose state is contained in the persisted snapshot.

func ReadSnapshotSyncStatus

func ReadSnapshotSyncStatus(db ethdb.KeyValueReader) []byte

ReadSnapshotSyncStatus retrieves the serialized sync status saved at shutdown.

func ReadStateAccountHistory

func ReadStateAccountHistory(db ethdb.AncientReaderOp, id uint64) []byte

ReadStateAccountHistory retrieves the state root corresponding to the specified state history. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateAccountIndex

func ReadStateAccountIndex(db ethdb.AncientReaderOp, id uint64) []byte

ReadStateAccountIndex retrieves the state root corresponding to the specified state history. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateHistory

func ReadStateHistory(db ethdb.AncientReaderOp, id uint64) ([]byte, []byte, []byte, []byte, []byte, error)

ReadStateHistory retrieves the state history from database with provided id. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateHistoryMeta

func ReadStateHistoryMeta(db ethdb.AncientReaderOp, id uint64) []byte

ReadStateHistoryMeta retrieves the metadata corresponding to the specified state history. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateHistoryMetaList

func ReadStateHistoryMetaList(db ethdb.AncientReaderOp, start uint64, count uint64) ([][]byte, error)

ReadStateHistoryMetaList retrieves a batch of meta objects with the specified start position and count. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateID

func ReadStateID(db ethdb.KeyValueReader, root common.Hash) *uint64

ReadStateID retrieves the state id with the provided state root.

func ReadStateStorageHistory

func ReadStateStorageHistory(db ethdb.AncientReaderOp, id uint64) []byte

ReadStateStorageHistory retrieves the state root corresponding to the specified state history. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStateStorageIndex

func ReadStateStorageIndex(db ethdb.AncientReaderOp, id uint64) []byte

ReadStateStorageIndex retrieves the state root corresponding to the specified state history. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func ReadStorageSnapshot

func ReadStorageSnapshot(db ethdb.KeyValueReader, accountHash, storageHash common.Hash) []byte

ReadStorageSnapshot retrieves the snapshot entry of an storage trie leaf.

func ReadStorageTrieNode

func ReadStorageTrieNode(db ethdb.KeyValueReader, accountHash common.Hash, path []byte) ([]byte, common.Hash)

ReadStorageTrieNode retrieves the storage trie node and the associated node hash with the specified node path.

func ReadTd

func ReadTd(db ethdb.Reader, hash common.Hash, number uint64) *big.Int

ReadTd retrieves a block's total difficulty corresponding to the hash.

func ReadTdRLP

func ReadTdRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue

ReadTdRLP retrieves a block's total difficulty corresponding to the hash in RLP encoding.

func ReadTransaction

func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64)

ReadTransaction retrieves a specific transaction from the database, along with its added positional metadata.

func ReadTransitionStatus

func ReadTransitionStatus(db ethdb.KeyValueReader) []byte

ReadTransitionStatus retrieves the eth2 transition status from the database

func ReadTrieJournal

func ReadTrieJournal(db ethdb.KeyValueReader) []byte

ReadTrieJournal retrieves the serialized in-memory trie nodes of layers saved at the last shutdown.

func ReadTrieNode

func ReadTrieNode(db ethdb.KeyValueReader, owner common.Hash, path []byte, hash common.Hash, scheme string) []byte

ReadTrieNode retrieves the trie node from database with the provided node info and associated node hash. hashScheme-based lookup requires the following:

  • hash

pathScheme-based lookup requires the following:

  • owner
  • path

func ReadTxIndexTail

func ReadTxIndexTail(db ethdb.KeyValueReader) *uint64

ReadTxIndexTail retrieves the number of oldest indexed block whose transaction indices has been indexed.

func ReadTxLookupEntry

func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64

ReadTxLookupEntry retrieves the positional metadata associated with a transaction hash to allow retrieving the transaction or receipt by hash.

func UnindexTransactions

func UnindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{})

UnindexTransactions removes txlookup indices of the specified block range. The from is included while to is excluded.

There is a passed channel, the whole procedure will be interrupted if any signal received.

func UpdateUncleanShutdownMarker

func UpdateUncleanShutdownMarker(db ethdb.KeyValueStore)

UpdateUncleanShutdownMarker updates the last marker's timestamp to now.

func WriteAccountSnapshot

func WriteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash, entry []byte)

WriteAccountSnapshot stores the snapshot entry of an account trie leaf.

func WriteAccountTrieNode

func WriteAccountTrieNode(db ethdb.KeyValueWriter, path []byte, node []byte)

WriteAccountTrieNode writes the provided account trie node into database.

func WriteAncientBlocks

func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts []types.Receipts, td *big.Int) (int64, error)

WriteAncientBlocks writes entire block data into ancient store and returns the total written size.

func WriteBadBlock

func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block)

WriteBadBlock serializes the bad block into the database. If the cumulated bad blocks exceeds the limitation, the oldest will be dropped.

func WriteBlock

func WriteBlock(db ethdb.KeyValueWriter, block *types.Block)

WriteBlock serializes a block into the database, header and body separately.

func WriteBloomBits

func WriteBloomBits(db ethdb.KeyValueWriter, bit uint, section uint64, head common.Hash, bits []byte)

WriteBloomBits stores the compressed bloom bits vector belonging to the given section and bit index.

func WriteBody

func WriteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64, body *types.Body)

WriteBody stores a block body into the database.

func WriteBodyRLP

func WriteBodyRLP(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rlp rlp.RawValue)

WriteBodyRLP stores an RLP encoded block body into the database.

func WriteCanonicalHash

func WriteCanonicalHash(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

WriteCanonicalHash stores the hash assigned to a canonical block number.

func WriteChainConfig

func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, cfg *params.ChainConfig)

WriteChainConfig writes the chain config settings to the database.

func WriteCode

func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte)

WriteCode writes the provided contract code database.

func WriteDatabaseVersion

func WriteDatabaseVersion(db ethdb.KeyValueWriter, version uint64)

WriteDatabaseVersion stores the version number of the database

func WriteFastTxLookupLimit

func WriteFastTxLookupLimit(db ethdb.KeyValueWriter, number uint64)

WriteFastTxLookupLimit stores the txlookup limit used in fast sync into database.

func WriteFinalizedBlockHash

func WriteFinalizedBlockHash(db ethdb.KeyValueWriter, hash common.Hash)

WriteFinalizedBlockHash stores the hash of the finalized block.

func WriteGenesisStateSpec

func WriteGenesisStateSpec(db ethdb.KeyValueWriter, blockhash common.Hash, data []byte)

WriteGenesisStateSpec writes the genesis state specification into the disk.

func WriteHeadBlockHash

func WriteHeadBlockHash(db ethdb.KeyValueWriter, hash common.Hash)

WriteHeadBlockHash stores the head block's hash.

func WriteHeadFastBlockHash

func WriteHeadFastBlockHash(db ethdb.KeyValueWriter, hash common.Hash)

WriteHeadFastBlockHash stores the hash of the current fast-sync head block.

func WriteHeadHeaderHash

func WriteHeadHeaderHash(db ethdb.KeyValueWriter, hash common.Hash)

WriteHeadHeaderHash stores the hash of the current canonical head header.

func WriteHeader

func WriteHeader(db ethdb.KeyValueWriter, header *types.Header)

WriteHeader stores a block header into the database and also stores the hash- to-number mapping.

func WriteHeaderNumber

func WriteHeaderNumber(db ethdb.KeyValueWriter, hash common.Hash, number uint64)

WriteHeaderNumber stores the hash->number mapping.

func WriteLastPivotNumber

func WriteLastPivotNumber(db ethdb.KeyValueWriter, pivot uint64)

WriteLastPivotNumber stores the number of the last pivot block.

func WriteLegacyTrieNode

func WriteLegacyTrieNode(db ethdb.KeyValueWriter, hash common.Hash, node []byte)

WriteLegacyTrieNode writes the provided legacy trie node to database.

func WritePersistentStateID

func WritePersistentStateID(db ethdb.KeyValueWriter, number uint64)

WritePersistentStateID stores the id of the persistent state into database.

func WritePreimages

func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte)

WritePreimages writes the provided set of preimages to the database.

func WriteReceipts

func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, receipts types.Receipts)

WriteReceipts stores all the transaction receipts belonging to a block.

func WriteSkeletonHeader

func WriteSkeletonHeader(db ethdb.KeyValueWriter, header *types.Header)

WriteSkeletonHeader stores a block header into the skeleton sync store.

func WriteSkeletonSyncStatus

func WriteSkeletonSyncStatus(db ethdb.KeyValueWriter, status []byte)

WriteSkeletonSyncStatus stores the serialized sync status to save at shutdown.

func WriteSnapshotDisabled

func WriteSnapshotDisabled(db ethdb.KeyValueWriter)

WriteSnapshotDisabled stores the snapshot pause flag.

func WriteSnapshotGenerator

func WriteSnapshotGenerator(db ethdb.KeyValueWriter, generator []byte)

WriteSnapshotGenerator stores the serialized snapshot generator to save at shutdown.

func WriteSnapshotJournal

func WriteSnapshotJournal(db ethdb.KeyValueWriter, journal []byte)

WriteSnapshotJournal stores the serialized in-memory diff layers to save at shutdown. The blob is expected to be max a few 10s of megabytes.

func WriteSnapshotRecoveryNumber

func WriteSnapshotRecoveryNumber(db ethdb.KeyValueWriter, number uint64)

WriteSnapshotRecoveryNumber stores the block number of the last persisted snapshot layer.

func WriteSnapshotRoot

func WriteSnapshotRoot(db ethdb.KeyValueWriter, root common.Hash)

WriteSnapshotRoot stores the root of the block whose state is contained in the persisted snapshot.

func WriteSnapshotSyncStatus

func WriteSnapshotSyncStatus(db ethdb.KeyValueWriter, status []byte)

WriteSnapshotSyncStatus stores the serialized sync status to save at shutdown.

func WriteStateHistory

func WriteStateHistory(db ethdb.AncientWriter, id uint64, meta []byte, accountIndex []byte, storageIndex []byte, accounts []byte, storages []byte)

WriteStateHistory writes the provided state history to database. Compute the position of state history in freezer by minus one since the id of first state history starts from one(zero for initial state).

func WriteStateID

func WriteStateID(db ethdb.KeyValueWriter, root common.Hash, id uint64)

WriteStateID writes the provided state lookup to database.

func WriteStorageSnapshot

func WriteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash common.Hash, entry []byte)

WriteStorageSnapshot stores the snapshot entry of an storage trie leaf.

func WriteStorageTrieNode

func WriteStorageTrieNode(db ethdb.KeyValueWriter, accountHash common.Hash, path []byte, node []byte)

WriteStorageTrieNode writes the provided storage trie node into database.

func WriteTd

func WriteTd(db ethdb.KeyValueWriter, hash common.Hash, number uint64, td *big.Int)

WriteTd stores the total difficulty of a block into the database.

func WriteTransitionStatus

func WriteTransitionStatus(db ethdb.KeyValueWriter, data []byte)

WriteTransitionStatus stores the eth2 transition status to the database

func WriteTrieJournal

func WriteTrieJournal(db ethdb.KeyValueWriter, journal []byte)

WriteTrieJournal stores the serialized in-memory trie nodes of layers to save at shutdown.

func WriteTrieNode

func WriteTrieNode(db ethdb.KeyValueWriter, owner common.Hash, path []byte, hash common.Hash, node []byte, scheme string)

WriteTrieNode writes the trie node into database with the provided node info and associated node hash. hashScheme-based lookup requires the following:

  • hash

pathScheme-based lookup requires the following:

  • owner
  • path

func WriteTxIndexTail

func WriteTxIndexTail(db ethdb.KeyValueWriter, number uint64)

WriteTxIndexTail stores the number of oldest indexed block into database.

func WriteTxLookupEntries

func WriteTxLookupEntries(db ethdb.KeyValueWriter, number uint64, hashes []common.Hash)

WriteTxLookupEntries is identical to WriteTxLookupEntry, but it works on a list of hashes

func WriteTxLookupEntriesByBlock

func WriteTxLookupEntriesByBlock(db ethdb.KeyValueWriter, block *types.Block)

WriteTxLookupEntriesByBlock stores a positional metadata for every transaction from a block, enabling hash based transaction and receipt lookups.

Types

type Freezer

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

Freezer is a memory mapped append-only database to store immutable ordered data into flat files:

  • The append-only nature ensures that disk writes are minimized.
  • The memory mapping ensures we can max out system memory for caching without reserving it for go-ethereum. This would also reduce the memory requirements of Geth, and thus also GC overhead.

func NewChainFreezer

func NewChainFreezer(datadir string, namespace string, readonly bool) (*Freezer, error)

NewChainFreezer is a small utility method around NewFreezer that sets the default parameters for the chain storage.

func NewFreezer

func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize uint32, tables map[string]bool) (*Freezer, error)

NewFreezer creates a freezer instance for maintaining immutable ordered data according to the given parameters.

The 'tables' argument defines the data tables. If the value of a map entry is true, snappy compression is disabled for the table.

func (*Freezer) Ancient

func (f *Freezer) Ancient(kind string, number uint64) ([]byte, error)

Ancient retrieves an ancient binary blob from the append-only immutable files.

func (*Freezer) AncientRange

func (f *Freezer) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error)

AncientRange retrieves multiple items in sequence, starting from the index 'start'. It will return

  • at most 'count' items,
  • if maxBytes is specified: at least 1 item (even if exceeding the maxByteSize), but will otherwise return as many items as fit into maxByteSize.
  • if maxBytes is not specified, 'count' items will be returned if they are present.

func (*Freezer) AncientSize

func (f *Freezer) AncientSize(kind string) (uint64, error)

AncientSize returns the ancient size of the specified category.

func (*Freezer) Ancients

func (f *Freezer) Ancients() (uint64, error)

Ancients returns the length of the frozen items.

func (*Freezer) Close

func (f *Freezer) Close() error

Close terminates the chain freezer, unmapping all the data files.

func (*Freezer) HasAncient

func (f *Freezer) HasAncient(kind string, number uint64) (bool, error)

HasAncient returns an indicator whether the specified ancient data exists in the freezer.

func (*Freezer) MigrateTable

func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error

MigrateTable processes the entries in a given table in sequence converting them to a new format if they're of an old format.

func (*Freezer) ModifyAncients

func (f *Freezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (writeSize int64, err error)

ModifyAncients runs the given write operation.

func (*Freezer) ReadAncients

func (f *Freezer) ReadAncients(fn func(ethdb.AncientReaderOp) error) (err error)

ReadAncients runs the given read operation while ensuring that no writes take place on the underlying freezer.

func (*Freezer) Sync

func (f *Freezer) Sync() error

Sync flushes all data tables to disk.

func (*Freezer) Tail

func (f *Freezer) Tail() (uint64, error)

Tail returns the number of first stored item in the freezer.

func (*Freezer) TruncateHead

func (f *Freezer) TruncateHead(items uint64) (uint64, error)

TruncateHead discards any recent data above the provided threshold number. It returns the previous head number.

func (*Freezer) TruncateTail

func (f *Freezer) TruncateTail(tail uint64) (uint64, error)

TruncateTail discards any recent data below the provided threshold number.

type KeyLengthIterator

type KeyLengthIterator struct {
	ethdb.Iterator
	// contains filtered or unexported fields
}

KeyLengthIterator is a wrapper for a database iterator that ensures only key-value pairs with a specific key length will be returned.

func (*KeyLengthIterator) Next

func (it *KeyLengthIterator) Next() bool

type LegacyTxLookupEntry

type LegacyTxLookupEntry struct {
	BlockHash  common.Hash
	BlockIndex uint64
	Index      uint64
}

LegacyTxLookupEntry is the legacy TxLookupEntry definition with some unnecessary fields.

type NumberHash

type NumberHash struct {
	Number uint64
	Hash   common.Hash
}

func ReadAllHashesInRange

func ReadAllHashesInRange(db ethdb.Iteratee, first, last uint64) []*NumberHash

ReadAllHashesInRange retrieves all the hashes assigned to blocks at certain heights, both canonical and reorged forks included. This method considers both limits to be _inclusive_.

type OpenOptions

type OpenOptions struct {
	Type              string // "leveldb" | "pebble"
	Directory         string // the datadir
	AncientsDirectory string // the ancients-dir
	Namespace         string // the namespace for database relevant metrics
	Cache             int    // the capacity(in megabytes) of the data caching
	Handles           int    // number of files to be open simultaneously
	ReadOnly          bool
}

OpenOptions contains the options to apply when opening a database. OBS: If AncientsDirectory is empty, it indicates that no freezer is to be used.

type ResettableFreezer

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

ResettableFreezer is a wrapper of the freezer which makes the freezer resettable.

func NewResettableFreezer

func NewResettableFreezer(datadir string, namespace string, readonly bool, maxTableSize uint32, tables map[string]bool) (*ResettableFreezer, error)

NewResettableFreezer creates a resettable freezer, note freezer is only resettable if the passed file directory is exclusively occupied by the freezer. And also the user-configurable ancient root directory is **not** supported for reset since it might be a mount and rename will cause a copy of hundreds of gigabyte into local directory. It needs some other file based solutions.

The reset function will delete directory atomically and re-create the freezer from scratch.

func NewStateHistoryFreezer added in v1.13.7

func NewStateHistoryFreezer(ancientDir string, readOnly bool) (*ResettableFreezer, error)

NewStateHistoryFreezer initializes the freezer for state history.

func (*ResettableFreezer) Ancient

func (f *ResettableFreezer) Ancient(kind string, number uint64) ([]byte, error)

Ancient retrieves an ancient binary blob from the append-only immutable files.

func (*ResettableFreezer) AncientRange

func (f *ResettableFreezer) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error)

AncientRange retrieves multiple items in sequence, starting from the index 'start'. It will return

  • at most 'max' items,
  • at least 1 item (even if exceeding the maxByteSize), but will otherwise return as many items as fit into maxByteSize

func (*ResettableFreezer) AncientSize

func (f *ResettableFreezer) AncientSize(kind string) (uint64, error)

AncientSize returns the ancient size of the specified category.

func (*ResettableFreezer) Ancients

func (f *ResettableFreezer) Ancients() (uint64, error)

Ancients returns the length of the frozen items.

func (*ResettableFreezer) Close

func (f *ResettableFreezer) Close() error

Close terminates the chain freezer, unmapping all the data files.

func (*ResettableFreezer) HasAncient

func (f *ResettableFreezer) HasAncient(kind string, number uint64) (bool, error)

HasAncient returns an indicator whether the specified ancient data exists in the freezer

func (*ResettableFreezer) MigrateTable

func (f *ResettableFreezer) MigrateTable(kind string, convert convertLegacyFn) error

MigrateTable processes the entries in a given table in sequence converting them to a new format if they're of an old format.

func (*ResettableFreezer) ModifyAncients

func (f *ResettableFreezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (writeSize int64, err error)

ModifyAncients runs the given write operation.

func (*ResettableFreezer) ReadAncients

func (f *ResettableFreezer) ReadAncients(fn func(ethdb.AncientReaderOp) error) (err error)

ReadAncients runs the given read operation while ensuring that no writes take place on the underlying freezer.

func (*ResettableFreezer) Reset

func (f *ResettableFreezer) Reset() error

Reset deletes the file directory exclusively occupied by the freezer and recreate the freezer from scratch. The atomicity of directory deletion is guaranteed by the rename operation, the leftover directory will be cleaned up in next startup in case crash happens after rename.

func (*ResettableFreezer) Sync

func (f *ResettableFreezer) Sync() error

Sync flushes all data tables to disk.

func (*ResettableFreezer) Tail

func (f *ResettableFreezer) Tail() (uint64, error)

Tail returns the number of first stored item in the freezer.

func (*ResettableFreezer) TruncateHead

func (f *ResettableFreezer) TruncateHead(items uint64) (uint64, error)

TruncateHead discards any recent data above the provided threshold number. It returns the previous head number.

func (*ResettableFreezer) TruncateTail

func (f *ResettableFreezer) TruncateTail(tail uint64) (uint64, error)

TruncateTail discards any recent data below the provided threshold number. It returns the previous value

Jump to

Keyboard shortcuts

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