dpos

package
v0.0.0-...-37c0745 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package dpos implements the Delegated-Proof-of-Stake consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	MinDelegateBalance  = big.NewFloat(10 * 1e18)  //10QCT
	MinCandidateBalance = big.NewFloat(100 * 1e18) //100QCT
	UnlockInterval      = big.NewInt(10)           //10 Block
)
View Source
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

func CalcDifficulty(epoch *EpochContext, signer common.Address, 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 SeedHash

func SeedHash(block uint64) []byte

SeedHash is the seed to use for generating a verification cache and the mining dataset.

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) GetCFDs

func (api *API) GetCFDs(number *rpc.BlockNumber) (map[string]map[string]*big.Int, error)

GetCFDs retrieves all candidates from their delegates at specified block

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

func (api *API) GetMintCnt(addr common.Address, number *rpc.BlockNumber) (int64, error)

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

func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)

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

func (c *DPOS) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Quickchain address recovered from the signature in the header's extra-data section.

func (*DPOS) Authorize

func (c *DPOS) Authorize(signer common.Address, signFn SignerFn)

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

func (c *DPOS) Prepare(chain consensus.ChainReader, header *types.Header) error

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

func (c *DPOS) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

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

func (c *DPOS) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*DPOS) VerifyUncles

func (c *DPOS) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

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

func (ec *EpochContext) CommitScores(scores map[common.Address]*big.Int) error

CommitScores commit candidate score into candidate tree in every epoch elec process

type SignerFn

type SignerFn func(accounts.Account, []byte) ([]byte, error)

SignerFn is a signer callback function to request a hash to be signed by a backing account.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL