Documentation ¶
Overview ¶
Package backend implements the Delegated-Proof-of-Stake consensus engine.
Index ¶
- Variables
- func CalcDifficulty(epoch *EpochContext, signer common.Address, parent *types.Header) *big.Int
- func New(config *bft.Config, privateKey *ecdsa.PrivateKey, db qctdb.Database) consensus.DBFT
- func SeedHash(block uint64) []byte
- type API
- func (api *API) Candidates() map[common.Address]bool
- func (api *API) Discard(address common.Address)
- func (api *API) GetCFDs(number *rpc.BlockNumber) (map[string]map[string]*big.Int, error)
- func (api *API) GetDposCandidate(addr common.Address, number *rpc.BlockNumber) (types.CandidateContext, error)
- func (api *API) GetDposCandidates(maxcnt, number *rpc.BlockNumber) ([]types.CandidateContext, error)
- func (api *API) GetDposValidators(number *rpc.BlockNumber) ([]common.Address, 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) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) GetSortableAddresses(number *rpc.BlockNumber) (types.SortableAddresses, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetValidatorsAtHash(hash common.Hash) ([]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)
- func (api *API) Propose(address common.Address, auth bool)
- 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) DB() qctdb.Database
- 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
- type Snapshot
- type Tally
- type Vote
Constants ¶
This section is empty.
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") 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") )
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 ( MinDelegateBalance = big.NewFloat(10 * 1e18) //10QCT MinCandidateBalance = big.NewFloat(100 * 1e18) //100QCT UnlockInterval = big.NewInt(10) //10 Block )
var ( ErrMismatchSignerAndValidator = errors.New("mismatch block signer and validator") ErrNilBlockHeader = errors.New("nil block header returned") )
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 dump BFT state
func (*API) Candidates ¶
Candidates returns the current candidates the node tries to uphold and vote on.
func (*API) Discard ¶
Discard drops a currently running candidate, stopping the validator from casting further votes (either for or against).
func (*API) GetDposCandidate ¶
func (api *API) GetDposCandidate(addr common.Address, number *rpc.BlockNumber) (types.CandidateContext, error)
GetDposCandidates retrieves the list of the candidates at specified block
func (*API) GetDposCandidates ¶
func (api *API) GetDposCandidates(maxcnt, number *rpc.BlockNumber) ([]types.CandidateContext, error)
GetCandidates retrieves maxcnt result of the list of the candidates at specified block
func (*API) GetDposValidators ¶
copy from dpos.api GetDposValidators retrieves the list of the validators 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) 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) GetSortableAddresses ¶
func (api *API) GetSortableAddresses(number *rpc.BlockNumber) (types.SortableAddresses, error)
func (*API) GetValidators ¶
GetValidators retrieves the list of authorized validators at the specified block.
func (*API) GetValidatorsAtHash ¶
GetValidatorsAtHash retrieves the state snapshot at a given 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 NewDPOS ¶
func NewDPOS(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
type SignerFn ¶
SignerFn is a signer callback function to request a hash to be signed by a backing account.
type Snapshot ¶
type Snapshot struct { Epoch uint64 // The number of blocks after which to checkpoint and reset the pending votes Number uint64 // Block number where the snapshot was created Hash common.Hash // Block hash where the snapshot was created Votes []*Vote // List of votes cast in chronological order Tally map[common.Address]Tally // Current vote tally to avoid recalculating ValSet bft.ValidatorSet // Set of authorized validators at this moment DposContext *types.DposContext StateDB *state.StateDB }
Snapshot is the state of the authorization voting at a given point in time.
func (*Snapshot) CommitScores ¶
CommitScores commit candidate score into candidate tree in every epoch elec process
func (*Snapshot) MarshalJSON ¶
Marshal to a json byte array
func (*Snapshot) UnmarshalJSON ¶
Unmarshal from a json byte array
type Tally ¶
type Tally struct { Authorize bool `json:"authorize"` // Whether the vote it about authorizing or kicking someone Votes int `json:"votes"` // Number of votes until now wanting to pass the proposal }
Tally is a simple vote tally to keep the current score of votes. Votes that go against the proposal aren't counted since it's equivalent to not voting.
type Vote ¶
type Vote struct { Validator common.Address `json:"validator"` // Authorized validator that cast this vote Block uint64 `json:"block"` // Block number the vote was cast in (expire old votes) Address common.Address `json:"address"` // Account being voted on to change its authorization Authorize bool `json:"authorize"` // Whether to authorize or deauthorize the voted account }
Vote represents a single vote that an authorized validator made to modify the list of authorizations.