rawdb

package
v0.0.0-...-1f8a15b Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SnapshotsHistoryKey = []byte("snapshots_history")
View Source
var SnapshotsKey = []byte("snapshots")

Functions

func AppendCanonicalTxNums

func AppendCanonicalTxNums(tx kv.RwTx, from uint64) (err error)

func AppendReceipts

func AppendReceipts(tx kv.StatelessWriteTx, blockNumber uint64, receipts types.Receipts) error

AppendReceipts stores all the transaction receipts belonging to a block.

func CanonicalTransactions

func CanonicalTransactions(db kv.Getter, baseTxId uint64, amount uint32) ([]types.Transaction, error)

func DeleteBody

func DeleteBody(db kv.Deleter, hash common.Hash, number uint64)

DeleteBody removes all block body data associated with a hash.

func DeleteChainConfig

func DeleteChainConfig(db kv.Deleter, hash libcommon.Hash) error

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

func DeleteHeader

func DeleteHeader(db kv.Deleter, hash common.Hash, number uint64)

DeleteHeader - dangerous, use PruneBlocks/TruncateBlocks methods

func DeleteNewerEpochs

func DeleteNewerEpochs(tx kv.RwTx, number uint64) error

func DeleteTxLookupEntry

func DeleteTxLookupEntry(db kv.Deleter, hash libcommon.Hash) error

DeleteTxLookupEntry removes all transaction data associated with a hash.

func FindEpochBeforeOrEqualNumber

func FindEpochBeforeOrEqualNumber(tx kv.Tx, n uint64) (blockNum uint64, blockHash common.Hash, transitionProof []byte, err error)

func GetStateVersion

func GetStateVersion(tx kv.Tx) (uint64, error)

func HasBlock

func HasBlock(db kv.Getter, hash common.Hash, number uint64) bool

HasBlock - is more efficient than ReadBlock because doesn't read transactions. It's is not equivalent of HasHeader because headers and bodies written by different stages

func HasBorReceipts

func HasBorReceipts(db kv.Has, number uint64) bool

HasBorReceipt verifies the existence of all block receipt belonging to a block.

func HasSenders

func HasSenders(db kv.Getter, hash common.Hash, number uint64) (bool, error)

func IncrementStateVersion

func IncrementStateVersion(tx kv.RwTx) (uint64, error)

func IsCanonicalHash

func IsCanonicalHash(db kv.Getter, hash common.Hash, number uint64) (bool, error)

func IsCanonicalHashDeprecated

func IsCanonicalHashDeprecated(db kv.Getter, hash common.Hash) (bool, *uint64, error)

IsCanonicalHashDeprecated determines whether a header with the given hash is on the canonical chain.

func IsPosBlock

func IsPosBlock(db kv.Getter, blockHash common.Hash) (trans bool, err error)

IsPosBlock returns true if the block number comes after POS transition or is the last POW block

func NonCanonicalTransactions

func NonCanonicalTransactions(db kv.Getter, baseTxId uint64, amount uint32) ([]types.Transaction, error)

func PruneBlocks

func PruneBlocks(tx kv.RwTx, blockTo uint64, blocksDeleteLimit int) error

PruneBlocks - delete [1, to) old blocks after moving it to snapshots. keeps genesis in db: [1, to) doesn't change sequences of kv.EthTx and kv.NonCanonicalTxs doesn't delete Receipts, Senders, Canonical markers, TotalDifficulty

func PruneBorBlocks

func PruneBorBlocks(tx kv.RwTx, blockTo uint64, blocksDeleteLimit int) error

PruneBorBlocks - delete [1, to) old blocks after moving it to snapshots. keeps genesis in db: [1, to) doesn't change sequences of kv.EthTx and kv.NonCanonicalTxs doesn't delete Receipts, Senders, Canonical markers, TotalDifficulty

func PruneTable

func PruneTable(tx kv.RwTx, table string, pruneTo uint64, ctx context.Context, limit int) error

PruneTable has `limit` parameter to avoid too large data deletes per one sync cycle - better delete by small portions to reduce db.FreeList size

func PruneTableDupSort

func PruneTableDupSort(tx kv.RwTx, table string, logPrefix string, pruneTo uint64, logEvery *time.Ticker, ctx context.Context) error

func RawTransactionsRange

func RawTransactionsRange(db kv.Getter, from, to uint64) (res [][]byte, err error)

func ReadAccount

func ReadAccount(db kv.Getter, addr libcommon.Address, acc *accounts.Account) (bool, error)

func ReadBadHeaderNumber

func ReadBadHeaderNumber(db kv.Getter, hash common.Hash) (*uint64, error)

func ReadBlock

func ReadBlock(tx kv.Getter, 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 ReadBlockWithSenders

func ReadBlockWithSenders(db kv.Getter, hash common.Hash, number uint64) (*types.Block, []common.Address, error)

func ReadBody

func ReadBody(db kv.Getter, hash common.Hash, number uint64) (*types.Body, uint64, uint32)

func ReadBodyByNumber

func ReadBodyByNumber(db kv.Tx, number uint64) (*types.Body, uint64, uint32, error)

ReadBodyByNumber - returns canonical block body

func ReadBodyForStorageByKey

func ReadBodyForStorageByKey(db kv.Getter, k []byte) (*types.BodyForStorage, error)

func ReadBodyRLP

func ReadBodyRLP(db kv.Tx, hash common.Hash, number uint64) rlp.RawValue

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

func ReadBodyWithTransactions

func ReadBodyWithTransactions(db kv.Getter, hash common.Hash, number uint64) (*types.Body, error)

func ReadBorReceipt

func ReadBorReceipt(db kv.Tx, blockHash libcommon.Hash, blockNumber uint64, receipts types.Receipts) (*types.Receipt, error)

func ReadBorTransaction

func ReadBorTransaction(db kv.Tx, borTxHash libcommon.Hash) (types.Transaction, error)

ReadBorTransaction returns a specific bor (fake) transaction by txn hash, along with its added positional metadata.

func ReadBorTransactionForBlock

func ReadBorTransactionForBlock(db kv.Tx, blockNum uint64) types.Transaction

ReadBorTransactionForBlock retrieves a specific bor (fake) transaction associated with a block, along with its added positional metadata.

func ReadBorTxLookupEntry

func ReadBorTxLookupEntry(db kv.Getter, borTxHash libcommon.Hash) (*uint64, error)

func ReadCanonicalHash

func ReadCanonicalHash(db kv.Getter, number uint64) (common.Hash, error)

ReadCanonicalHash retrieves the hash assigned to a canonical block number.

func ReadChainConfig

func ReadChainConfig(db kv.Getter, hash libcommon.Hash) (*chain.Config, error)

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

func ReadCurrentBlockNumber

func ReadCurrentBlockNumber(db kv.Getter) *uint64

func ReadCurrentHeader

func ReadCurrentHeader(db kv.Getter) *types.Header

func ReadDBSchemaVersion

func ReadDBSchemaVersion(tx kv.Tx) (major, minor, patch uint32, ok bool, err error)

func ReadEpoch

func ReadEpoch(tx kv.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err error)

func ReadForkchoiceFinalized

func ReadForkchoiceFinalized(db kv.Getter) common.Hash

ReadForkchoiceFinalized retrieves finalizedBlockHash from the last Engine API forkChoiceUpdated.

func ReadForkchoiceHead

func ReadForkchoiceHead(db kv.Getter) common.Hash

ReadForkchoiceHead retrieves headBlockHash from the last Engine API forkChoiceUpdated.

func ReadForkchoiceSafe

func ReadForkchoiceSafe(db kv.Getter) common.Hash

ReadForkchoiceSafe retrieves safeBlockHash from the last Engine API forkChoiceUpdated.

func ReadHeadBlockHash

func ReadHeadBlockHash(db kv.Getter) common.Hash

ReadHeadBlockHash retrieves the hash of the current canonical head block.

func ReadHeadHeaderHash

func ReadHeadHeaderHash(db kv.Getter) common.Hash

ReadHeadHeaderHash retrieves the hash of the current canonical head header.

func ReadHeader

func ReadHeader(db kv.Getter, hash common.Hash, number uint64) *types.Header

ReadHeader retrieves the block header corresponding to the hash.

func ReadHeaderByHash

func ReadHeaderByHash(db kv.Getter, hash common.Hash) (*types.Header, error)

func ReadHeaderByNumber

func ReadHeaderByNumber(db kv.Getter, number uint64) *types.Header

func ReadHeaderNumber

func ReadHeaderNumber(db kv.Getter, hash common.Hash) *uint64

ReadHeaderNumber returns the header number assigned to a hash.

func ReadHeaderRLP

func ReadHeaderRLP(db kv.Getter, hash common.Hash, number uint64) rlp.RawValue

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

func ReadHeadersByNumber

func ReadHeadersByNumber(db kv.Tx, number uint64) ([]*types.Header, error)

func ReadPendingEpoch

func ReadPendingEpoch(tx kv.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err error)

func ReadRawBorReceipt

func ReadRawBorReceipt(db kv.Tx, number uint64) (*types.Receipt, bool, error)

func ReadRawReceipts

func ReadRawReceipts(db kv.Tx, blockNum 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 ReadReceipts

func ReadReceipts(db kv.Tx, block *types.Block, senders []common.Address) 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 ReadSenders

func ReadSenders(db kv.Getter, hash common.Hash, number uint64) ([]common.Address, error)

func ReadSnapshots

func ReadSnapshots(tx kv.Tx) ([]string, []string, error)

func ReadStorageBody

func ReadStorageBody(db kv.Getter, hash common.Hash, number uint64) (types.BodyForStorage, error)

func ReadStorageBodyRLP

func ReadStorageBodyRLP(db kv.Getter, hash common.Hash, number uint64) rlp.RawValue

func ReadTd

func ReadTd(db kv.Getter, hash common.Hash, number uint64) (*big.Int, error)

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

func ReadTdByHash

func ReadTdByHash(db kv.Getter, hash common.Hash) (*big.Int, error)

func ReadTotalBurnt

func ReadTotalBurnt(db kv.Getter, number uint64) (*big.Int, error)

func ReadTotalIssued

func ReadTotalIssued(db kv.Getter, number uint64) (*big.Int, error)

func ReadTxLookupEntry

func ReadTxLookupEntry(db kv.Getter, txnHash libcommon.Hash) (*uint64, error)

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

func ReadVerkleNode

func ReadVerkleNode(tx kv.RwTx, root common.Hash) (verkle.VerkleNode, error)

func ReadVerkleRoot

func ReadVerkleRoot(tx kv.Tx, blockNum uint64) (common.Hash, error)

func ReceiptsAvailableFrom

func ReceiptsAvailableFrom(tx kv.Tx) (uint64, error)

func ResetSequence

func ResetSequence(tx kv.RwTx, bucket string, newValue uint64) error

ResetSequence - allow set arbitrary value to sequence (for example to decrement it to exact value)

func Transitioned

func Transitioned(db kv.Getter, blockNum uint64, terminalTotalDifficulty *big.Int) (trans bool, err error)

Transitioned returns true if the block number comes after POS transition or is the last POW block

func TruncateBlocks

func TruncateBlocks(ctx context.Context, tx kv.RwTx, blockFrom uint64) error

TruncateBlocks - delete block >= blockFrom does decrement sequences of kv.EthTx and kv.NonCanonicalTxs doesn't delete Receipts, Senders, Canonical markers, TotalDifficulty

func TruncateBorReceipts

func TruncateBorReceipts(db kv.RwTx, number uint64) error

TruncateBorReceipts removes all bor receipt for given block number or newer

func TruncateCanonicalChain

func TruncateCanonicalChain(ctx context.Context, db kv.RwTx, from uint64) error

func TruncateCanonicalHash

func TruncateCanonicalHash(tx kv.RwTx, blockFrom uint64, markChainAsBad bool) error

TruncateCanonicalHash removes all the number to hash canonical mapping from block number N Mark chain as bad feature:

  • BadBlock must be not available by hash
  • but available by hash+num - if read num from kv.BadHeaderNumber table
  • prune blocks: must delete Canonical/NonCanonical/BadBlocks also

func TruncateReceipts

func TruncateReceipts(db kv.RwTx, number uint64) error

TruncateReceipts removes all receipt for given block number or newer

func TruncateTd

func TruncateTd(tx kv.RwTx, blockFrom uint64) error

TruncateTd removes all block total difficulty from block number N

func TxnByIdxInBlock

func TxnByIdxInBlock(db kv.Getter, blockHash common.Hash, blockNum uint64, txIdxInBlock int) (types.Transaction, error)

func WriteBlock

func WriteBlock(db kv.RwTx, block *types.Block) error

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

func WriteBody

func WriteBody(db kv.RwTx, hash common.Hash, number uint64, body *types.Body) (err error)

func WriteBodyForStorage

func WriteBodyForStorage(db kv.Putter, hash common.Hash, number uint64, body *types.BodyForStorage) error

WriteBodyForStorage stores an RLP encoded block body into the database.

func WriteBorReceipt

func WriteBorReceipt(tx kv.RwTx, hash libcommon.Hash, number uint64, borReceipt *types.Receipt) error

WriteBorReceipt stores all the bor receipt belonging to a block (storing the state sync recipt and log).

func WriteCanonicalHash

func WriteCanonicalHash(db kv.Putter, hash common.Hash, number uint64) error

WriteCanonicalHash stores the hash assigned to a canonical block number.

func WriteChainConfig

func WriteChainConfig(db kv.Putter, hash libcommon.Hash, cfg *chain.Config) error

WriteChainConfig writes the chain config settings to the database.

func WriteDBSchemaVersion

func WriteDBSchemaVersion(tx kv.RwTx) error

func WriteEpoch

func WriteEpoch(tx kv.RwTx, blockNum uint64, blockHash common.Hash, transitionProof []byte) (err error)

func WriteForkchoiceFinalized

func WriteForkchoiceFinalized(db kv.Putter, hash common.Hash)

WriteForkchoiceFinalized stores finalizedBlockHash from the last Engine API forkChoiceUpdated.

func WriteForkchoiceHead

func WriteForkchoiceHead(db kv.Putter, hash common.Hash)

WriteForkchoiceHead stores headBlockHash from the last Engine API forkChoiceUpdated.

func WriteForkchoiceSafe

func WriteForkchoiceSafe(db kv.Putter, hash common.Hash)

WriteForkchoiceSafe stores safeBlockHash from the last Engine API forkChoiceUpdated.

func WriteHeadBlockHash

func WriteHeadBlockHash(db kv.Putter, hash common.Hash)

WriteHeadBlockHash stores the head block's hash.

func WriteHeadHeaderHash

func WriteHeadHeaderHash(db kv.Putter, hash common.Hash) error

WriteHeadHeaderHash stores the hash of the current canonical head header.

func WriteHeader

func WriteHeader(db kv.RwTx, header *types.Header) error

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

func WriteHeaderNumber

func WriteHeaderNumber(db kv.Putter, hash common.Hash, number uint64) error

WriteHeaderNumber stores the hash->number mapping.

func WriteHeaderRaw

func WriteHeaderRaw(db kv.StatelessRwTx, number uint64, hash common.Hash, headerRlp []byte, skipIndexing bool) error

func WritePendingEpoch

func WritePendingEpoch(tx kv.RwTx, blockNum uint64, blockHash common.Hash, transitionProof []byte) (err error)

func WriteRawBody

func WriteRawBody(db kv.RwTx, hash common.Hash, number uint64, body *types.RawBody) (ok bool, err error)

func WriteRawBodyIfNotExists

func WriteRawBodyIfNotExists(db kv.RwTx, hash common.Hash, number uint64, body *types.RawBody) (ok bool, err error)

func WriteRawTransactions

func WriteRawTransactions(tx kv.RwTx, txs [][]byte, baseTxId uint64) error

func WriteReceipts

func WriteReceipts(tx kv.Putter, number uint64, receipts types.Receipts) error

WriteReceipts stores all the transaction receipts belonging to a block.

func WriteSenders

func WriteSenders(db kv.Putter, hash common.Hash, number uint64, senders []common.Address) error

func WriteSnapshots

func WriteSnapshots(tx kv.RwTx, list, histList []string) error

func WriteTd

func WriteTd(db kv.Putter, hash common.Hash, number uint64, td *big.Int) error

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

func WriteTotalBurnt

func WriteTotalBurnt(db kv.Putter, number uint64, totalBurnt *big.Int) error

func WriteTotalIssued

func WriteTotalIssued(db kv.Putter, number uint64, totalIssued *big.Int) error

func WriteTransactions

func WriteTransactions(db kv.RwTx, txs []types.Transaction, baseTxId uint64) error

func WriteTxLookupEntries

func WriteTxLookupEntries(db kv.Putter, block *types.Block)

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

func WriteVerkleNode

func WriteVerkleNode(tx kv.RwTx, node verkle.VerkleNode) error

func WriteVerkleRoot

func WriteVerkleRoot(tx kv.RwTx, blockNum uint64, root common.Hash) error

Types

type TxLookupEntry

type TxLookupEntry struct {
	BlockHash  libcommon.Hash
	BlockIndex uint64
	Index      uint64
}

TxLookupEntry is a positional metadata to help looking up the data content of a transaction or receipt given only its hash.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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