consensus

package
v0.0.0-...-d82d076 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: MIT, GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package consensus implements different Hpb consensus engines.

Index

Constants

View Source
const (
	ElectionContractMainnet = "0x60a3698bE1493da2065E6F84B2E77B5b5D201D5D"
	ElectionContractTestnet = "0x2B21E06f11eFd1272691B62428E31513bF3B6F31"

	ElectionContractAddr = ElectionContractMainnet

	BlockSetProxyTestnet = "0x35ceE08F55E4946876cE18850207A29Dd79EbBB6"
	BlockSetProxyMainnet = "0xF3bCFEB2538c4D00cdD9c54d7AB00c00856ffADE"
)
View Source
const BandwithLimit = 200 //200M
View Source
const BlockSetContractAddr = BlockSetProxyMainnet
View Source
const BlockSetGetValue = "getValue"
View Source
const BlockSetProxyABI = "" /* 2090-byte string literal not displayed */
View Source
const BootnodeInfoContractABI = "" /* 5200-byte string literal not displayed */
View Source
const BootnodeInfoContractAddr = "0x2251a2533556e7c6243a73f015eb96aa155c5791" //mainnet nodeinfo contract addr
View Source
const BootnodeInfoContractMethodName = "getAllHpbNodes"
View Source
const FechHpbBallotAddrABI = "" /* 3286-byte string literal not displayed */
View Source
const Fechcontractaddr = "0x43f75fc8c4fc623b8ddf0039ee76e9d4ca9ca7b3"
View Source
const HPBMainNetWorkId = 100
View Source
const HpbNodeBacktrackingNumber = 100
View Source
const HpbNodeCheckpointInterval = 200
View Source
const Hpcalclookbackround = 3
View Source
const InvokeIndexOne = 1
View Source
const InvokeIndexThree = 3
View Source
const InvokeIndexTwo = 2
View Source
const MaxBlockForever = 999999999999999999 // ()
View Source
const NewContractABI = "" /* 289-byte string literal not displayed */
View Source
const NewContractAddr = "0x5f1fbc00690f2cba74985126cae1b9e0bc09cdc8"
View Source
const NewContractInterfaceABI = "" /* 819-byte string literal not displayed */
View Source
const NewContractMethod = "getInvokeContract"
View Source
const NewfetchAllHolderAddrs = "fetchAllHolderAddrs"
View Source
const NewfetchAllVoteResult = "fetchAllVoteResult"
View Source
const NewgetAllHpbNodes = "getAllHpbNodes"
View Source
const Nodenumfirst = 151
View Source
const NumberBackBandwith = 1100 //bandwith statistic block num + 100
View Source
const StepLength = 4

Variables

View Source
var (
	HpbNodenumber = 31    //hpb nodes number
	NumberPrehp   = 20    //nodes num from 151 nodes select
	IgnoreRetErr  = false //ignore finalize return err

	StageNumberII  uint64 = 260000
	StageNumberIII uint64 = 1200000
	StageNumberIV  uint64 = 2560000
	StageNumberV   uint64 = 999999000000 // unused forever
	StageNumberVI  uint64 = 2561790
	StageNumberVII uint64 = 2896000

	StageNumberRealRandom uint64 = 5159000               // used to enable real random.
	StateNumberNewHash           = StageNumberRealRandom // used to enable fpga hashV2 and limit continue gen block.

	StageNumberUpgradedEVM uint64 = 8685000 // used to upgraded EVM .

	StageNumberNewPrecompiledContract uint64 = 11850000

	ContinuousGenBlkLimit uint64 = 2

	NewContractVersion        uint64 = 3788000
	CadNodeCheckpointInterval uint64 = 200

	StageElectionKey             = "ElectionBlock"
	StageNumberElection   uint64 = MaxBlockForever // got from contract, otherwise forever not used.
	StageNumberEvmBugFork uint64 = 12414000        // fix contract bug for unlimited generate HPB coin happend at 2021-10-20
)
View Source
var (
	// ErrUnknownAncestor is returned when validating a block requires an ancestor
	// that is unknown.
	ErrUnknownAncestor = errors.New("unknown ancestor")

	// ErrFutureBlock is returned when a block's timestamp is in the future according
	// to the current node.
	ErrFutureBlock = errors.New("block in the future")

	// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
	// plus one.
	ErrInvalidNumber = errors.New("invalid block number")

	// extra-data
	ErrMissingVanity = errors.New("extra-data 32 byte vanity prefix missing")

	ErrMissingSignature = errors.New("extra-data 65 byte suffix signature missing")

	ErrExtraSigners = errors.New("non-checkpoint block contains extra signer list")

	// invalid signer list on checkpoint block
	ErrInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")

	ErrInvalidMixDigest = errors.New("non-zero mix digest")

	ErrInvalidUncleHash = errors.New("non empty uncle hash")

	// invalid difficulty, only 1 or 2 allowed
	ErrInvalidDifficulty = errors.New("invalid difficulty")

	ErrInvalidTimestamp = errors.New("invalid timestamp")

	ErrInvalidVotingChain = errors.New("invalid voting chain")

	ErrUnauthorized = errors.New("unauthorized")

	ErrWaitTransactions = errors.New("waiting for transactions")

	ErrUnknownBlock = errors.New("unknown block")

	ErrInvalidCheckpointBeneficiary = errors.New("beneficiary in checkpoint block non-zero")

	ErrInvalidVote = errors.New("vote nonce not 0x00..0 or 0xff..f")

	// vote nonce in checkpoint block non-zero
	ErrInvalidCheckpointVote = errors.New("vote nonce in checkpoint block non-zero")
	// reject block but do not drop peer
	ErrInvalidblockbutnodrop = errors.New("reject block but do not drop peer")
	// boe hecheck err
	Errboehwcheck = errors.New("boe hwcheck err")
	// verify header random err
	Errrandcheck = errors.New("verify header random err")
	// bandwith err
	ErrBandwith = errors.New("verify header bandwith beyond the limit")
	// bad param
	ErrBadParam = errors.New("input bad param")
	// invalid cadaddress
	ErrInvalidCadaddr = errors.New("invalid cadaddress")
	Errnilparam       = errors.New("input param is nil")
	ErrNoLastBlock    = errors.New("No Last Block when verify during the fullsync")
)
View Source
var (
	NonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signerHash
	NonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signerHash.
	Zeroaddr      = common.HexToAddress("0x0000000000000000000000000000000000000000")

	ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signerHash vanity
	ExtraSeal   = 65 // Fixed number of extra-data suffix bytes reserved for signerHash seal
)

Functions

func Ecrecover

func Ecrecover(header *types.Header, sigcache *lru.ARCCache) (common.Address, error)

get current signer

func Gen32BRandom

func Gen32BRandom() [32]byte

func SetTestParam

func SetTestParam()

func SigHash

func SigHash(header *types.Header) (hash common.Hash)

func VerifyHWRlRndSign

func VerifyHWRlRndSign(HWRlRnd []byte, Sign []byte) (common.Address, error)

Types

type ChainReader

type ChainReader interface {
	// Config retrieves the blockchain's chain configuration.
	Config() *config.ChainConfig

	// CurrentHeader retrieves the current header from the local chain.
	CurrentHeader() *types.Header

	// GetHeader retrieves a block header from the database by hash and number.
	GetHeader(hash common.Hash, number uint64) *types.Header

	// GetHeaderByNumber retrieves a block header from the database by number.
	GetHeaderByNumber(number uint64) *types.Header

	// GetHeaderByHash retrieves a block header from the database by its hash.
	GetHeaderByHash(hash common.Hash) *types.Header

	// GetBlock retrieves a block from the database by hash and number.
	GetBlock(hash common.Hash, number uint64) *types.Block

	StateAt(root common.Hash) (*state.StateDB, error)
}

ChainReader defines a small collection of methods needed to access the local blockchain during header and/or uncle verification.

type Engine

type Engine interface {
	// Author retrieves the Hpb address of the account that minted the given
	// block, which may be different from the header's coinbase if a consensus
	// engine is based on signatures.
	Author(header *types.Header) (common.Address, error)

	// VerifyHeader checks whether a header conforms to the consensus rules of a
	// given engine. Verifying the seal may be done optionally here, or explicitly
	// via the VerifySeal method.
	VerifyHeader(chain ChainReader, header *types.Header, seal bool, mode config.SyncMode) error

	// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
	// concurrently. The method returns a quit channel to abort the operations and
	// a results channel to retrieve the async verifications (the order is that of
	// the input slice).
	VerifyHeaders(chain ChainReader, headers []*types.Header, seals []bool, mode config.SyncMode) (chan<- struct{}, <-chan error)

	//set net node type
	SetNetTopology(chain ChainReader, headers []*types.Header)

	// VerifyUncles verifies that the given block's uncles conform to the consensus
	// rules of a given engine.
	VerifyUncles(chain ChainReader, block *types.Block) error

	// VerifySeal checks whether the crypto seal on a header is valid according to
	// the consensus rules of the given engine.
	VerifySeal(chain ChainReader, header *types.Header) error

	PrepareBlockHeader(chain ChainReader, header *types.Header, state *state.StateDB) error

	// Finalize runs any post-transaction state modifications (e.g. block rewards)
	// and assembles the final block.
	// Note: The block header and state database might be updated to reflect any
	// consensus rules that happen at finalization (e.g. block rewards).
	Finalize(chain ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
		uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

	// Seal generates a new block for the given input block with the local miner's
	// seal place on top.
	GenBlockWithSig(chain ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

	// APIs returns the RPC APIs this consensus engine provides.
	APIs(chain ChainReader) []rpc.API
}

Engine is an algorithm agnostic consensus engine.

Directories

Path Synopsis
puppeth is a command to assemble networks configure.
puppeth is a command to assemble networks configure.
puppeth is a command to assemble networks configure.
puppeth is a command to assemble networks configure.

Jump to

Keyboard shortcuts

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