store

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: LGPL-3.0 Imports: 9 Imported by: 41

Documentation

Index

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:

  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.

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) AddIndices

func (store *MemStore) AddIndices(block *types.Block) error

func (*MemStore) DeleteBlock

func (store *MemStore) DeleteBlock(hash common.Hash) error

func (*MemStore) DeleteBlockHash

func (store *MemStore) DeleteBlockHash(height uint64) (bool, error)

func (*MemStore) DeleteBlockHeader added in v1.0.2

func (store *MemStore) DeleteBlockHeader(hash common.Hash) error

func (*MemStore) DeleteIndices

func (store *MemStore) DeleteIndices(block *types.Block) error

func (*MemStore) GetBlock

func (store *MemStore) GetBlock(hash common.Hash) (*types.Block, error)

func (*MemStore) GetBlockByHeight

func (store *MemStore) GetBlockByHeight(height uint64) (*types.Block, error)

func (*MemStore) GetBlockHash

func (store *MemStore) GetBlockHash(height uint64) (common.Hash, error)

func (*MemStore) GetBlockHeader

func (store *MemStore) GetBlockHeader(hash common.Hash) (*types.BlockHeader, error)

func (*MemStore) GetBlockTotalDifficulty

func (store *MemStore) GetBlockTotalDifficulty(hash common.Hash) (*big.Int, error)

func (*MemStore) GetDebtIndex

func (store *MemStore) GetDebtIndex(txHash common.Hash) (*types.DebtIndex, error)

func (*MemStore) GetHeadBlockHash

func (store *MemStore) GetHeadBlockHash() (common.Hash, error)

func (*MemStore) GetReceiptByTxHash

func (store *MemStore) GetReceiptByTxHash(txHash common.Hash) (*types.Receipt, error)

func (*MemStore) GetReceiptsByBlockHash

func (store *MemStore) GetReceiptsByBlockHash(hash common.Hash) ([]*types.Receipt, error)

func (*MemStore) GetTxIndex

func (store *MemStore) GetTxIndex(txHash common.Hash) (*types.TxIndex, error)

func (*MemStore) HasBlock

func (store *MemStore) HasBlock(hash common.Hash) (bool, error)

func (*MemStore) PutBlock

func (store *MemStore) PutBlock(block *types.Block, td *big.Int, isHead bool) error

func (*MemStore) PutBlockHash

func (store *MemStore) PutBlockHash(height uint64, hash common.Hash) error

func (*MemStore) PutBlockHeader

func (store *MemStore) PutBlockHeader(hash common.Hash, header *types.BlockHeader, td *big.Int, isHead bool) error

func (*MemStore) PutHeadBlockHash

func (store *MemStore) PutHeadBlockHash(hash common.Hash) error

func (*MemStore) PutReceipts

func (store *MemStore) PutReceipts(hash common.Hash, receipts []*types.Receipt) error

func (*MemStore) RecoverHeightToBlockMap added in v1.1.4

func (store *MemStore) RecoverHeightToBlockMap(block *types.Block) error

Jump to

Keyboard shortcuts

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