store

package
v0.0.0-...-f58d8a1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockchainStore

type BlockchainStore interface {
	// GetBlockHash retrieves the block hash for the specified canonical block height.
	GetBlockHash(height uint64) (common.Hash, error)

	// PutBlockHash writes the height-to-blockHash entry in the canonical chain.
	PutBlockHash(height uint64, hash common.Hash) error

	// DeleteBlockHash deletes the block hash of the specified canonical block height.
	DeleteBlockHash(height uint64) (bool, error)

	// GetHeadBlockHash retrieves the HEAD block hash.
	GetHeadBlockHash() (common.Hash, error)

	// PutHeadBlockHash writes the HEAD block hash into the store.
	PutHeadBlockHash(hash common.Hash) error

	// GetBlockHeader retrieves the block header for the specified block hash.
	GetBlockHeader(hash common.Hash) (*types.BlockHeader, error)

	// PutBlockHeader serializes a block header with the specified total difficulty (td) into the store.
	// The input parameter isHead indicates if the header is a HEAD block header.
	PutBlockHeader(hash common.Hash, header *types.BlockHeader, td *big.Int, isHead bool) error

	// DeleteBlockHeader deletes the block header in light chains
	DeleteBlockHeader(hash common.Hash) error

	// GetBlockTotalDifficulty retrieves a block's total difficulty for the specified block hash.
	GetBlockTotalDifficulty(hash common.Hash) (*big.Int, error)

	// PutBlock serializes the given block with the given total difficulty (td) into the store.
	// The input parameter isHead indicates if the given block is a HEAD block.
	PutBlock(block *types.Block, td *big.Int, isHead bool) error

	// GetBlock retrieves the block for the specified block hash.
	GetBlock(hash common.Hash) (*types.Block, error)

	// HasBlock checks if the block with the specified hash exists.
	HasBlock(hash common.Hash) (bool, error)

	// DeleteBlock deletes the block of the specified block hash.
	DeleteBlock(hash common.Hash) error

	// GetBlockByHeight retrieves the block for the specified block height.
	GetBlockByHeight(height uint64) (*types.Block, error)

	// RecoverHeightToBlockMap recover the height-to-block mapping
	RecoverHeightToBlockMap(block *types.Block) error

	// PutReceipts serializes given receipts for the specified block hash.
	PutReceipts(hash common.Hash, receipts []*types.Receipt) error

	// GetReceiptsByBlockHash retrieves the receipts for the specified block hash.
	GetReceiptsByBlockHash(hash common.Hash) ([]*types.Receipt, error)

	// GetReceiptByTxHash retrieves the receipt for the specified tx hash.
	GetReceiptByTxHash(txHash common.Hash) (*types.Receipt, error)

	// PutDirtyAccounts serializes given dirty accounts for the specified block hash.
	PutDirtyAccounts(hash common.Hash, accounts []common.Address) error

	// GetDirtyAccountsByBlockHash retrieves the receipts for the specified block hash.
	GetDirtyAccountsByBlockHash(hash common.Hash) ([]common.Address, error)

	// AddIndices addes tx/debt indices for the specified block.
	AddIndices(block *types.Block) error

	// GetTxIndex retrieves the tx index for the specified tx hash.
	GetTxIndex(txHash common.Hash) (*types.TxIndex, error)

	// GetDebtIndex retrieves the debt index for the specified debt hash
	GetDebtIndex(debtHash common.Hash) (*types.DebtIndex, error)

	// DeleteIndices deletes tx/debt indices of the specified block.
	DeleteIndices(block *types.Block) error
}

BlockchainStore is the interface that wraps the atomic CRUD methods of blockchain.

func NewBlockchainDatabase

func NewBlockchainDatabase(db database.Database) BlockchainStore

NewBlockchainDatabase returns a blockchainDatabase instance. There are following mappings in database:

  1. keyPrefixHash + height => hash
  2. keyHeadBlockHash => HEAD hash
  3. keyPrefixHeader + hash => header
  4. keyPrefixTD + hash => total difficulty (td for short)
  5. keyPrefixBody + hash => block body (transactions)
  6. keyPrefixReceipts + hash => block receipts
  7. keyPrefixTxIndex + txHash => txIndex

func NewCachedStore

func NewCachedStore(store BlockchainStore) BlockchainStore

NewCachedStore returns a cached blockchainDatabase instance based on LRU.

Jump to

Keyboard shortcuts

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