Documentation ¶
Index ¶
- func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int
- func FindAncientHeader(header *types.Header, ite uint64, chain consensus.ChainHeaderReader, ...) *types.Header
- type Consortium
- func (c *Consortium) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (c *Consortium) Author(header *types.Header) (common.Address, error)
- func (c *Consortium) Authorize(signer common.Address, signFn consortiumCommon.SignerFn, ...)
- func (c *Consortium) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (c *Consortium) Close() error
- func (c *Consortium) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) error
- func (c *Consortium) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, []*types.Receipt, error)
- func (c *Consortium) GetActiveValidatorAt(chain consensus.ChainHeaderReader, blockNumber uint64, blockHash common.Hash) []finality.ValidatorWithBlsPub
- func (c *Consortium) GetBestParentBlock(chain *core.BlockChain) (*types.Block, bool)
- func (c *Consortium) GetFinalizedBlock(chain consensus.ChainHeaderReader, headNumber uint64, headHash common.Hash) (uint64, common.Hash)
- func (c *Consortium) GetJustifiedBlock(chain consensus.ChainHeaderReader, blockNumber uint64, blockHash common.Hash) (uint64, common.Hash)
- func (c *Consortium) GetRecents(chain consensus.ChainHeaderReader, number uint64) map[uint64]common.Address
- func (c *Consortium) IsActiveValidatorAt(chain consensus.ChainHeaderReader, header *types.Header) bool
- func (c *Consortium) IsSystemContract(to *common.Address) bool
- func (c *Consortium) IsSystemMessage(msg core.Message, header *types.Header) bool
- func (c *Consortium) IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)
- func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *Consortium) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (c *Consortium) SealHash(header *types.Header) common.Hash
- func (c *Consortium) SetVotePool(votePool consensus.VotePool)
- func (c *Consortium) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (c *Consortium) VerifyHeaderAndParents(chain consensus.ChainHeaderReader, header *types.Header, ...) error
- func (c *Consortium) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *Consortium) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- func (c *Consortium) VerifyVote(chain consensus.ChainHeaderReader, vote *types.VoteEnvelope) error
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 validator.
func FindAncientHeader ¶
func FindAncientHeader(header *types.Header, ite uint64, chain consensus.ChainHeaderReader, candidateParents []*types.Header) *types.Header
FindAncientHeader finds the most recent checkpoint header Travel through the candidateParents to find the ancient header. If all headers in candidateParents have the number is larger than the header number, the search function will return the index, but it is not valid if we check with the header since the number and hash is not equals. The candidateParents is only available when it downloads blocks from the network. Otherwise, the candidateParents is nil, and it will be found by header hash and number.
Types ¶
type Consortium ¶
type Consortium struct {
// contains filtered or unexported fields
}
Consortium is the delegated proof-of-stake consensus engine proposed to support the Ronin to become more decentralized
func New ¶
func New( chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.PublicBlockChainAPI, genesisHash common.Hash, v1 consortiumCommon.ConsortiumAdapter, ) *Consortium
New creates a Consortium delegated proof-of-stake consensus engine
func (*Consortium) APIs ¶
func (c *Consortium) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs are backward compatible with the v1, so we do not to implement it again
func (*Consortium) Authorize ¶
func (c *Consortium) Authorize(signer common.Address, signFn consortiumCommon.SignerFn, signTxFn consortiumCommon.SignerTxFn)
Authorize injects a private key into the consensus engine to mint new blocks with
func (*Consortium) CalcDifficulty ¶
func (c *Consortium) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have: * DIFF_NOTURN(3) if (BLOCK_NUMBER + 1) / VALIDATOR_COUNT != VALIDATOR_INDEX * DIFF_INTURN(7) if (BLOCK_NUMBER + 1) / VALIDATOR_COUNT == VALIDATOR_INDEX
func (*Consortium) Close ¶
func (c *Consortium) Close() error
Close implements consensus.Engine. It's a noop for Consortium as there are no background threads.
func (*Consortium) Finalize ¶
func (c *Consortium) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt, systemTxs *[]*types.Transaction, internalTxs *[]*types.InternalTransaction, usedGas *uint64) error
Finalize implements consensus.Engine that calls three methods from smart contracts: - WrapUpEpoch at epoch to distribute rewards and sort the validators set - Slash the validator who does not sign if it is in-turn - SubmitBlockRewards of the current block
func (*Consortium) FinalizeAndAssemble ¶
func (c *Consortium) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, []*types.Receipt, error)
FinalizeAndAssemble implements consensus.Engine that calls three methods from smart contracts: - WrapUpEpoch at epoch to distribute rewards and sort the validators set - Slash the validator who does not sign if it is in-turn - SubmitBlockRewards of the current block
func (*Consortium) GetActiveValidatorAt ¶
func (c *Consortium) GetActiveValidatorAt( chain consensus.ChainHeaderReader, blockNumber uint64, blockHash common.Hash, ) []finality.ValidatorWithBlsPub
GetActiveValidatorAt gets the validator that can vote for block number (the vote is included in block number + 1), so get the snapshot at block number
func (*Consortium) GetBestParentBlock ¶
func (c *Consortium) GetBestParentBlock(chain *core.BlockChain) (*types.Block, bool)
GetBestParentBlock goes backward in the canonical chain to find if the miner can create a chain which has more difficulty than current chain. In case the miner cannot create a better chain, this function returns the head block of current canonical chain.
func (*Consortium) GetFinalizedBlock ¶
func (c *Consortium) GetFinalizedBlock( chain consensus.ChainHeaderReader, headNumber uint64, headHash common.Hash, ) (uint64, common.Hash)
GetFinalizedBlock gets the fast finality finalized block
func (*Consortium) GetJustifiedBlock ¶
func (c *Consortium) GetJustifiedBlock(chain consensus.ChainHeaderReader, blockNumber uint64, blockHash common.Hash) (uint64, common.Hash)
GetJustifiedBlock gets the fast finality justified block
func (*Consortium) GetRecents ¶
func (c *Consortium) GetRecents(chain consensus.ChainHeaderReader, number uint64) map[uint64]common.Address
GetRecents implements common.ConsortiumAdapter, always returning nil as this consensus mechanism doesn't need to get recents
func (*Consortium) IsActiveValidatorAt ¶
func (c *Consortium) IsActiveValidatorAt(chain consensus.ChainHeaderReader, header *types.Header) bool
IsActiveValidatorAt is used to check if we can vote for header.Number (the vote is included at header.Number + 1). As explained in assembleFinalityVote, the vote for header.Number is verified by the validator set at snapshot at block.Number. So here we get the snapshot at block.Number not at block.Number - 1
func (*Consortium) IsSystemContract ¶
func (c *Consortium) IsSystemContract(to *common.Address) bool
IsSystemContract implements consensus.PoSA, checking whether a contract is a system contract or not A system contract is a contract is defined in params.ConsortiumV2Contracts
func (*Consortium) IsSystemMessage ¶
IsSystemMessage implements consensus.PoSA, checking whether a transaction is a system transaction or not. A system transaction is a transaction that has the recipient of the contract address is defined in params.ConsortiumV2Contracts
func (*Consortium) IsSystemTransaction ¶
func (c *Consortium) IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)
In normal case, IsSystemTransaction in consortium/main.go is used instead of this function. This function is only used in testing when we create standalone consortium v2 engine without the v1
func (*Consortium) Prepare ¶
func (c *Consortium) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Consortium) Seal ¶
func (c *Consortium) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Consortium) SealHash ¶
func (c *Consortium) SealHash(header *types.Header) common.Hash
SealHash returns the hash of a block prior to it being sealed.
func (*Consortium) SetVotePool ¶
func (c *Consortium) SetVotePool(votePool consensus.VotePool)
SetVotePool sets the finality vote pool to be used by consensus engine
func (*Consortium) VerifyHeader ¶
func (c *Consortium) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Consortium) VerifyHeaderAndParents ¶
func (c *Consortium) VerifyHeaderAndParents(chain consensus.ChainHeaderReader, header *types.Header, parents []*types.Header) error
VerifyHeaderAndParents checks whether a header conforms to the consensus rules.The caller may optionally pass in a batch of parents (ascending order) to avoid looking those up from the database. This is useful for concurrently verifying a batch of new headers.
func (*Consortium) VerifyHeaders ¶
func (c *Consortium) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
VerifyHeaders implements consensus.Engine, always returning an empty abort and results channels. In normal case, VerifyHeaders in consortium/main.go is used instead of this function. This function is only used in testing when we create standalone consortium v2 engine without the v1
func (*Consortium) VerifyUncles ¶
func (c *Consortium) 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.
func (*Consortium) VerifyVote ¶
func (c *Consortium) VerifyVote(chain consensus.ChainHeaderReader, vote *types.VoteEnvelope) error
VerifyVote check if the finality voter is in the validator set, it assumes the signature is already verified
type Snapshot ¶
type Snapshot struct { Number uint64 `json:"number"` // Block number where the snapshot was created Hash common.Hash `json:"hash"` // Block hash where the snapshot was created Validators map[common.Address]struct{} `json:"validators,omitempty"` // Set of authorized validators at this moment before Shillin Recents map[uint64]common.Address `json:"recents"` // Set of recent validators for spam protections // Finality additional fields ValidatorsWithBlsPub []finality.ValidatorWithBlsPub `json:"validatorWithBlsPub,omitempty"` // Array of sorted authorized validators and BLS public keys after Shillin JustifiedBlockNumber uint64 `json:"justifiedBlockNumber,omitempty"` // The justified block number JustifiedBlockHash common.Hash `json:"justifiedBlockHash,omitempty"` // The justified block hash // contains filtered or unexported fields }
Snapshot is the state of the authorization validators at a given point in time.