consensus

package
v0.0.0-...-3a744d8 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package consensus implements different Hpb consensus engines.

Index

Constants

View Source
const BandwithLimit = 200 //200M
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 HpbNodeBacktrackingNumber = 100 // 往前回溯的个数
View Source
const HpbNodeCheckpointInterval = 200 // 高性能投票间隔
View Source
const Hpcalclookbackround = 3
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 // 暂不启用
	StageNumberVI  uint64 = 2561790
	StageNumberVII uint64 = 2896000 //待定 6月23日15时

	CadNodeCheckpointInterval uint64 = 200 // 社区投票间隔
)
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。
	ErrExtraSigners = errors.New("non-checkpoint block contains extra signer list")

	// 没有经过授权的Signers
	ErrInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")

	// 错误的签名
	ErrInvalidMixDigest = errors.New("non-zero mix digest")

	// 非法的叔叔hash
	ErrInvalidUncleHash = errors.New("non empty uncle hash")

	// 错误的难度值,目前的难度值仅1和2
	ErrInvalidDifficulty = errors.New("invalid difficulty")

	// 错误的时间戳,保持一定的间隔
	ErrInvalidTimestamp = errors.New("invalid timestamp")

	// 不可靠的投票
	ErrInvalidVotingChain = errors.New("invalid voting chain")

	// 未授权错误
	ErrUnauthorized = errors.New("unauthorized")

	// 禁止使用0交易的区块
	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")
	// 非法的投票检查点
	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")
)

const Nodenumsecond = 301 const Nodenumthird = 1000

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)

获取当前的签名者

func SetTestParam

func SetTestParam()

func SigHash

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

对区块头部进行签名,最小65Byte

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