Documentation ¶
Overview ¶
Package dpos implements the proof-of-stake-authority consensus engine.
Index ¶
- Constants
- Variables
- func DposRLP(header *types.Header) []byte
- func SealHash(header *types.Header) (hash common.Hash)
- type API
- func (api *API) CancelQueueValidatorsLength(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) EffictiveValsLength(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) EpochInfo(epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.EpochInfo, error)
- func (api *API) GetAddressProposalCount(addr common.Address, number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) GetAddressProposalSets(addr common.Address, number *rpc.BlockNumber) ([]string, error)
- func (api *API) GetAddressProposals(addr common.Address, number *rpc.BlockNumber) ([]ProposalInfo, error)
- func (api *API) GetAllProposalSets(number *rpc.BlockNumber) ([]string, error)
- func (api *API) GetAllProposals(number *rpc.BlockNumber) ([]ProposalInfo, error)
- func (api *API) GetBaseInfos(number *rpc.BlockNumber) (map[string]interface{}, error)
- func (api *API) GetCancelQueueValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetCurrentEpochValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetEffictiveValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetHeaderAndState(number *rpc.BlockNumber) (*types.Header, *state.StateDB, error)
- func (api *API) GetInvalidValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetProposal(id string, number *rpc.BlockNumber) (*ProposalInfo, error)
- func (api *API) GetProposalCount(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) GetTotalDeposit(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) GetTotalVotes(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) GetValidator(addr common.Address, number *rpc.BlockNumber) (*systemcontract.Validator, error)
- func (api *API) GetValidatorVoters(addr common.Address, number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)
- func (api *API) InvalidValsLength(number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) IsEffictiveValidator(addr common.Address, number *rpc.BlockNumber) (bool, error)
- func (api *API) KickoutInfo(epoch *big.Int, number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) PendingValidatorReward(addr common.Address, number *rpc.BlockNumber) (map[string]*big.Int, error)
- func (api *API) PendingVoteRedeem(val common.Address, voter common.Address, number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) PendingVoteReward(val common.Address, voter common.Address, number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) PunishInfo(addr common.Address, epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.Punish, error)
- func (api *API) Status() (*status, error)
- func (api *API) ValidatorRewardInfoByEpoch(addr common.Address, epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.Reward, error)
- func (api *API) ValidatorRewardsInfo(addr common.Address, number *rpc.BlockNumber) (*SysRewardsInfo, error)
- func (api *API) ValidatorVotersLength(addr common.Address, number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) VoteListLength(addr common.Address, number *rpc.BlockNumber) (*big.Int, error)
- func (api *API) VotesRewardRedeemInfo(val common.Address, voter common.Address, number *rpc.BlockNumber) (*systemcontract.VotesRewardRedeemInfo, error)
- func (api *API) VotesRewardRedeemInfos(voter common.Address, number *rpc.BlockNumber) ([]systemcontract.VotesRewardRedeemInfo, error)
- type Dpos
- func (d *Dpos) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (d *Dpos) ApplySysTx(evm *vm.EVM, state *state.StateDB, txIndex int, sender common.Address, ...) (ret []byte, vmerr error, err error)
- func (d *Dpos) Author(header *types.Header) (common.Address, error)
- func (d *Dpos) Authorize(validator common.Address, signFn ValidatorFn, signTxFn SignTxFn)
- func (d *Dpos) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (d *Dpos) CanCreate(state consensus.StateReader, addr common.Address, height *big.Int) bool
- func (d *Dpos) Close() error
- func (d *Dpos) CreateEvmExtraValidator(header *types.Header, parentState *state.StateDB) types.EvmExtraValidator
- func (d *Dpos) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) error
- func (d *Dpos) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (b *types.Block, rs []*types.Receipt, err error)
- func (d *Dpos) IsSysTransaction(sender common.Address, tx *types.Transaction, header *types.Header) (bool, error)
- func (d *Dpos) PreHandle(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB) error
- func (d *Dpos) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (d *Dpos) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (d *Dpos) SealHash(header *types.Header) common.Hash
- func (d *Dpos) SetChain(chain consensus.ChainHeaderReader)
- func (d *Dpos) SetStateFn(fn StateFn)
- func (d *Dpos) ValidateTx(sender common.Address, tx *types.Transaction, header *types.Header, ...) error
- func (d *Dpos) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (d *Dpos) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (d *Dpos) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error
- func (d *Dpos) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type EventCheckRule
- type Proposal
- type ProposalInfo
- type SignTxFn
- type Snapshot
- type StateFn
- type SysRewardsInfo
- type ValidatorFn
Constants ¶
const ( DirectionFrom blacklistDirection = iota DirectionTo DirectionBoth )
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") )
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.
var GenesisAlloc = `` /* 160280-byte string literal not displayed */
Functions ¶
func DposRLP ¶
DposRLP returns the rlp bytes which needs to be signed for the proof-of-stake-authority sealing. The RLP to sign consists of the entire header apart from the 65 byte signature contained at the end of the extra data.
Note, the method requires the extra data to be at least 65 bytes, otherwise it panics. This is done to avoid accidentally using both forms (signature present or not), which could be abused to produce different hashes for the same header.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a user facing RPC API to allow controlling the validator and voting mechanisms of the proof-of-authority scheme.
func (*API) CancelQueueValidatorsLength ¶
CancelQueueValidatorsLength return cancel queue validators length
func (*API) EffictiveValsLength ¶
EffictiveValsLength return effictive validators length
func (*API) EpochInfo ¶
func (api *API) EpochInfo(epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.EpochInfo, error)
EpochInfo return the epoch info
func (*API) GetAddressProposalCount ¶
func (api *API) GetAddressProposalCount(addr common.Address, number *rpc.BlockNumber) (*big.Int, error)
GetAddressProposalCount return the address proposal count
func (*API) GetAddressProposalSets ¶
func (api *API) GetAddressProposalSets(addr common.Address, number *rpc.BlockNumber) ([]string, error)
GetAddressProposalSets return the address proposal id
func (*API) GetAddressProposals ¶
func (api *API) GetAddressProposals(addr common.Address, number *rpc.BlockNumber) ([]ProposalInfo, error)
GetAddressProposals return the address proposals
func (*API) GetAllProposalSets ¶
func (api *API) GetAllProposalSets(number *rpc.BlockNumber) ([]string, error)
GetAllProposalSets return all proposals id
func (*API) GetAllProposals ¶
func (api *API) GetAllProposals(number *rpc.BlockNumber) ([]ProposalInfo, error)
GetAllProposals return all proposals
func (*API) GetBaseInfos ¶
func (api *API) GetBaseInfos(number *rpc.BlockNumber) (map[string]interface{}, error)
func (*API) GetCancelQueueValidators ¶
GetCancelQueueValidators return all canceling queue validators
func (*API) GetCurrentEpochValidators ¶
GetCurrentEpochValidators return current epoch validators
func (*API) GetEffictiveValidators ¶
GetEffictiveValidators return all effictive validators
func (*API) GetHeaderAndState ¶
func (*API) GetInvalidValidators ¶
GetInvalidValidators return all invalid validators
func (*API) GetProposal ¶
func (api *API) GetProposal(id string, number *rpc.BlockNumber) (*ProposalInfo, error)
GetProposal return the proposal of id
func (*API) GetProposalCount ¶
GetProposalCount return all proposal count
func (*API) GetSnapshot ¶
func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
GetSnapshot retrieves the state snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
func (*API) GetTotalDeposit ¶
GetTotalDeposit return total deposit
func (*API) GetTotalVotes ¶
GetTotalVotes return total votes
func (*API) GetValidator ¶
func (api *API) GetValidator(addr common.Address, number *rpc.BlockNumber) (*systemcontract.Validator, error)
GetValidator return the validator of address
func (*API) GetValidatorVoters ¶
func (api *API) GetValidatorVoters(addr common.Address, number *rpc.BlockNumber) ([]common.Address, error)
GetValidatorVoters return the address voter
func (*API) GetValidators ¶
GetValidators retrieves the list of authorized validators at the specified block.
func (*API) GetValidatorsAtHash ¶
GetValidatorsAtHash retrieves the list of authorized validators at the specified block.
func (*API) InvalidValsLength ¶
InvalidValsLength return invalid validators length
func (*API) IsEffictiveValidator ¶
IsEffictiveValidator return the address is validator
func (*API) KickoutInfo ¶
KickoutInfo return kickout addresses in epoch
func (*API) PendingValidatorReward ¶
func (api *API) PendingValidatorReward(addr common.Address, number *rpc.BlockNumber) (map[string]*big.Int, error)
PendingValidatorReward return the address reward
func (*API) PendingVoteRedeem ¶
func (api *API) PendingVoteRedeem(val common.Address, voter common.Address, number *rpc.BlockNumber) (*big.Int, error)
PendingVoteRedeem return the voter redeem validators voters
func (*API) PendingVoteReward ¶
func (api *API) PendingVoteReward(val common.Address, voter common.Address, number *rpc.BlockNumber) (*big.Int, error)
PendingVoteReward return the voter vote the validator rewards
func (*API) PunishInfo ¶
func (api *API) PunishInfo(addr common.Address, epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.Punish, error)
PunishInfo punishInfo function of systemRewards contract
func (*API) Status ¶
Status returns the status of the last N blocks, - the number of active validators, - the number of validators, - the percentage of in-turn blocks
func (*API) ValidatorRewardInfoByEpoch ¶
func (api *API) ValidatorRewardInfoByEpoch(addr common.Address, epoch *big.Int, number *rpc.BlockNumber) (*systemcontract.Reward, error)
ValidatorRewardInfoByEpoch return the address and the epoch reward info
func (*API) ValidatorRewardsInfo ¶
func (api *API) ValidatorRewardsInfo(addr common.Address, number *rpc.BlockNumber) (*SysRewardsInfo, error)
ValidatorRewardsInfo return the sys reward info
func (*API) ValidatorVotersLength ¶
func (api *API) ValidatorVotersLength(addr common.Address, number *rpc.BlockNumber) (*big.Int, error)
ValidatorVotersLength return the validator voters length
func (*API) VoteListLength ¶
VoteListLength return the voter vote list length
func (*API) VotesRewardRedeemInfo ¶
func (api *API) VotesRewardRedeemInfo(val common.Address, voter common.Address, number *rpc.BlockNumber) (*systemcontract.VotesRewardRedeemInfo, error)
VotesRewardRedeemInfo votesRewardRedeemInfo
func (*API) VotesRewardRedeemInfos ¶
func (api *API) VotesRewardRedeemInfos(voter common.Address, number *rpc.BlockNumber) ([]systemcontract.VotesRewardRedeemInfo, error)
VotesRewardRedeemInfos nodevotes.VotesRewardRedeemInfos
type Dpos ¶
type Dpos struct {
// contains filtered or unexported fields
}
Dpos is the proof-of-stake-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.
func New ¶
func New(chainConfig *params.ChainConfig, db ethdb.Database) *Dpos
New creates a Dpos proof-of-stake-authority consensus engine with the initial validators set to the ones provided by the user.
func (*Dpos) APIs ¶
func (d *Dpos) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the validator voting.
func (*Dpos) ApplySysTx ¶
func (d *Dpos) ApplySysTx(evm *vm.EVM, state *state.StateDB, txIndex int, sender common.Address, tx *types.Transaction) (ret []byte, vmerr error, err error)
ApplySysTx applies a system-transaction using a given evm, the main purpose of this method is for tracing a system-transaction.
func (*Dpos) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*Dpos) Authorize ¶
func (d *Dpos) Authorize(validator common.Address, signFn ValidatorFn, signTxFn SignTxFn)
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Dpos) CalcDifficulty ¶
func (d *Dpos) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have: * DIFF_NOTURN(2) if BLOCK_NUMBER % validator_COUNT != validator_INDEX * DIFF_INTURN(1) if BLOCK_NUMBER % validator_COUNT == validator_INDEX
func (*Dpos) CanCreate ¶
CanCreate determines where a given address can create a new contract.
This will query the system Developers contract, by DIRECTLY to get the target slot value of the contract, it means that it's strongly relative to the layout of the Developers contract's state variables
func (*Dpos) Close ¶
Close implements consensus.Engine. It's a noop for dpos as there are no background threads.
func (*Dpos) CreateEvmExtraValidator ¶
func (*Dpos) Finalize ¶
func (d *Dpos) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt, systemTxs []*types.Transaction) error
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.
func (*Dpos) FinalizeAndAssemble ¶
func (d *Dpos) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (b *types.Block, rs []*types.Receipt, err error)
FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*Dpos) IsSysTransaction ¶
func (d *Dpos) IsSysTransaction(sender common.Address, tx *types.Transaction, header *types.Header) (bool, error)
IsSysTransaction checks whether a specific transaction is a system transaction.
func (*Dpos) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Dpos) Seal ¶
func (d *Dpos) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Dpos) SetChain ¶
func (d *Dpos) SetChain(chain consensus.ChainHeaderReader)
func (*Dpos) SetStateFn ¶
SetStateFn sets the function to get state.
func (*Dpos) ValidateTx ¶
func (d *Dpos) ValidateTx(sender common.Address, tx *types.Transaction, header *types.Header, parentState *state.StateDB) error
ValidateTx do a consensus-related validation on the given transaction at the given header and state. the parentState must be the state of the header's parent block.
func (*Dpos) VerifyHeader ¶
func (d *Dpos) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Dpos) VerifyHeaders ¶
func (d *Dpos) VerifyHeaders(chain consensus.ChainHeaderReader, 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 (*Dpos) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Dpos) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
type EventCheckRule ¶
type EventCheckRule struct { EventSig common.Hash Checks map[int]common.AddressCheckType }
type Proposal ¶
type Proposal struct { Id *big.Int Action *big.Int From common.Address To common.Address Value *big.Int Data []byte }
Proposal is the system governance proposal info.
type ProposalInfo ¶
type SignTxFn ¶
type SignTxFn func(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
type Snapshot ¶
type Snapshot struct { Number uint64 `json:"number"` // Block number where the snapshot was created Hash common.Hash `json:"hash"` // Block hash where the snapshot was created Validators map[common.Address]struct{} `json:"validators"` // Set of authorized validators at this moment Recents map[uint64]common.Address `json:"recents"` // Set of recent validators for spam protections // contains filtered or unexported fields }
Snapshot is the state of the authorization voting at a given point in time.