github.com/theQRL/go-zond@v0.2.1/consensus/consensus.go (about)

     1  // Copyright 2017 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Package consensus implements different Zond consensus engines.
    18  package consensus
    19  
    20  import (
    21  	"github.com/theQRL/go-zond/common"
    22  	"github.com/theQRL/go-zond/core/state"
    23  	"github.com/theQRL/go-zond/core/types"
    24  	"github.com/theQRL/go-zond/params"
    25  	"github.com/theQRL/go-zond/rpc"
    26  )
    27  
    28  // ChainHeaderReader defines a small collection of methods needed to access the local
    29  // blockchain during header verification.
    30  type ChainHeaderReader interface {
    31  	// Config retrieves the blockchain's chain configuration.
    32  	Config() *params.ChainConfig
    33  
    34  	// CurrentHeader retrieves the current header from the local chain.
    35  	CurrentHeader() *types.Header
    36  
    37  	// GetHeader retrieves a block header from the database by hash and number.
    38  	GetHeader(hash common.Hash, number uint64) *types.Header
    39  
    40  	// GetHeaderByNumber retrieves a block header from the database by number.
    41  	GetHeaderByNumber(number uint64) *types.Header
    42  
    43  	// GetHeaderByHash retrieves a block header from the database by its hash.
    44  	GetHeaderByHash(hash common.Hash) *types.Header
    45  }
    46  
    47  // ChainReader defines a small collection of methods needed to access the local
    48  // blockchain during header.
    49  type ChainReader interface {
    50  	ChainHeaderReader
    51  
    52  	// GetBlock retrieves a block from the database by hash and number.
    53  	GetBlock(hash common.Hash, number uint64) *types.Block
    54  }
    55  
    56  // Engine is an algorithm agnostic consensus engine.
    57  type Engine interface {
    58  	// Author retrieves the Zond address of the account that minted the given
    59  	// block, which may be different from the header's coinbase if a consensus
    60  	// engine is based on signatures.
    61  	Author(header *types.Header) (common.Address, error)
    62  
    63  	// VerifyHeader checks whether a header conforms to the consensus rules of a
    64  	// given engine.
    65  	VerifyHeader(chain ChainHeaderReader, header *types.Header) error
    66  
    67  	// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
    68  	// concurrently. The method returns a quit channel to abort the operations and
    69  	// a results channel to retrieve the async verifications (the order is that of
    70  	// the input slice).
    71  	VerifyHeaders(chain ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error)
    72  
    73  	// Finalize runs any post-transaction state modifications (e.g. block rewards
    74  	// or process withdrawals) but does not assemble the block.
    75  	//
    76  	// Note: The state database might be updated to reflect any consensus rules
    77  	// that happen at finalization (e.g. block rewards).
    78  	Finalize(chain ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body)
    79  
    80  	// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
    81  	// rewards or process withdrawals) and assembles the final block.
    82  	//
    83  	// Note: The block header and state database might be updated to reflect any
    84  	// consensus rules that happen at finalization (e.g. block rewards).
    85  	FinalizeAndAssemble(chain ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body,
    86  		receipts []*types.Receipt) (*types.Block, error)
    87  
    88  	// APIs returns the RPC APIs this consensus engine provides.
    89  	APIs(chain ChainHeaderReader) []rpc.API
    90  
    91  	// Close terminates any background threads maintained by the consensus engine.
    92  	Close() error
    93  }