rawdb

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendReceipts

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

AppendReceipts stores all the transaction receipts belonging to a block.

func CanonicalBlockByNumberWithSenders

func CanonicalBlockByNumberWithSenders(db kv.Tx, number uint64) (*block.Block, []types.Address, error)

func CanonicalTransactions

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

func CanonicalTxnByID

func CanonicalTxnByID(db kv.Getter, id uint64) (*transaction.Transaction, error)

func DeleteDeposit

func DeleteDeposit(db kv.Deleter, addr types.Address) error

DeleteDeposit removes Deposit data associated with an address.

func DeleteHeaderNumber

func DeleteHeaderNumber(db kv.Deleter, hash types.Hash)

DeleteHeaderNumber removes hash->number mapping.

func DeleteTxLookupEntry

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

DeleteTxLookupEntry removes all transaction data associated with a hash.

func DepositNum

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

func FirstKey

func FirstKey(tx kv.Tx, table string) ([]byte, error)

FirstKey - candidate on move to kv.Tx interface

func GetAccount

func GetAccount(db kv.Tx, addr types.Address, acc *account.StateAccount) (bool, error)

func GetAccountReward

func GetAccountReward(db kv.Getter, account types.Address) (*uint256.Int, error)

GetAccountReward

func GetDeposit

func GetDeposit(db kv.Getter, addr types.Address) (types.PublicKey, *uint256.Int, error)

GetDeposit

func GetPoaSnapshot

func GetPoaSnapshot(db kv.Getter, hash types.Hash) ([]byte, error)

func HasBlock

func HasBlock(db kv.Getter, hash types.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 HasHeader

func HasHeader(db kv.Has, hash types.Hash, number uint64) bool

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

func HasReceipts

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

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

func IsCanonicalHash

func IsCanonicalHash(db kv.Getter, hash types.Hash) (bool, error)

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

func IsDeposit

func IsDeposit(db kv.Getter, addr types.Address) bool

IsDeposit is deposit account

func LastKey

func LastKey(tx kv.Tx, table string) ([]byte, error)

LastKey - candidate on move to kv.Tx interface

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 PutAccountReward

func PutAccountReward(db kv.Putter, account types.Address, val *uint256.Int) error

PutAccountReward

func PutDeposit

func PutDeposit(db kv.Putter, addr types.Address, pub types.PublicKey, amount uint256.Int) error

func RawTransactionsRange

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

func ReadBlock

func ReadBlock(tx kv.Getter, hash types.Hash, number uint64) *block.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 ReadBlockByHash

func ReadBlockByHash(db kv.Tx, hash types.Hash) (*block.Block, error)

func ReadBlockByNumber

func ReadBlockByNumber(db kv.Getter, number uint64) (*block.Block, error)

func ReadBlockWithSenders

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

func ReadBody

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

func ReadBodyByNumber

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

ReadBodyByNumber - returns canonical block body

func ReadBodyForStorageByKey

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

func ReadBodyRAW

func ReadBodyRAW(db kv.Tx, hash types.Hash, number uint64) []byte

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

func ReadBodyWithTransactions

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

func ReadCanonicalBodyWithTransactions

func ReadCanonicalBodyWithTransactions(db kv.Getter, hash types.Hash, number uint64) *block.Body

func ReadCanonicalHash

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

ReadCanonicalHash retrieves the hash assigned to a canonical block number.

func ReadChainConfig

func ReadChainConfig(db kv.Getter, hash types.Hash) (*params.ChainConfig, error)

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

func ReadCurrentBlock

func ReadCurrentBlock(db kv.Tx) *block.Block

func ReadCurrentBlockNumber

func ReadCurrentBlockNumber(db kv.Getter) *uint64

func ReadCurrentHeader

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

func ReadHeadBlockHash

func ReadHeadBlockHash(db kv.Getter) types.Hash

ReadHeadBlockHash retrieves the hash of the current canonical head block.

func ReadHeadHeaderHash

func ReadHeadHeaderHash(db kv.Getter) types.Hash

ReadHeadHeaderHash retrieves the hash of the current canonical head header.

func ReadHeader

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

ReadHeader retrieves the block header corresponding to the hash.

func ReadHeaderByHash

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

func ReadHeaderByNumber

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

func ReadHeaderNumber

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

ReadHeaderNumber returns the header number assigned to a hash.

func ReadHeaderRAW

func ReadHeaderRAW(db kv.Getter, hash types.Hash, number uint64) []byte

ReadHeaderRAW retrieves a block header in its raw database encoding.

func ReadHeadersByNumber

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

func ReadRawReceipts

func ReadRawReceipts(db kv.Tx, blockNum uint64) block.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 kv.Tx, txHash types.Hash) (*block.Receipt, types.Hash, uint64, uint64, error)

func ReadReceipts

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

func ReadReceiptsByHash(db kv.Tx, hash types.Hash) (block.Receipts, error)

func ReadRewards

func ReadRewards(db kv.Getter, hash types.Hash, number uint64) ([]*block.Reward, error)

func ReadSenders

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

func ReadStorageBody

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

func ReadStorageBodyRAW

func ReadStorageBodyRAW(db kv.Getter, hash types.Hash, number uint64) []byte

func ReadTd

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

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

func ReadTdByHash

func ReadTdByHash(db kv.Getter, hash types.Hash) (*uint256.Int, error)

func ReadTransaction

func ReadTransaction(db kv.Tx, hash types.Hash, blockNumber uint64) (*transaction.Transaction, types.Hash, uint64, uint64, error)

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

func ReadTransactionByHash

func ReadTransactionByHash(db kv.Tx, hash types.Hash) (*transaction.Transaction, types.Hash, uint64, uint64, error)

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

func ReadTxLookupEntry

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

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

func ReadVerifies

func ReadVerifies(db kv.Getter, hash types.Hash, number uint64) ([]*block.Verify, error)

func ReceiptsAvailableFrom

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

func SecondKey

func SecondKey(tx kv.Tx, table string) ([]byte, error)

SecondKey - useful if table always has zero-key (for example genesis block)

func StorePoaSnapshot

func StorePoaSnapshot(db kv.Putter, hash types.Hash, data []byte) error

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 TruncateCanonicalHash

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

TruncateCanonicalHash removes all the number to hash canonical mapping from block number N

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 WriteBlock

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

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

func WriteBody

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

func WriteBodyForStorage

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

WriteBodyForStorage stores an encoded block body into the database.

func WriteCanonicalHash

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

WriteCanonicalHash stores the hash assigned to a canonical block number.

func WriteChainConfig

func WriteChainConfig(db kv.RwTx, hash types.Hash, cfg *params.ChainConfig) error

WriteChainConfig writes the chain config settings to the database.

func WriteHeadBlockHash

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

WriteHeadBlockHash stores the head block's hash.

func WriteHeadHeaderHash

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

WriteHeadHeaderHash stores the hash of the current canonical head header.

func WriteHeader

func WriteHeader(db kv.Putter, header *block.Header)

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

func WriteHeaderNumber

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

WriteHeaderNumber stores the hash->number mapping.

func WriteRawBody

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

func WriteRawBodyIfNotExists

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

func WriteRawTransactions

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

func WriteReceipts

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

WriteReceipts stores all the transaction receipts belonging to a block.

func WriteRewards

func WriteRewards(db kv.Putter, hash types.Hash, number uint64, rewards []*block.Reward) error

func WriteTd

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

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

func WriteTransactions

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

func WriteTxLookupEntries

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

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

func WriteVerifies

func WriteVerifies(db kv.Putter, hash types.Hash, number uint64, verifies []*block.Verify) error

Types

type TxLookupEntry

type TxLookupEntry struct {
	BlockHash  types.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.

Jump to

Keyboard shortcuts

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