Documentation ¶
Overview ¶
Package dpor implements the dpor consensus engine.
Index ¶
- Constants
- Variables
- func IsCheckPoint(number uint64, termLen uint64, viewLen uint64) bool
- type API
- type BroadcastBlockFn
- type Dpor
- func New(config *configs.DporConfig, db database.Database) *Dpor
- func NewDoNothingFaker(config *configs.DporConfig, db database.Database) *Dpor
- func NewFakeDelayer(config *configs.DporConfig, db database.Database, delay time.Duration) *Dpor
- func NewFakeFailer(config *configs.DporConfig, db database.Database, fail uint64) *Dpor
- func NewFaker(config *configs.DporConfig, db database.Database) *Dpor
- func (d *Dpor) APIs(chain consensus.ChainReader) []rpc.API
- func (d *Dpor) Author(header *types.Header) (common.Address, error)
- func (d *Dpor) Authorize(signer common.Address, signFn backend.SignFn)
- func (d *Dpor) BroadcastBlock(block *types.Block, prop bool)
- func (d *Dpor) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (d *Dpor) Client() backend.ClientBackend
- func (d *Dpor) Coinbase() common.Address
- func (d *Dpor) CreateImpeachBlock() (*types.Block, error)
- func (d *Dpor) CurrentSnap() *DporSnapshot
- func (d *Dpor) EcrecoverSigs(header *types.Header, state consensus.State) ([]common.Address, []types.DporSignature, error)
- func (d *Dpor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (d *Dpor) FutureTermOf(number uint64) uint64
- func (d *Dpor) GAPIs(chain consensus.ChainReader) []grpc.GApi
- func (d *Dpor) GetCalcRptInfo(address common.Address, blockNum uint64) int64
- func (d *Dpor) GetCurrentBlock() *types.Block
- func (d *Dpor) GetMac() (mac string, sig []byte, err error)
- func (d *Dpor) HandleMinedBlock(block *types.Block) error
- func (d *Dpor) HasBlockInChain(hash common.Hash, number uint64) bool
- func (d *Dpor) IfSigned(number uint64) (common.Hash, bool)
- func (d *Dpor) ImpeachTimeout() time.Duration
- func (d *Dpor) InsertChain(block *types.Block) error
- func (d *Dpor) IsMiner() bool
- func (d *Dpor) Mode() Mode
- func (d *Dpor) PbftStatus() *consensus.PbftStatus
- func (d *Dpor) PrepareBlock(chain consensus.ChainReader, header *types.Header) error
- func (d *Dpor) ProposersOf(number uint64) ([]common.Address, error)
- func (d *Dpor) ProposersOfTerm(term uint64) ([]common.Address, error)
- func (d *Dpor) Protocol() consensus.Protocol
- func (d *Dpor) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (d *Dpor) SetAsMiner(isMiner bool)
- func (d *Dpor) SetClient(client backend.ClientBackend)
- func (d *Dpor) SetCurrentSnap(snap *DporSnapshot)
- func (d *Dpor) SetHandler(handler *backend.Handler) error
- func (d *Dpor) SignHash(hash []byte) ([]byte, error)
- func (d *Dpor) SignHeader(header *types.Header, state consensus.State) error
- func (d *Dpor) StartMining(blockchain consensus.ChainReadWriter, server *p2p.Server, ...)
- func (d *Dpor) State() consensus.State
- func (d *Dpor) Status() *consensus.PbftStatus
- func (d *Dpor) StatusUpdate() error
- func (d *Dpor) StopMining()
- func (d *Dpor) TermOf(number uint64) uint64
- func (d *Dpor) UpdateFinalSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)
- func (d *Dpor) UpdatePrepareSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)
- func (d *Dpor) ValidateBlock(block *types.Block, verifySigs bool, verifyProposers bool) error
- func (d *Dpor) ValidatorsOf(number uint64) ([]common.Address, error)
- func (d *Dpor) ValidatorsOfTerm(term uint64) ([]common.Address, error)
- func (d *Dpor) VerifyHeader(chain consensus.ChainReader, header *types.Header, verifySigs bool, ...) error
- func (d *Dpor) VerifyHeaderWithState(header *types.Header, state consensus.State) error
- func (d *Dpor) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, verifySigs []bool, ...) (chan<- struct{}, <-chan error)
- func (d *Dpor) VerifyProposerOf(signer common.Address, term uint64) (bool, error)
- func (d *Dpor) VerifySeal(chain consensus.ChainReader, header *types.Header, refHeader *types.Header) error
- func (d *Dpor) VerifySigs(chain consensus.ChainReader, header *types.Header, refHeader *types.Header) error
- func (d *Dpor) VerifyValidatorOf(signer common.Address, term uint64) (bool, error)
- type DporSnapshot
- func (s *DporSnapshot) FutureProposerViewOf(signer common.Address, number uint64) (int, error)
- func (s *DporSnapshot) FutureProposersOf(number uint64) []common.Address
- func (s *DporSnapshot) FutureSignerViewOf(signer common.Address, number uint64) (int, error)
- func (s *DporSnapshot) FutureSignersOf(number uint64) []common.Address
- func (s *DporSnapshot) FutureTermOf(blockNum uint64) uint64
- func (s *DporSnapshot) InturnOf(number uint64, signer common.Address) bool
- func (s *DporSnapshot) IsFutureProposerOf(proposer common.Address, number uint64) bool
- func (s *DporSnapshot) IsFutureSignerOf(signer common.Address, number uint64) bool
- func (s *DporSnapshot) IsProposerOf(signer common.Address, number uint64) (bool, error)
- func (s *DporSnapshot) IsValidatorOf(validator common.Address, number uint64) bool
- func (s *DporSnapshot) ProposerViewOf(proposer common.Address, number uint64) (int, error)
- func (s *DporSnapshot) ProposersOf(number uint64) []common.Address
- func (s *DporSnapshot) StartBlockNumberOfTerm(term uint64) uint64
- func (s *DporSnapshot) Term() uint64
- func (s *DporSnapshot) TermOf(blockNum uint64) uint64
- func (s *DporSnapshot) ValidatorViewOf(validator common.Address, number uint64) (int, error)
- func (s *DporSnapshot) ValidatorsOf(number uint64) []common.Address
- type Mode
- type Signatures
Constants ¶
const ( // TermDistBetweenElectionAndMining is the the term gap between election and mining. TermDistBetweenElectionAndMining = 2 // TermDistBetweenElectionAndMining = effective term - current term(last block) // MaxSizeOfRecentSigners is the size of the RecentSigners. // TODO: @shiyc MaxSizeOfRecentSigners is about to be removed later //MaxSizeOfRecentValidators is the size of the RecentValidators //MaxSizeOfRecentProposers is the size of the RecentProposers MaxSizeOfRecentSigners = 200 MaxSizeOfRecentValidators = 200 MaxSizeOfRecentProposers = 200 )
Variables ¶
var (
DporDifficulty = big.NewInt(1) // Block difficulty for out-of-turn signatures
)
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 ¶
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 proof-of-authority scheme.
func (*API) GetSnapshot ¶
func (api *API) GetSnapshot(number rpc.BlockNumber) (*DporSnapshot, error)
GetSnapshot retrieves the state Snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
func (api *API) GetSnapshotAtHash(hash common.Hash) (*DporSnapshot, error)
GetSnapshotAtHash retrieves the state Snapshot at a given block.
type BroadcastBlockFn ¶
BroadcastBlockFn broadcasts a block to normal peers(not pbft replicas)
type Dpor ¶
type Dpor struct {
// contains filtered or unexported fields
}
Dpor is the proof-of-reputation consensus engine proposed to support the cpchain testnet.
func New ¶
func New(config *configs.DporConfig, db database.Database) *Dpor
New creates a Dpor proof-of-reputation consensus engine with the initial signers set to the ones provided by the user.
func NewDoNothingFaker ¶
func NewDoNothingFaker(config *configs.DporConfig, db database.Database) *Dpor
func NewFakeDelayer ¶
func NewFakeFailer ¶
func (*Dpor) APIs ¶
func (d *Dpor) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*Dpor) Author ¶
Author implements consensus.Engine, returning the cpchain address recovered from the signature in the header's extra-data section.
func (*Dpor) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Dpor) BroadcastBlock ¶
BroadcastBlock broadcasts a block to normal peers(not pbft replicas)
func (*Dpor) CalcDifficulty ¶
func (d *Dpor) 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 (*Dpor) Client ¶
func (d *Dpor) Client() backend.ClientBackend
func (*Dpor) CreateImpeachBlock ¶
CreateImpeachBlock creates an impeachment block
func (*Dpor) CurrentSnap ¶
func (d *Dpor) CurrentSnap() *DporSnapshot
CurrentSnap returns current dpor snapshot
func (*Dpor) EcrecoverSigs ¶
func (d *Dpor) EcrecoverSigs(header *types.Header, state consensus.State) ([]common.Address, []types.DporSignature, error)
EcrecoverSigs recovers signer address and corresponding signature, it ignores empty signature and return empty addresses if one of the sigs are illegal
func (*Dpor) Finalize ¶
func (d *Dpor) 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 (*Dpor) FutureTermOf ¶
FutureTermOf returns the future term number of given block number
func (*Dpor) GAPIs ¶
func (d *Dpor) GAPIs(chain consensus.ChainReader) []grpc.GApi
GAPIs is APIs for dpor.
func (*Dpor) GetCalcRptInfo ¶
GetCalcRptInfo get the rpt value of an address at specific block number
func (*Dpor) GetCurrentBlock ¶
GetCurrentBlock returns current block
func (*Dpor) HandleMinedBlock ¶
HandleMinedBlock receives a block to add to handler's pending block channel
func (*Dpor) HasBlockInChain ¶
HasBlockInChain returns if a block is in local chain
func (*Dpor) ImpeachTimeout ¶
ImpeachTimeout returns impeach time out
func (*Dpor) InsertChain ¶
InsertChain inserts a block to chain
func (*Dpor) PbftStatus ¶
func (d *Dpor) PbftStatus() *consensus.PbftStatus
PbftStatus returns current state of dpor
func (*Dpor) PrepareBlock ¶
PrepareBlock implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Dpor) ProposersOfTerm ¶
func (*Dpor) Seal ¶
func (d *Dpor) 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. NB please populate the correct field values. we are now removing some fields such as nonce.
func (*Dpor) SetAsMiner ¶
func (*Dpor) SetClient ¶
func (d *Dpor) SetClient(client backend.ClientBackend)
func (*Dpor) SetCurrentSnap ¶
func (d *Dpor) SetCurrentSnap(snap *DporSnapshot)
SetCurrentSnap sets current dpor snapshot
func (*Dpor) SetHandler ¶
SetHandler sets dpor.handler
func (*Dpor) SignHeader ¶
SignHeader signs the header and adds all known sigs to header
func (*Dpor) StartMining ¶
func (d *Dpor) StartMining(blockchain consensus.ChainReadWriter, server *p2p.Server, pmBroadcastBlockFn BroadcastBlockFn)
StartMining starts to create a handler and start it.
func (*Dpor) Status ¶
func (d *Dpor) Status() *consensus.PbftStatus
Status returns a pbft replica's status
func (*Dpor) UpdateFinalSigsCache ¶
func (d *Dpor) UpdateFinalSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)
Update the signature to final signature cache(two kinds of sigs, one for prepared, another for final)
func (*Dpor) UpdatePrepareSigsCache ¶
func (d *Dpor) UpdatePrepareSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)
Update the signature to prepare signature cache(two kinds of sigs, one for prepared, another for final)
func (*Dpor) ValidateBlock ¶
ValidateBlock validates a basic field excepts seal of a block.
func (*Dpor) ValidatorsOfTerm ¶
func (*Dpor) VerifyHeader ¶
func (d *Dpor) VerifyHeader(chain consensus.ChainReader, header *types.Header, verifySigs bool, refHeader *types.Header) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Dpor) VerifyHeaderWithState ¶
VerifyHeaderWithState verifies the given header if in preprepared state, verify basic fields if in prepared state, verify if enough prepare sigs if in committed state, verify if enough commit sigs
func (*Dpor) VerifyHeaders ¶
func (d *Dpor) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, verifySigs []bool, refHeaders []*types.Header) (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 (*Dpor) VerifyProposerOf ¶
VerifyProposerOf verifies if an address is a proposer of given term
func (*Dpor) VerifySeal ¶
func (d *Dpor) VerifySeal(chain consensus.ChainReader, header *types.Header, refHeader *types.Header) error
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Dpor) VerifySigs ¶
func (d *Dpor) VerifySigs(chain consensus.ChainReader, header *types.Header, refHeader *types.Header) error
VerifySigs checks if header has enough signatures of validators.
type DporSnapshot ¶
type DporSnapshot struct { Mode Mode `json:"mode"` Number uint64 `json:"number"` // Block number where the Snapshot was created Hash common.Hash `json:"hash"` // Block hash where the Snapshot was created Candidates []common.Address `json:"candidates"` // Set of candidates read from campaign contract // RecentSigners *lru.ARCCache `json:"signers"` RecentSigners map[uint64][]common.Address `json:"signers"` // Set of recent signers RecentProposers map[uint64][]common.Address `json:"proposers"` // Set of recent proposers RecentValidators map[uint64][]common.Address `json:"validators"` // Set of recent validators Client backend.ClientBackend `json:"-"` // contains filtered or unexported fields }
DporSnapshot is the state of the authorization voting at a given point in time.
func (*DporSnapshot) FutureProposerViewOf ¶
FutureProposerViewOf returns the future signer view with given signer address and block number
func (*DporSnapshot) FutureProposersOf ¶
func (s *DporSnapshot) FutureProposersOf(number uint64) []common.Address
FutureProposersOf returns future proposers of given block number
func (*DporSnapshot) FutureSignerViewOf ¶
FutureSignerViewOf returns the future signer view with given signer address and block number TODO: @shiyc need to remove it later
func (*DporSnapshot) FutureSignersOf ¶
func (s *DporSnapshot) FutureSignersOf(number uint64) []common.Address
FutureSignersOf returns future signers of given block number
func (*DporSnapshot) FutureTermOf ¶
func (s *DporSnapshot) FutureTermOf(blockNum uint64) uint64
FutureTermOf returns future term idx with given block number
func (*DporSnapshot) InturnOf ¶
func (s *DporSnapshot) InturnOf(number uint64, signer common.Address) bool
InturnOf returns if a signer at a given block height is in-turn or not
func (*DporSnapshot) IsFutureProposerOf ¶
func (s *DporSnapshot) IsFutureProposerOf(proposer common.Address, number uint64) bool
IsFutureProposerOf returns if an address is a future proposer in the given block number
func (*DporSnapshot) IsFutureSignerOf ¶
func (s *DporSnapshot) IsFutureSignerOf(signer common.Address, number uint64) bool
IsFutureSignerOf returns if an address is a future signer in the given block number TODO: @shiyc need to remove it later
func (*DporSnapshot) IsProposerOf ¶
IsProposerOf returns if an address is a proposer in the given block number
func (*DporSnapshot) IsValidatorOf ¶
func (s *DporSnapshot) IsValidatorOf(validator common.Address, number uint64) bool
IsValidatorOf returns if an address is a validator in the given block number
func (*DporSnapshot) ProposerViewOf ¶
ProposerViewOf returns the proposer's view(turn) with given proposer's address and block number
func (*DporSnapshot) ProposersOf ¶
func (s *DporSnapshot) ProposersOf(number uint64) []common.Address
func (*DporSnapshot) StartBlockNumberOfTerm ¶
func (s *DporSnapshot) StartBlockNumberOfTerm(term uint64) uint64
func (*DporSnapshot) Term ¶
func (s *DporSnapshot) Term() uint64
Term returns the term index of current block number, which is 0-based
func (*DporSnapshot) TermOf ¶
func (s *DporSnapshot) TermOf(blockNum uint64) uint64
TermOf returns the term index of given block number
func (*DporSnapshot) ValidatorViewOf ¶
ValidatorViewOf returns validator's view with given validator's address and block number
func (*DporSnapshot) ValidatorsOf ¶
func (s *DporSnapshot) ValidatorsOf(number uint64) []common.Address
type Signatures ¶
type Signatures struct {
// contains filtered or unexported fields
}
Signatures stores sigs in a block