Documentation
¶
Overview ¶
Package poc implements the delegated-proof-of-stake consensus engine.
Index ¶
- Variables
- type API
- type CandidateSlice
- type Declare
- type HeaderExtra
- type Join
- type PoC
- func (a *PoC) APIs(chain consensus.ChainReader) []rpc.API
- func (a *PoC) ApplyGenesis(chain consensus.ChainReader, genesisHash common.Hash) error
- func (a *PoC) Author(header *types.Header) (common.Address, error)
- func (a *PoC) Authorize(signer common.Address, signFn SignerFn, signTxFn SignTxFn)
- func (a *PoC) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (a *PoC) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (a *PoC) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (a *PoC) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (a *PoC) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (a *PoC) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (a *PoC) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (a *PoC) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Proposal
- type RefundGas
- type RefundHash
- type RefundPair
- type ScoreItem
- type SignTxFn
- type SignerFn
- type Snapshot
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") )
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
}
API is a user facing RPC API to allow controlling the signer and voting mechanisms of the delegated-proof-of-stake scheme.
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.
type CandidateSlice ¶
type CandidateSlice []ScoreItem
func (CandidateSlice) Len ¶
func (s CandidateSlice) Len() int
func (CandidateSlice) Less ¶
func (s CandidateSlice) Less(i, j int) bool
func (CandidateSlice) Swap ¶
func (s CandidateSlice) Swap(i, j int)
type Declare ¶
Declare : declare come from custom tx which data like "ufo:1:event:declare:hash:yes" proposal only come from the current candidates hash is the hash of proposal tx
type HeaderExtra ¶
type HeaderExtra struct { CurrentBlockProposals []Proposal CurrentBlockDeclares []Declare CurrentBlockJoin []Join }
HeaderExtra is the struct of info in header.Extra[extraVanity:len(header.extra)-extraSeal] HeaderExtra is the current struct
type PoC ¶
type PoC struct {
// contains filtered or unexported fields
}
PoC is the delegated-proof-of-stake consensus engine.
func New ¶
New creates a PoC delegated-proof-of-stake consensus engine with the initial signers set to the ones provided by the user.
func (*PoC) APIs ¶
func (a *PoC) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*PoC) ApplyGenesis ¶
ApplyGenesis
func (*PoC) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*PoC) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*PoC) CalcDifficulty ¶
func (a *PoC) 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 (*PoC) Finalize ¶
func (a *PoC) 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 (*PoC) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*PoC) Seal ¶
func (a *PoC) 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 (*PoC) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*PoC) VerifyHeaders ¶
func (a *PoC) 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 (*PoC) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*PoC) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
type Proposal ¶
type Proposal struct { Hash common.Hash // tx hash ReceivedNumber *big.Int // block number of proposal received CurrentDeposit *big.Int // received deposit for this proposal ValidationLoopCnt uint64 // validation block number length of this proposal from the received block number ProposalType uint64 // type of proposal 1 - add candidate 2 - remove candidate ... Proposer common.Address // proposer TargetAddress common.Address // candidate need to add/remove if candidateNeedPD == true MinerRewardPerThousand uint64 // reward of miner + side chain miner Declares []*Declare // Declare this proposal received (always empty in block header) MinVoterBalance uint64 // value of minVoterBalance , need to mul big.Int(1e+18) ProposalDeposit uint64 // The deposit need to be frozen during before the proposal get final conclusion. (TTC) }
Proposal : proposal come from custom tx which data like "ufo:1:event:proposal:candidate:add:address" or "ufo:1:event:proposal:percentage:60" proposal only come from the current candidates not only candidate add/remove , current signer can proposal for params modify like percentage of reward distribution ...
type SignTxFn ¶
type SignTxFn func(accounts.Account, *types.Transaction, *big.Int) (*types.Transaction, error)
SignTxFn is a signTx
type SignerFn ¶
SignerFn is a signer callback function to request a hash to be signed by a backing account.
type Snapshot ¶
type Snapshot struct { LCRS uint64 // Loop count to recreate signers from top tally CurrentEpoch uint64 `json:"currentEpoch"` Period uint64 `json:"period"` // Period of seal each block Number uint64 `json:"number"` // Block number where the snapshot was created ConfirmedNumber uint64 `json:"confirmedNumber"` // Block number confirmed when the snapshot was created Hash common.Hash `json:"hash"` // Block hash where the snapshot was created Validators []common.Address `json:"validators"` // Signers queue in current header Candidates map[common.Address]*big.Int `json:"candidates"` // Candidates for Signers (0- adding procedure 1- normal 2- removing procedure) MintCount map[common.Address]uint64 `json:"mintCount"` // Punished map[common.Address]uint64 `json:"punished"` // The signer be punished count cause of missing seal Proposals map[common.Hash]*Proposal `json:"proposals"` // The Proposals going or success (failed proposal will be removed) HeaderTime uint64 `json:"headerTime"` // Time of the current header LoopStartTime uint64 `json:"loopStartTime"` // Start Time of the current loop ProposalRefund map[uint64]map[common.Address]*big.Int `json:"proposalRefund"` // Refund proposal deposit MinerReward uint64 `json:"minerReward"` // miner reward per thousand MinContribution *big.Int `json:"minVoterBalance"` // min voter balance // contains filtered or unexported fields }
Snapshot is the state of the authorization voting at a given point in time.