blockchain

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
	BlockChainVersion = 3
)
View Source
const IdealBatchSize = 100 * 1024

Variables

View Source
var (

	// Chain index prefixes (use `i` + single byte to avoid mixing data types).
	BloomBitsIndexPrefix = []byte("iB") // BloomBitsIndexPrefix is the data table of a chain indexer to track its progress

	ErrChainConfigNotFound = errors.New("ChainConfig not found") // general config not found error

)
View Source
var (
	ErrNoGenesis = errors.New("Genesis not found in chain")
)

Functions

func DeleteBlock

func DeleteBlock(db DatabaseDeleter, hash types.Hash, number uint64)

DeleteBlock removes all block data associated with a hash.

func DeleteBlockReceipts

func DeleteBlockReceipts(db DatabaseDeleter, hash types.Hash, number uint64)

DeleteBlockReceipts removes all receipt data associated with a block hash.

func DeleteBody

func DeleteBody(db DatabaseDeleter, hash types.Hash, number uint64)

DeleteBody removes all block body data associated with a hash.

func DeleteCanonicalHash

func DeleteCanonicalHash(db DatabaseDeleter, number uint64)

DeleteCanonicalHash removes the number to hash canonical mapping.

func DeleteHeader

func DeleteHeader(db DatabaseDeleter, hash types.Hash, number uint64)

DeleteHeader removes all block header data associated with a hash.

func DeleteTxAddrNonceLookupEntry

func DeleteTxAddrNonceLookupEntry(db DatabaseDeleter, tx *transaction.Transaction)

DeleteTxAddrNonceLookupEntry removes all transaction data associated with a hash.

func DeleteTxLookupEntry

func DeleteTxLookupEntry(db DatabaseDeleter, hash types.Hash)

DeleteTxLookupEntry removes all transaction data associated with a hash.

func FindCommonAncestor

func FindCommonAncestor(db DatabaseReader, a, b *block.Header) *block.Header

FindCommonAncestor returns the last common ancestor of two block headers

func GetAddrNonceTxLookupEntry

func GetAddrNonceTxLookupEntry(db DatabaseReader, sender types.Address, nonce uint64) (types.Hash, uint64, uint64)

func GetBlock

func GetBlock(db DatabaseReader, hash types.Hash, number uint64) *block.Block

GetBlock 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 GetBlockChainVersion

func GetBlockChainVersion(db DatabaseReader) int

GetBlockChainVersion reads the version number from db.

func GetBlockNumber

func GetBlockNumber(db DatabaseReader, hash types.Hash) uint64

GetBlockNumber returns the block number assigned to a block hash if the corresponding header is present in the database

func GetBlockReceipts

func GetBlockReceipts(db DatabaseReader, hash types.Hash, number uint64) transaction.Receipts

GetBlockReceipts retrieves the receipts generated by the transactions included in a block given by its hash.

func GetBloomBits

func GetBloomBits(db DatabaseReader, bit uint, section uint64, head types.Hash) ([]byte, error)

GetBloomBits retrieves the compressed bloom bit vector belonging to the given section and bit index from the.

func GetBody

func GetBody(db DatabaseReader, hash types.Hash, number uint64) *block.Body

GetBody retrieves the block body corresponding to the hash, nil if none found.

func GetBodyMsgp

func GetBodyMsgp(db DatabaseReader, hash types.Hash, number uint64) []byte

GetBodyMsgp retrieves the block body in Msgp encoding.

func GetCanonicalHash

func GetCanonicalHash(db DatabaseReader, number uint64) types.Hash

GetCanonicalHash retrieves a hash assigned to a canonical block number.

func GetChainConfig

func GetChainConfig(db DatabaseReader, hash types.Hash) (*params.ChainConfig, error)

GetChainConfig will fetch the network settings based on the given hash.

func GetCoinBaseReceipt

func GetCoinBaseReceipt(db DatabaseReader, blockHash types.Hash, blockNumber uint64) (*transaction.Receipt, types.Hash, uint64, uint64)

GetCoinBaseReceipt returns coin base transaction receipt

func GetExtra

func GetExtra(db DatabaseReader, key []byte) []byte

func GetHeadBlockHash

func GetHeadBlockHash(db DatabaseReader) types.Hash

GetHeadBlockHash retrieves the hash of the current canonical head block.

func GetHeadFastBlockHash

func GetHeadFastBlockHash(db DatabaseReader) types.Hash

GetHeadFastBlockHash retrieves the hash of the current canonical head block during fast synchronization. The difference between this and GetHeadBlockHash is that whereas the last block hash is only updated upon a full block import, the last fast hash is updated when importing pre-processed blocks.

func GetHeadHeaderHash

func GetHeadHeaderHash(db DatabaseReader) types.Hash

GetHeadHeaderHash retrieves the hash of the current canonical head block's header. The difference between this and GetHeadBlockHash is that whereas the last block hash is only updated upon a full block import, the last header hash is updated already at header import, allowing head tracking for the light synchronization mechanism.

func GetHeader

func GetHeader(db DatabaseReader, hash types.Hash, number uint64) *block.Header

GetHeader retrieves the block header corresponding to the hash, nil if none found.

func GetHeaderMsgp

func GetHeaderMsgp(db DatabaseReader, hash types.Hash, number uint64) []byte

GetHeaderMsgp retrieves a block header in its raw MSGP database encoding, or nil if the header's not found.

func GetReceipt

func GetReceipt(db DatabaseReader, hash types.Hash) (*transaction.Receipt, types.Hash, uint64, uint64)

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

func GetTransaction

func GetTransaction(db DatabaseReader, hash types.Hash) (*transaction.Transaction, types.Hash, uint64, uint64)

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

func GetTransactionByAddress

func GetTransactionByAddress(db DatabaseReader, addr types.Address, nonce uint64) (*transaction.Transaction, types.Hash, uint64, uint64)

func GetTxLookupEntry

func GetTxLookupEntry(db DatabaseReader, hash types.Hash) (types.Hash, uint64, uint64)

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

func PreimageTable

func PreimageTable(db database.IDatabase) database.IDatabase

PreimageTable returns a Database instance with the key prefix for preimage entries.

func SetReceiptsData

func SetReceiptsData(config *params.ChainConfig, block *block.Block, receipts transaction.Receipts)

SetReceiptsData computes all the non-consensus fields of the receipts

func WriteBlock

func WriteBlock(db database.IDatabasePutter, block *block.Block) error

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

func WriteBlockChainVersion

func WriteBlockChainVersion(db database.IDatabasePutter, vsn int)

WriteBlockChainVersion writes vsn as the version number to db.

func WriteBlockReceipts

func WriteBlockReceipts(db database.IDatabasePutter, hash types.Hash, number uint64, receipts transaction.Receipts) error

WriteBlockReceipts stores all the transaction receipts belonging to a block as a single receipt slice. This is used during chain reorganisations for rescheduling dropped transactions.

func WriteBlockStat

func WriteBlockStat(db database.IDatabasePutter, hash types.Hash, stat *BlockStat) error

func WriteBloomBits

func WriteBloomBits(db database.IDatabasePutter, bit uint, section uint64, head types.Hash, bits []byte)

WriteBloomBits writes the compressed bloom bits vector belonging to the given section and bit index.

func WriteBody

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

WriteBody serializes the body of a block into the database.

func WriteBodyMsgp

func WriteBodyMsgp(db database.IDatabasePutter, hash types.Hash, number uint64, data []byte) error

WriteBodyMsgp writes a serialized body of a block into the database.

func WriteCanonicalHash

func WriteCanonicalHash(db database.IDatabasePutter, hash types.Hash, number uint64) error

WriteCanonicalHash stores the canonical hash for the given block number.

func WriteChainConfig

func WriteChainConfig(db database.IDatabasePutter, hash types.Hash, cfg *params.ChainConfig) error

WriteChainConfig writes the chain config settings to the database.

func WriteExtra

func WriteExtra(db database.IDatabasePutter, key, val []byte) error

func WriteHeadBlockHash

func WriteHeadBlockHash(db database.IDatabasePutter, hash types.Hash) error

WriteHeadBlockHash stores the head block's hash.

func WriteHeadFastBlockHash

func WriteHeadFastBlockHash(db database.IDatabasePutter, hash types.Hash) error

WriteHeadFastBlockHash stores the fast head block's hash.

func WriteHeadHeaderHash

func WriteHeadHeaderHash(db database.IDatabasePutter, hash types.Hash) error

WriteHeadHeaderHash stores the head header's hash.

func WriteHeader

func WriteHeader(db database.IDatabasePutter, header *block.Header) error

WriteHeader serializes a block header into the database.

func WritePreimages

func WritePreimages(db database.IDatabase, number uint64, preimages map[types.Hash][]byte) error

WritePreimages writes the provided set of preimages to the database. `number` is the current block number, and is used for debug messages only.

func WriteTxLookupEntries

func WriteTxLookupEntries(db database.IDatabasePutter, block *block.Block) error

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

Types

type BadBlockArgs

type BadBlockArgs struct {
	Hash   types.Hash    `msg:"hash"`
	Header *block.Header `msg:"header"`
}

BadBlockArgs represents the entries in the list returned when bad blocks are queried.

type BlockChain

type BlockChain struct {
	// contains filtered or unexported fields
}

BlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations.

Importing blocks in to the block chain happens according to the set of rules defined by the two stage Validator. Processing of blocks is done using the Processor which processes the included transaction. The validation of the state is done in the second part of the Validator. Failing results in aborting of the import.

The BlockChain also helps in returning blocks from **any** chain included in the database as well as blocks that represents the canonical chain. It's important to note that GetBlock can return any block and does not need to be included in the canonical one where as GetBlockByNumber always represents the canonical chain.

func NewBlockChain

func NewBlockChain(chainDb database.IDatabase, config *params.ChainConfig, engine consensus.Engine) (*BlockChain, error)

NewBlockChain returns a fully initialised block chain using information available in the database. It initialises the default bchain Validator and Processor.

func (*BlockChain) BadBlocks

func (bc *BlockChain) BadBlocks() ([]BadBlockArgs, error)

BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network

func (*BlockChain) Config

func (bc *BlockChain) Config() *params.ChainConfig

Config retrieves the blockchain's chain configuration.

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *block.Block

CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentBlockNum

func (bc *BlockChain) CurrentBlockNum() uint64

func (*BlockChain) CurrentFastBlock

func (bc *BlockChain) CurrentFastBlock() *block.Block

CurrentFastBlock retrieves the current fast-sync head block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentHeader

func (bc *BlockChain) CurrentHeader() *block.Header

CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.

func (*BlockChain) Engine

func (bc *BlockChain) Engine() consensus.Engine

Engine retrieves the blockchain's consensus engine.

func (*BlockChain) Export

func (bc *BlockChain) Export(w io.Writer) error

Export writes the active chain to the given writer.

func (*BlockChain) ExportN

func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error

ExportN writes a subset of the active chain to the given writer.

func (*BlockChain) FastSyncCommitHead

func (bc *BlockChain) FastSyncCommitHead(hash types.Hash) error

FastSyncCommitHead sets the current head block to the one defined by the hash irrelevant what the chain contents were prior.

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *block.Block

Genesis retrieves the chain's genesis block.

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash types.Hash, number uint64) *block.Block

GetBlock retrieves a block from the database by hash and number, caching it if found.

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash types.Hash) *block.Block

GetBlockByHash retrieves a block from the database by hash, caching it if found.

func (*BlockChain) GetBlockByNumber

func (bc *BlockChain) GetBlockByNumber(number uint64) *block.Block

GetBlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.

func (*BlockChain) GetBlockHashesFromHash

func (bc *BlockChain) GetBlockHashesFromHash(hash types.Hash, max uint64) []types.Hash

GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.

func (*BlockChain) GetBlockStat

func (bc *BlockChain) GetBlockStat(hash types.Hash) *BlockStat

func (*BlockChain) GetBlocksFromHash

func (bc *BlockChain) GetBlocksFromHash(hash types.Hash, n int) (blocks []*block.Block)

GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.

func (*BlockChain) GetBody

func (bc *BlockChain) GetBody(hash types.Hash) *block.Body

GetBody retrieves a block body from the database by hash, caching it if found.

func (*BlockChain) GetBodyMsgp

func (bc *BlockChain) GetBodyMsgp(hash types.Hash) []byte

func (*BlockChain) GetConsensusData

func (bc *BlockChain) GetConsensusData(key types.Hash) []byte

func (*BlockChain) GetDb

func (bc *BlockChain) GetDb() database.IDatabase

func (*BlockChain) GetExtra

func (bc *BlockChain) GetExtra(key []byte) []byte

func (*BlockChain) GetGenesis

func (bc *BlockChain) GetGenesis() *block.Block

func (*BlockChain) GetHeader

func (bc *BlockChain) GetHeader(hash types.Hash, number uint64) *block.Header

GetHeader retrieves a block header from the database by hash and number, caching it if found.

func (*BlockChain) GetHeaderByHash

func (bc *BlockChain) GetHeaderByHash(hash types.Hash) *block.Header

GetHeaderByHash retrieves a block header from the database by hash, caching it if found.

func (*BlockChain) GetHeaderByNumber

func (bc *BlockChain) GetHeaderByNumber(number uint64) *block.Header

GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.

func (*BlockChain) GetNowBlockHash

func (bc *BlockChain) GetNowBlockHash() types.Hash

func (*BlockChain) GetReceiptsByHash

func (bc *BlockChain) GetReceiptsByHash(hash types.Hash) transaction.Receipts

GetReceiptsByHash retrieves the receipts for all transactions in a given block.

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash types.Hash, number uint64) bool

HasBlock checks if a block is fully present in the database or not.

func (*BlockChain) HasBlockAndState

func (bc *BlockChain) HasBlockAndState(hash types.Hash) bool

HasBlockAndState checks if a block and associated state trie is fully present in the database or not, caching it if present.

func (*BlockChain) HasHeader

func (bc *BlockChain) HasHeader(hash types.Hash, number uint64) bool

HasHeader checks if a block header is present in the database or not, caching it if present.

func (*BlockChain) HasState

func (bc *BlockChain) HasState(hash types.Hash) bool

HasState checks if state trie is fully present in the database or not.

func (*BlockChain) InsertChain

func (bc *BlockChain) InsertChain(chain block.Blocks) (int, error)

InsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork. If an error is returned it will return the index number of the failing block as well an error describing what went wrong.

After insertion is done, all accumulated events will be fired.

func (*BlockChain) InsertHeaderChain

func (bc *BlockChain) InsertHeaderChain(chain []*block.Header, checkFreq int) (int, error)

InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.

The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verify nonces, as well as because nonces can be verified sparsely, not needing to check each.

func (*BlockChain) InsertReceiptChain

func (bc *BlockChain) InsertReceiptChain(blockChain block.Blocks, receiptChain []transaction.Receipts) (int, error)

InsertReceiptChain attempts to complete an already existing header chain with transaction and receipt data.

func (*BlockChain) LastBlockHash

func (bc *BlockChain) LastBlockHash() types.Hash

LastBlockHash return the hash of the HEAD block.

func (*BlockChain) MuLock

func (bc *BlockChain) MuLock()

func (*BlockChain) MuUnLock

func (bc *BlockChain) MuUnLock()

func (*BlockChain) PostChainEvents

func (bc *BlockChain) PostChainEvents(events []interface{}, logs []*transaction.Log)

PostChainEvents iterates over the events generated by a chain insertion and posts them into the event feed. TODO: Should not expose PostChainEvents. The chain events should be posted in WriteBlock.

func (*BlockChain) Processor

func (bc *BlockChain) Processor() Processor

Processor returns the current processor.

func (*BlockChain) ReportBlock

func (bc *BlockChain) ReportBlock(block *block.Block, receipts transaction.Receipts, err error)

func (*BlockChain) Reset

func (bc *BlockChain) Reset() error

Reset purges the entire blockchain, restoring it to its genesis state.

func (*BlockChain) ResetWithGenesisBlock

func (bc *BlockChain) ResetWithGenesisBlock(genesis *block.Block) error

ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.

func (*BlockChain) Rollback

func (bc *BlockChain) Rollback(chain []types.Hash)

Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.

func (*BlockChain) SetHead

func (bc *BlockChain) SetHead(head uint64) error

SetHead rewinds the local chain to a new head. In the case of headers, everything above the new head will be deleted and the new one set. In the case of blocks though, the head may be further rewound if block bodies are missing (non-archive nodes after a fast sync).

func (*BlockChain) SetProcessor

func (bc *BlockChain) SetProcessor(processor Processor)

SetProcessor sets the processor required for making state modifications.

func (*BlockChain) SetValidator

func (bc *BlockChain) SetValidator(validator Validator)

SetValidator sets the validator which is used to validate incoming blocks.

func (*BlockChain) State

func (bc *BlockChain) State() (*state.StateDB, error)

State returns a new mutable state based on the current HEAD block.

func (*BlockChain) StateAt

func (bc *BlockChain) StateAt(root types.Hash) (*state.StateDB, error)

StateAt returns a new mutable state based on a particular point in time.

func (*BlockChain) StateCache

func (bc *BlockChain) StateCache() state.Database

func (*BlockChain) Status

func (bc *BlockChain) Status() (numnber *big.Int, currentBlock types.Hash, genesisBlock types.Hash)

Status returns status information about the current chain such as the HEAD Number, the HEAD hash and the hash of the genesis block.

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.

func (*BlockChain) SubscribeChainEvent

func (bc *BlockChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription

SubscribeChainEvent registers a subscription of ChainEvent.

func (*BlockChain) SubscribeChainHeadEvent

func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

SubscribeChainHeadEvent registers a subscription of ChainHeadEvent.

func (*BlockChain) SubscribeChainSideEvent

func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

SubscribeChainSideEvent registers a subscription of ChainSideEvent.

func (*BlockChain) SubscribeLogsEvent

func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*transaction.Log) event.Subscription

SubscribeLogsEvent registers a subscription of []*types.Log.

func (*BlockChain) SubscribeRemovedLogsEvent

func (bc *BlockChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription

SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.

func (*BlockChain) Test_insert

func (bc *BlockChain) Test_insert(block *block.Block)

func (*BlockChain) Validate

func (bc *BlockChain) Validate() Validator

func (*BlockChain) Validator

func (bc *BlockChain) Validator() Validator

Validator returns the current validator.

func (*BlockChain) VerifyNextRoundBlock

func (bc *BlockChain) VerifyNextRoundBlock(block *block.Block) bool

func (*BlockChain) WriteBlockAndState

func (bc *BlockChain) WriteBlockAndState(block *block.Block, receipts []*transaction.Receipt, state *state.StateDB) (status WriteStatus, err error)

WriteBlock writes the block to the chain.

func (*BlockChain) WriteConsensusData

func (bc *BlockChain) WriteConsensusData(key types.Hash, value []byte) error

type BlockStat

type BlockStat struct {
	Ttxs        *types.BigInt
	TsoNormal   *types.BigInt
	TsoContract *types.BigInt
	TstateNum   *types.BigInt
}

block statistics info

func GetBlockStat

func GetBlockStat(db DatabaseReader, hash types.Hash) *BlockStat

func (*BlockStat) DecodeMsg

func (z *BlockStat) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*BlockStat) EncodeMsg

func (z *BlockStat) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*BlockStat) MarshalMsg

func (z *BlockStat) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*BlockStat) Msgsize

func (z *BlockStat) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*BlockStat) UnmarshalMsg

func (z *BlockStat) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type BlockValidator

type BlockValidator struct {
	// contains filtered or unexported fields
}

BlockValidator implements Validator.

func NewBlockValidator

func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator

NewBlockValidator returns a new block validator which is safe for re-use

func (*BlockValidator) ValidateBody

func (v *BlockValidator) ValidateBody(blk *block.Block) error

ValidateBody verifies the the block header's transaction root. The headers are assumed to be already validated at this point.

func (*BlockValidator) ValidateState

func (v *BlockValidator) ValidateState(blk, parent *block.Block, statedb *state.StateDB, receipts transaction.Receipts) error

ValidateState validates the various changes that happen after a state transition, such as the receipt roots and the state root itself. ValidateState returns a database batch if the validation was a success otherwise nil and an error is returned.

type CacheConfig

type CacheConfig struct {
	Disabled      bool          // Whether to disable trie write caching (archive node)
	TrieNodeLimit int           // Memory limit (MB) at which to flush the current in-memory trie to disk
	TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
}

CacheConfig contains the configuration values for the trie caching/pruning that's resident in a blockchain.

type DatabaseDeleter

type DatabaseDeleter interface {
	Delete(key []byte) error
}

DatabaseDeleter wraps the Delete method of a backing data store.

type DatabaseReader

type DatabaseReader interface {
	Get(key []byte) (value []byte, err error)
}

DatabaseReader wraps the Get method of a backing data store.

type DeleteCallback

type DeleteCallback func(types.Hash, uint64)

DeleteCallback is a callback function that is called by SetHead before each header is deleted.

type HeaderChain

type HeaderChain struct {
	// contains filtered or unexported fields
}

HeaderChain implements the basic block header chain logic that is shared by core.BlockChain and light.LightChain. It is not usable in itself, only as a part of either structure. It is not thread safe either, the encapsulating chain structures should do the necessary mutex locking/unlocking.

func NewHeaderChain

func NewHeaderChain(chainDb database.IDatabase, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error)

NewHeaderChain creates a new HeaderChain structure.

getValidator should return the parent's validator
procInterrupt points to the parent's interrupt semaphore
wg points to the parent's shutdown wait group

func (*HeaderChain) Config

func (hc *HeaderChain) Config() *params.ChainConfig

Config retrieves the header chain's chain configuration.

func (*HeaderChain) CurrentHeader

func (hc *HeaderChain) CurrentHeader() *block.Header

CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.

func (*HeaderChain) Engine

func (hc *HeaderChain) Engine() consensus.Engine

Engine retrieves the header chain's consensus engine.

func (*HeaderChain) GetBlock

func (hc *HeaderChain) GetBlock(hash types.Hash, number uint64) *block.Block

GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.

func (*HeaderChain) GetBlockHashesFromHash

func (hc *HeaderChain) GetBlockHashesFromHash(hash types.Hash, max uint64) []types.Hash

GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.

func (*HeaderChain) GetBlockNumber

func (hc *HeaderChain) GetBlockNumber(hash types.Hash) uint64

GetBlockNumber retrieves the block number belonging to the given hash from the cache or database

func (*HeaderChain) GetHeader

func (hc *HeaderChain) GetHeader(hash types.Hash, number uint64) *block.Header

GetHeader retrieves a block header from the database by hash and number, caching it if found.

func (*HeaderChain) GetHeaderByHash

func (hc *HeaderChain) GetHeaderByHash(hash types.Hash) *block.Header

GetHeaderByHash retrieves a block header from the database by hash, caching it if found.

func (*HeaderChain) GetHeaderByNumber

func (hc *HeaderChain) GetHeaderByNumber(number uint64) *block.Header

GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.

func (*HeaderChain) HasHeader

func (hc *HeaderChain) HasHeader(hash types.Hash, number uint64) bool

HasHeader checks if a block header is present in the database or not.

func (*HeaderChain) InsertHeaderChain

func (hc *HeaderChain) InsertHeaderChain(chain []*block.Header, writeHeader WhCallback, start time.Time) (int, error)

InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.

The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verfy nonces, as well as because nonces can be verified sparsely, not needing to check each.

func (*HeaderChain) SetCurrentHeader

func (hc *HeaderChain) SetCurrentHeader(head *block.Header)

SetCurrentHeader sets the current head header of the canonical chain.

func (*HeaderChain) SetGenesis

func (hc *HeaderChain) SetGenesis(head *block.Header)

SetGenesis sets a new genesis block header for the chain

func (*HeaderChain) SetHead

func (hc *HeaderChain) SetHead(head uint64, delFn DeleteCallback)

SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.

func (*HeaderChain) ValidateHeaderChain

func (hc *HeaderChain) ValidateHeaderChain(chain []*block.Header, checkFreq int) (int, error)

func (*HeaderChain) WriteHeader

func (hc *HeaderChain) WriteHeader(header *block.Header) (status WriteStatus, err error)

WriteHeader writes a header into the local chain, given that its parent is already known.

type Processor

type Processor interface {
	Process(block *block.Block, statedb *state.StateDB, db database.IDatabaseGetter, config *params.ChainConfig) (transaction.Receipts, []*transaction.Log, error)
}

Processor is an interface for processing blocks using a given initial state.

Process takes the block to be processed and the statedb upon which the initial state is based. It should return the receipts generated and return an error if any of the internal rules failed.

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.

func (*TxLookupEntry) DecodeMsg

func (z *TxLookupEntry) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*TxLookupEntry) EncodeMsg

func (z *TxLookupEntry) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*TxLookupEntry) MarshalMsg

func (z *TxLookupEntry) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*TxLookupEntry) Msgsize

func (z *TxLookupEntry) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*TxLookupEntry) UnmarshalMsg

func (z *TxLookupEntry) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Validator

type Validator interface {
	// ValidateBody validates the given block's content.
	ValidateBody(block *block.Block) error

	// ValidateState validates the given statedb and optionally the receipts
	ValidateState(block, parent *block.Block, state *state.StateDB, receipts transaction.Receipts) error
}

type WhCallback

type WhCallback func(*block.Header) error

WhCallback is a callback function for inserting individual headers. A callback is used for two reasons: first, in a LightChain, status should be processed and light chain events sent, while in a BlockChain this is not necessary since chain events are sent after inserting blocks. Second, the header writes should be protected by the parent chain mutex individually.

type WriteStatus

type WriteStatus byte

WriteStatus status of write

const (
	NonStatTy WriteStatus = iota
	CanonStatTy
	SideStatTy
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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