Documentation ¶
Overview ¶
Package dpos implements the Delegated-Proof-of-Stake consensus engine.
Index ¶
- Variables
- func CalcDifficulty(epoch *EpochContext, signer common.Address, parent *types.Header) *big.Int
- func SeedHash(block uint64) []byte
- type API
- func (api *API) GetCFDs(number *rpc.BlockNumber) (map[string]map[string]*big.Int, error)
- func (api *API) GetCandidate(addr common.Address, number *rpc.BlockNumber) (types.CandidateContext, error)
- func (api *API) GetCandidates(maxcnt, number *rpc.BlockNumber) ([]types.CandidateContext, error)
- func (api *API) GetMintCnt(addr common.Address, number *rpc.BlockNumber) (int64, error)
- func (api *API) GetMintCnts(maxcnt, number *rpc.BlockNumber) ([]types.MintCntAddress, error)
- func (api *API) GetSortableAddresses(number *rpc.BlockNumber) (types.SortableAddresses, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetVote(addr common.Address, number *rpc.BlockNumber) (map[string]types.VoteContext, error)
- func (api *API) GetVotes(number *rpc.BlockNumber) (map[string]types.VoteContext, error)
- type DPOS
- func (c *DPOS) APIs(chain consensus.ChainReader) []rpc.API
- func (c *DPOS) Author(header *types.Header) (common.Address, error)
- func (c *DPOS) Authorize(signer common.Address, signFn SignerFn)
- func (c *DPOS) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (c *DPOS) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (c *DPOS) JudgeTx(chain consensus.ChainReader, header *types.Header, tx *types.Transaction, ...) error
- func (c *DPOS) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (c *DPOS) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (c *DPOS) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (c *DPOS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *DPOS) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (c *DPOS) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type EpochContext
- type SignerFn
Constants ¶
This section is empty.
Variables ¶
var ( MinDelegateBalance = big.NewFloat(10 * 1e18) //10QCT MinCandidateBalance = big.NewFloat(100 * 1e18) //100QCT UnlockInterval = big.NewInt(10) //10 Block )
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") ErrWaitForPrevBlock = errors.New("wait for last block arrived") ErrMintFutureBlock = errors.New("mint the future block") ErrMismatchSignerAndValidator = errors.New("mismatch block signer and validator") ErrInvalidBlockValidator = errors.New("invalid block validator") ErrInvalidMintBlockTime = errors.New("invalid time to mint the block") ErrNilBlockHeader = errors.New("nil block header returned") )
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 ¶
func CalcDifficulty ¶
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.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a user facing RPC API to allow controlling the delegate and voting mechanisms of the delegated-proof-of-stake
func (*API) GetCandidate ¶
func (api *API) GetCandidate(addr common.Address, number *rpc.BlockNumber) (types.CandidateContext, error)
GetCandidates retrieves the list of the candidates at specified block
func (*API) GetCandidates ¶
func (api *API) GetCandidates(maxcnt, number *rpc.BlockNumber) ([]types.CandidateContext, error)
GetCandidates retrieves maxcnt result of the list of the candidates at specified block
func (*API) GetMintCnt ¶
GetMintCnt retrieves the mint cnt of the validator at specified block
func (*API) GetMintCnts ¶
func (api *API) GetMintCnts(maxcnt, number *rpc.BlockNumber) ([]types.MintCntAddress, error)
GetMintCnt retrieves maxcnt result of the mint cnt of all validators at specified block
func (*API) GetSortableAddresses ¶
func (api *API) GetSortableAddresses(number *rpc.BlockNumber) (types.SortableAddresses, error)
func (*API) GetValidators ¶
GetValidators retrieves the list of the validators at specified block
func (*API) GetVote ¶
func (api *API) GetVote(addr common.Address, number *rpc.BlockNumber) (map[string]types.VoteContext, error)
GetVote retrieves delegator to candidate at specified block
func (*API) GetVotes ¶
func (api *API) GetVotes(number *rpc.BlockNumber) (map[string]types.VoteContext, error)
GetVotes retrieves all delegator to their candidate at specified block
type DPOS ¶
type DPOS struct {
// contains filtered or unexported fields
}
dpos is the Delegated-Proof-of-Stake consensus engine
func New ¶
func New(config *params.DPOSConfig, db qctdb.Database) *DPOS
New creates a Delegated-Proof-of-Stake consensus engine with the initial signers set to the ones provided by the user.
func (*DPOS) APIs ¶
func (c *DPOS) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*DPOS) Author ¶
Author implements consensus.Engine, returning the Quickchain address recovered from the signature in the header's extra-data section.
func (*DPOS) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*DPOS) CalcDifficulty ¶
func (c *DPOS) 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 (*DPOS) Finalize ¶
func (c *DPOS) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, dposContext *types.DposContext) (*types.Block, error)
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*DPOS) JudgeTx ¶
func (c *DPOS) JudgeTx(chain consensus.ChainReader, header *types.Header, tx *types.Transaction, from common.Address) error
Judge the create contract Transaction from a no authorized account for dpos engine.
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 (c *DPOS) 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 (*DPOS) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*DPOS) VerifyHeaders ¶
func (c *DPOS) 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 (*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 EpochContext ¶
type EpochContext struct { TimeStamp int64 DposContext *types.DposContext Number uint64 `json:"number"` // Block number Hash common.Hash `json:"hash"` // Block hash Signers map[common.Address]struct{} `json:"signers"` // Set of authorized signers at this moment Recents map[uint64]common.Address `json:"recents"` // Set of recent signers for spam protections // contains filtered or unexported fields }
func (*EpochContext) CommitScores ¶
CommitScores commit candidate score into candidate tree in every epoch elec process