6 "github.com/vapor/common"
7 "github.com/vapor/protocol/bc"
8 "github.com/vapor/protocol/bc/types"
11 // ChainReader defines a small collection of methods needed to access the local
12 // blockchain during header and/or uncle verification.
13 type ChainReader interface {
14 // Config retrieves the blockchain's chain configuration.
15 //Config() *params.ChainConfig
17 // CurrentHeader retrieves the current header from the local chain.
18 CurrentHeader() *types.BlockHeader
20 // GetHeader retrieves a block header from the database by hash and number.
21 GetHeader(hash bc.Hash, number uint64) *types.BlockHeader
23 // GetHeaderByNumber retrieves a block header from the database by number.
24 GetHeaderByNumber(number uint64) *types.BlockHeader
26 // GetHeaderByHash retrieves a block header from the database by its hash.
27 GetHeaderByHash(hash bc.Hash) *types.BlockHeader
29 // GetBlock retrieves a block from the database by hash and number.
30 GetBlock(hash bc.Hash, number uint64) *types.Block
33 // Engine is an algorithm agnostic consensus engine.
34 type Engine interface {
35 // Author retrieves the Ethereum address of the account that minted the given
36 // block, which may be different from the header's coinbase if a consensus
37 // engine is based on signatures.
38 Author(header *types.BlockHeader) (common.Address, error)
40 // VerifyHeader checks whether a header conforms to the consensus rules of a
41 // given engine. Verifying the seal may be done optionally here, or explicitly
42 // via the VerifySeal method.
43 VerifyHeader(chain ChainReader, header *types.BlockHeader, seal bool) error
45 // VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
46 // concurrently. The method returns a quit channel to abort the operations and
47 // a results channel to retrieve the async verifications (the order is that of
49 VerifyHeaders(chain ChainReader, headers []*types.BlockHeader, seals []bool) (chan<- struct{}, <-chan error)
51 // VerifyUncles verifies that the given block's uncles conform to the consensus
52 // rules of a given engine.
53 VerifyUncles(chain ChainReader, block *types.Block) error
55 // VerifySeal checks whether the crypto seal on a header is valid according to
56 // the consensus rules of the given engine.
57 VerifySeal(chain ChainReader, header *types.BlockHeader) error
59 // Prepare initializes the consensus fields of a block header according to the
60 // rules of a particular engine. The changes are executed inline.
61 Prepare(chain ChainReader, header *types.BlockHeader) error
63 // Finalize runs any post-transaction state modifications (e.g. block rewards)
64 // and assembles the final block.
65 // Note: The block header and state database might be updated to reflect any
66 // consensus rules that happen at finalization (e.g. block rewards).
68 Finalize(chain ChainReader, header *types.BlockHeader , state *state.StateDB, txs []*types.Transaction,
69 uncles []*types.BlockHeader , receipts []*types.Receipt) (*types.Block, error)
72 // Seal generates a new block for the given input block with the local miner's
74 Seal(chain ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
76 // CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
77 // that a new block should have.
78 CalcDifficulty(chain ChainReader, time uint64, parent *types.BlockHeader) *big.Int
80 // APIs returns the RPC APIs this consensus engine provides.
81 //APIs(chain ChainReader) []rpc.API