Documentation ¶
Overview ¶
Copyright 2018 The Spectrum Authors
Index ¶
- Constants
- Variables
- type API
- func (api *API) Bind(from *common.Address, passphrase string) (string, error)
- func (api *API) BindInfo(addr *common.Address, num *big.Int) (map[string]interface{}, error)
- func (api *API) BindSign(from *common.Address) (string, error)
- func (api *API) GetHistory(last *big.Int, noRpc *bool) (interface{}, error)
- func (api *API) GetMiner(number *rpc.BlockNumber) (*TribeMiner, error)
- func (api *API) GetSigners(hash *common.Hash) ([]*Signer, error)
- func (api *API) GetSinners(hash *common.Hash) ([]common.Address, error)
- func (api *API) GetStatus(hash *common.Hash) (*TribeStatus, error)
- func (api *API) GetVolunteers(hash *common.Hash) (*TribeVolunteers, error)
- func (api *API) PocDeposit(from *common.Address, passphrase string) (string, error)
- func (api *API) PocGetStatus(hash *common.Hash) (*params.PocStatus, error)
- func (api *API) PocStart(from *common.Address, passphrase string) (string, error)
- func (api *API) PocStop(from *common.Address, passphrase string) (string, error)
- func (api *API) PocWithdraw(from *common.Address, passphrase string) (string, error)
- func (api *API) PocWithdrawSurplus(from *common.Address, passphrase string) (string, error)
- func (api *API) Unbind(from *common.Address, passphrase string) (string, error)
- type History
- type Signer
- type SignerFn
- type Tribe
- func (t *Tribe) APIs(chain consensus.ChainReader) []rpc.API
- func (t *Tribe) Author(header *types.Header) (common.Address, error)
- func (t *Tribe) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (t *Tribe) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (t *Tribe) GetChiefUpdateTx(chain consensus.ChainReader, header *types.Header, state *state.StateDB) *types.Transaction
- func (t *Tribe) GetConfig() *params.TribeConfig
- func (t *Tribe) GetPeriod(header *types.Header, signers []*Signer) (p uint64)
- func (t *Tribe) GetPeriodChief100(header *types.Header, signers []*Signer) (p uint64)
- func (t *Tribe) Init()
- func (t *Tribe) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (t *Tribe) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (t *Tribe) SetConfig(config *params.TribeConfig)
- func (t *Tribe) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (t *Tribe) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (t *Tribe) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (t *Tribe) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type TribeMiner
- type TribeStatus
- func (self *TribeStatus) GetMinerAddress() common.Address
- func (self *TribeStatus) GetMinerAddressByChan(rtn chan common.Address)
- func (self *TribeStatus) GetNodeKey() *ecdsa.PrivateKey
- func (self *TribeStatus) InTurnForCalcDiffcultyChief100(signer common.Address, parent *types.Header) *big.Int
- func (self *TribeStatus) InTurnForCalcDifficulty(signer common.Address, parent *types.Header) *big.Int
- func (self *TribeStatus) InTurnForVerifyDiffculty(number int64, parentHash common.Hash, signer common.Address) *big.Int
- func (self *TribeStatus) InTurnForVerifyDifficultyChief100(number int64, parentHash common.Hash, signer common.Address) *big.Int
- func (self *TribeStatus) IsLeader(addr common.Address) bool
- func (self *TribeStatus) LoadStatusFromChief(hash common.Hash, number *big.Int) error
- func (self *TribeStatus) SetNodeKey(nodeKey *ecdsa.PrivateKey)
- func (self *TribeStatus) SetTribe(tribe *Tribe)
- func (self *TribeStatus) String() string
- func (self *TribeStatus) ValidateBlock(parent, block *types.Block, validateSigner bool) error
- type TribeVolunteers
- type Volunteer
Constants ¶
const ( // None -> Volunteer -> Signer -> Sinner LevelNone = "None" LevelVolunteer = "Volunteer" LevelSigner = "Signer" LevelSinner = "Sinner" //黑名单 CHIEF_NUMBER = int64(3) //最早版本chief合约开始生效的块数 )
Variables ¶
var ( // ErrInvalidTimestamp is returned if the timestamp of a block is lower than // the previous block's timestamp + the minimum block period. ErrInvalidTimestamp = errors.New("invalid timestamp") ErrInvalidTimestampSIP002 = errors.New("invalid timestamp (SIP002)") // for tribe consensus block validator ErrTribeNotAllowEmptyTxList = errors.New("tribe not allow empty tx list") ErrTribeMustContainChiefTx = errors.New("tribe must contain chief tx") ErrTribeChiefVolunteerLowBalance = errors.New("tribe chief volunteer low balance") ErrTribeChiefVolunteerFail = errors.New("tribe chief volunteer check fail") ErrTribeChiefTxMustAtPositionZero = errors.New("tribe chief tx must at postion 0") ErrTribeChiefTxSignerAndBlockSignerNotMatch = errors.New("tribe chief update tx signer and block signer not match") ErrTribeValdateTxSenderCannotInSignerList = errors.New("tx sender cannot in signerlist") Chief100BlockReward, _ = new(big.Int).SetString("35000000000000000000", 10) //Block reward in wei for successfully mining a block BlockRewardReducedInterval = 4505000 //half reward about two years SmartMeshFoundationAccount = common.HexToAddress("0xe0014a4268ad3d7b131551be47bc6ed72a6937e4") SmartMeshFoundationAccountDestroyBalance, _ = new(big.Int).SetString("376991118360000000000000000", 10) )
Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func (*API) GetHistory ¶
func (*API) GetMiner ¶
func (api *API) GetMiner(number *rpc.BlockNumber) (*TribeMiner, error)
func (*API) GetSinners ¶
chief-0.0.3 show blacklist
func (*API) GetVolunteers ¶
func (api *API) GetVolunteers(hash *common.Hash) (*TribeVolunteers, error)
func (*API) PocDeposit ¶
PocDeposit 调用poc合约的deposit质押,满足金额以后,自动开启挖矿
func (*API) PocGetStatus ¶
PocGetStatus 查询poc合约状态
func (*API) PocWithdraw ¶
PocWithdraw 调用poc合约的withdraw,在stop两周后,可以撤回押金
func (*API) PocWithdrawSurplus ¶
PocWithdrawSurplus 调用poc合约的PocWithdrawSurplus,从合约中撤回多余的抵押押金
type Signer ¶
type SignerFn ¶
SignerFn is a signer callback function to request a hash to be signed by a backing account.
type Tribe ¶
type Tribe struct { Status *TribeStatus // contains filtered or unexported fields }
func (*Tribe) APIs ¶
func (t *Tribe) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*Tribe) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*Tribe) CalcDifficulty ¶
func (t *Tribe) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.
func (*Tribe) Finalize ¶
func (t *Tribe) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*Tribe) GetChiefUpdateTx ¶
func (t *Tribe) GetChiefUpdateTx(chain consensus.ChainReader, header *types.Header, state *state.StateDB) *types.Transaction
获取要插入的chief Tx 1.0之后是通过vrf来选择下一轮出块人 1.0之前因为没有奖励,所以是现有signer任意指定候选人
func (*Tribe) GetConfig ¶
func (t *Tribe) GetConfig() *params.TribeConfig
func (*Tribe) GetPeriodChief100 ¶
GetPeriodChief100: 计算出块节点对应的延时时间 依据: 普通节点替补出块规则调整为当前常委会出块节点替补出块,当前常委会出块节点替补出块规则调整为常委会节点列表顺序替补出块,出块难度依次递减。 当普通节点出块时,难度为6->5->4->3->2->1;当常委会节点出块时,难度为6->5->4->3->2。每次替补出块时间都顺延4秒, 下一个区块将在当前区块产生以后的14秒+ 以后产生。 总共只有5个常委会节点,其排序固定 signers:[0,...,16] 0号对应的是常委会节点,1-16对应的是普通出块节点 场景1: 假设`header`中的块该signers[3]出, 如果signers[3]出,则延时14秒,否则只能由其他常委会节点替代 假设当前signers[0]对应的是常委2,那么如果常委2出则延时18,常委3出则延时22,...,如果常委1出则延时34 场景2: 假设`header`中的块该signers[0]出, 如果signers[0]出,则延时14秒,否则只能由其他常委会节点替代 假设当前signers[0]对应的是常委2,那么常委3出则延时18,常委4出则延时22,...常委1出则延时30
func (*Tribe) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Tribe) Seal ¶
func (t *Tribe) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Tribe) SetConfig ¶
func (t *Tribe) SetConfig(config *params.TribeConfig)
func (*Tribe) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Tribe) VerifyHeaders ¶
func (t *Tribe) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. 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).
func (*Tribe) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements. don't support remote miner agent, these code never reached
func (*Tribe) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
type TribeMiner ¶
type TribeStatus ¶
type TribeStatus struct { Signers []*Signer `json:"signers"` Leaders []common.Address `json:"leaders"` SignerLevel string `json:"signerLevel"` // None -> Volunteer -> Signer Number int64 `json:"number"` // last block.number // for watch the set method result Epoch *big.Int `json:"epoch"` LeaderLimit *big.Int `json:"leaderLimit"` SignerLimit *big.Int `json:"signerLimit"` Vsn string `json:"version"` // chief version // contains filtered or unexported fields }
func NewTribeStatus ¶
func NewTribeStatus() *TribeStatus
func (*TribeStatus) GetMinerAddress ¶
func (self *TribeStatus) GetMinerAddress() common.Address
func (*TribeStatus) GetMinerAddressByChan ¶
func (self *TribeStatus) GetMinerAddressByChan(rtn chan common.Address)
func (*TribeStatus) GetNodeKey ¶
func (self *TribeStatus) GetNodeKey() *ecdsa.PrivateKey
func (*TribeStatus) InTurnForCalcDiffcultyChief100 ¶
func (self *TribeStatus) InTurnForCalcDiffcultyChief100(signer common.Address, parent *types.Header) *big.Int
InTurnForCalcDiffcultyChief100 计算规则参考inTurnForCalcChief100
func (*TribeStatus) InTurnForCalcDifficulty ¶
func (self *TribeStatus) InTurnForCalcDifficulty(signer common.Address, parent *types.Header) *big.Int
InTurnForCalcDifficulty 在0.6版本yiqian 计算难度
func (*TribeStatus) InTurnForVerifyDiffculty ¶
func (self *TribeStatus) InTurnForVerifyDiffculty(number int64, parentHash common.Hash, signer common.Address) *big.Int
0.6版本之前校验难度
func (*TribeStatus) InTurnForVerifyDifficultyChief100 ¶
func (self *TribeStatus) InTurnForVerifyDifficultyChief100(number int64, parentHash common.Hash, signer common.Address) *big.Int
InTurnForVerifyDifficultyChief100: 计算规则参考inTurnForCalcChief100
func (*TribeStatus) LoadStatusFromChief ¶
在每次出块prepare的时候去获取一次,同时在同步区块的时候去获取一次,同步区块获取的是最新块的父区块信息,出块时获取的是当前本地最新块的状态信息
func (*TribeStatus) SetNodeKey ¶
func (self *TribeStatus) SetNodeKey(nodeKey *ecdsa.PrivateKey)
func (*TribeStatus) SetTribe ¶
func (self *TribeStatus) SetTribe(tribe *Tribe)
func (*TribeStatus) String ¶
func (self *TribeStatus) String() string
func (*TribeStatus) ValidateBlock ¶
func (self *TribeStatus) ValidateBlock(parent, block *types.Block, validateSigner bool) error
every block sync download or mine check chief tx