Documentation ¶
Index ¶
- Variables
- type BlockchainStore
- type MemStore
- func (store *MemStore) AddIndices(block *types.Block) error
- func (store *MemStore) DeleteBlock(hash common.Hash) error
- func (store *MemStore) DeleteBlockHash(height uint64) (bool, error)
- func (store *MemStore) DeleteBlockHeader(hash common.Hash) error
- func (store *MemStore) DeleteIndices(block *types.Block) error
- func (store *MemStore) GetBlock(hash common.Hash) (*types.Block, error)
- func (store *MemStore) GetBlockByHeight(height uint64) (*types.Block, error)
- func (store *MemStore) GetBlockHash(height uint64) (common.Hash, error)
- func (store *MemStore) GetBlockHeader(hash common.Hash) (*types.BlockHeader, error)
- func (store *MemStore) GetBlockTotalDifficulty(hash common.Hash) (*big.Int, error)
- func (store *MemStore) GetDebtIndex(txHash common.Hash) (*types.DebtIndex, error)
- func (store *MemStore) GetHeadBlockHash() (common.Hash, error)
- func (store *MemStore) GetReceiptByTxHash(txHash common.Hash) (*types.Receipt, error)
- func (store *MemStore) GetReceiptsByBlockHash(hash common.Hash) ([]*types.Receipt, error)
- func (store *MemStore) GetTxIndex(txHash common.Hash) (*types.TxIndex, error)
- func (store *MemStore) HasBlock(hash common.Hash) (bool, error)
- func (store *MemStore) PutBlock(block *types.Block, td *big.Int, isHead bool) error
- func (store *MemStore) PutBlockHash(height uint64, hash common.Hash) error
- func (store *MemStore) PutBlockHeader(hash common.Hash, header *types.BlockHeader, td *big.Int, isHead bool) error
- func (store *MemStore) PutHeadBlockHash(hash common.Hash) error
- func (store *MemStore) PutReceipts(hash common.Hash, receipts []*types.Receipt) error
- func (store *MemStore) RecoverHeightToBlockMap(block *types.Block) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrDBCorrupt = errors.New("db corrupted")
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) // 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:
- keyPrefixHash + height => hash
- keyHeadBlockHash => HEAD hash
- keyPrefixHeader + hash => header
- keyPrefixTD + hash => total difficulty (td for short)
- keyPrefixBody + hash => block body (transactions)
- keyPrefixReceipts + hash => block receipts
- keyPrefixTxIndex + txHash => txIndex
func NewCachedStore ¶
func NewCachedStore(store BlockchainStore) BlockchainStore
NewCachedStore returns a cached blockchainDatabase instance based on LRU.
type MemStore ¶
type MemStore struct { CanonicalBlocks map[uint64]common.Hash // height to block hash map in canonical chain HeadBlockHash common.Hash // HEAD block hash Blocks map[common.Hash]*memBlock TxLookups map[common.Hash]types.TxIndex // tx hash to index mapping DebtLookups map[common.Hash]types.DebtIndex // debt hash to index mapping CorruptOnPutBlock bool // used to test blockchain recovery if program crashed }
MemStore prepresents a in-memory database that used for the blockchain.
func NewMemStore ¶
func NewMemStore() *MemStore
func (*MemStore) DeleteBlockHash ¶
func (*MemStore) DeleteBlockHeader ¶ added in v1.0.2
func (*MemStore) GetBlockByHeight ¶
func (*MemStore) GetBlockHash ¶
func (*MemStore) GetBlockHeader ¶
func (*MemStore) GetBlockTotalDifficulty ¶
func (*MemStore) GetDebtIndex ¶
func (*MemStore) GetReceiptByTxHash ¶
func (*MemStore) GetReceiptsByBlockHash ¶
func (*MemStore) GetTxIndex ¶
func (*MemStore) PutBlockHash ¶
func (*MemStore) PutBlockHeader ¶
func (*MemStore) PutReceipts ¶
Click to show internal directories.
Click to hide internal directories.