rawdb

package
v3.0.0-alpha5.0...-c974331 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllSegmentsDownloadComplete

func AllSegmentsDownloadComplete(tx kv.Getter) (allSegmentsDownloadComplete bool, err error)

func AllSegmentsDownloadCompleteFromDB

func AllSegmentsDownloadCompleteFromDB(db kv.RoDB) (allSegmentsDownloadComplete bool, err error)

func AppendCanonicalTxNums

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

func CanonicalTransactions

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

func DeleteBody

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

DeleteBody removes all block body data associated with a hash.

func DeleteHeader

func DeleteHeader(db kv.Putter, 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.Putter, 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.Getter, number uint64) bool

HasBorReceipts 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 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 PruneBlocks

func PruneBlocks(tx kv.RwTx, blockTo uint64, blocksDeleteLimit int) (deleted int, err 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 doesn't delete Receipts, Senders, Canonical markers, TotalDifficulty Returns false if there is nothing to prune

func PruneTable

func PruneTable(tx kv.RwTx, table string, pruneTo uint64, ctx context.Context, limit int, timeout time.Duration) 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 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 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 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

ReadCurrentHeader reads the current canonical head header. It is updated in stage_headers, updateForkChoice. See: ReadHeadHeaderHash, ReadCurrentHeaderHavingBody

func ReadCurrentHeaderHavingBody

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

ReadCurrentHeaderHavingBody reads the current canonical head header for which its block body is known. It is updated in stage_finish. See: ReadHeadBlockHash, ReadCurrentHeader

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 ReadFirstNonGenesisHeaderNumber

func ReadFirstNonGenesisHeaderNumber(tx kv.Tx) (uint64, bool, 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 ReadGenesis

func ReadGenesis(db kv.Getter) (*types.Genesis, error)

func ReadHeadBlockHash

func ReadHeadBlockHash(db kv.Getter) common.Hash

ReadHeadBlockHash retrieves the hash of the current canonical head header for which its block body is known. It is updated in stage_finish. See: kv.HeadBlockKey

func ReadHeadHeaderHash

func ReadHeadHeaderHash(db kv.Getter) common.Hash

ReadHeadHeaderHash retrieves the hash of the current canonical head header. It is updated in stage_headers, updateForkChoice. See: ReadHeadBlockHash

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) (res []*types.Header, err error)

func ReadLastNewBlockSeen

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

func ReadPendingEpoch

func ReadPendingEpoch(tx kv.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err 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 ReadStorageBodyRLP deprecated

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

Deprecated: use readBodyForStorage

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 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 doesn't delete Receipts, Senders, Canonical markers, TotalDifficulty

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 - used for Unwind

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

func WriteGenesisIfNotExist(db kv.RwTx, g *types.Genesis) error

func WriteHeadBlockHash

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

WriteHeadBlockHash stores the hash of the current canonical head header for which its block body is known. It is updated in stage_finish. See: kv.HeadBlockKey

func WriteHeadHeaderHash

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

WriteHeadHeaderHash stores the hash of the current canonical head header. It is updated in stage_headers, updateForkChoice. See: WriteHeadBlockHash

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 WriteLastNewBlockSeen

func WriteLastNewBlockSeen(tx kv.RwTx, blockNum uint64) 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(rwTx kv.RwTx, txs [][]byte, txnID 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 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 WriteTransactions

func WriteTransactions(rwTx kv.RwTx, txs []types.Transaction, txnID uint64) error

Write transactions to the database and use txnID as first identifier

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