Documentation ¶
Index ¶
- Variables
- func CheckValidatorSignature(valSet ValidatorSet, data []byte, sig []byte) (common.Address, error)
- func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)
- func GetSignatureAddressNoHashing(data []byte, sig []byte) (common.Address, error)
- func RLPHash(v interface{}) (h common.Hash)
- type Backend
- type Config
- func (c Config) Get2FPlus1Enabled(blockNumber *big.Int) bool
- func (c Config) GetConfig(blockNumber *big.Int) Config
- func (c Config) GetValidatorContractAddress(blockNumber *big.Int) common.Address
- func (c Config) GetValidatorSelectionMode(blockNumber *big.Int) string
- func (c Config) GetValidatorsAt(blockNumber *big.Int) []common.Address
- func (c *Config) IsQBFTConsensusAt(blockNumber *big.Int) bool
- func (c Config) QBFTBlockNumber() int64
- type Core
- type Engine
- type FinalCommittedEvent
- type MessageEvent
- type Preprepare
- type Proposal
- type ProposalSelector
- type ProposerPolicy
- type ProposerPolicyId
- type Request
- type RequestEvent
- type Subject
- type Validator
- type ValidatorSet
- type ValidatorSortByFunc
- type Validators
- type View
Constants ¶
This section is empty.
Variables ¶
var ( // current validator set. ErrUnauthorizedAddress = errors.New("unauthorized address") // ErrStoppedEngine is returned if the engine is stopped ErrStoppedEngine = errors.New("stopped engine") // ErrStartedEngine is returned if the engine is already started ErrStartedEngine = errors.New("started engine") )
var DefaultConfig = &Config{ RequestTimeout: 10000, BlockPeriod: 5, EmptyBlockPeriod: 0, ProposerPolicy: NewRoundRobinProposerPolicy(), Epoch: 30000, Ceil2Nby3Block: big.NewInt(0), AllowedFutureBlockTime: 0, TestQBFTBlock: big.NewInt(0), }
Functions ¶
func CheckValidatorSignature ¶
func GetSignatureAddress ¶
GetSignatureAddress gets the signer address from the signature
func GetSignatureAddressNoHashing ¶
GetSignatureAddressNoHashing gets the signer address from the signature without first hashing the data
Types ¶
type Backend ¶
type Backend interface { // Address returns the owner's address Address() common.Address // Validators returns the validator set Validators(proposal Proposal) ValidatorSet // EventMux returns the event mux in backend EventMux() *event.TypeMux // Broadcast sends a message to all validators (include self) Broadcast(valSet ValidatorSet, code uint64, payload []byte) error // Gossip sends a message to all validators (exclude self) Gossip(valSet ValidatorSet, code uint64, payload []byte) error // Commit delivers an approved proposal to backend. // The delivered proposal will be put into blockchain. Commit(proposal Proposal, seals [][]byte, round *big.Int) error // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, // the time difference of the proposal and current time is also returned. Verify(Proposal) (time.Duration, error) // Sign signs input data with the backend's private key Sign([]byte) ([]byte, error) // SignWithoutHashing sign input data with the backend's private key without hashing the input data SignWithoutHashing([]byte) ([]byte, error) // CheckSignature verifies the signature by checking if it's signed by // the given validator CheckSignature(data []byte, addr common.Address, sig []byte) error // LastProposal retrieves latest committed proposal and the address of proposer LastProposal() (Proposal, common.Address) // HasPropsal checks if the combination of the given hash and height matches any existing blocks HasPropsal(hash common.Hash, number *big.Int) bool // GetProposer returns the proposer of the given block height GetProposer(number uint64) common.Address // ParentValidators returns the validator set of the given proposal's parent block ParentValidators(proposal Proposal) ValidatorSet // HasBadProposal returns whether the block with the hash is a bad block HasBadProposal(hash common.Hash) bool Close() error // IsQBFTConsensus checks qbftBlock fork block and returns if it should be enabled IsQBFTConsensusAt(*big.Int) bool // StartQBFTConsensus stops existing legacy ibft consensus and starts the new qbft consensus StartQBFTConsensus() error }
Backend provides application specific functions for Istanbul core
type Config ¶
type Config struct { RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds. BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second EmptyBlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between a block and empty block's timestamps in second ProposerPolicy *ProposerPolicy `toml:",omitempty"` // The policy for proposer selection Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes Ceil2Nby3Block *big.Int `toml:",omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)] AllowedFutureBlockTime uint64 `toml:",omitempty"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks TestQBFTBlock *big.Int `toml:",omitempty"` // Fork block at which block confirmations are done using qbft consensus instead of ibft BeneficiaryMode *string `toml:",omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators) BlockReward *math.HexOrDecimal256 `toml:",omitempty"` // Reward MiningBeneficiary *common.Address `toml:",omitempty"` // Wallet address that benefits at every new block (besu mode) ValidatorContract common.Address `toml:",omitempty"` Validators []common.Address `toml:",omitempty"` ValidatorSelectionMode *string `toml:",omitempty"` Client bind.ContractCaller `toml:",omitempty"` Transitions []params.Transition }
func (Config) GetValidatorContractAddress ¶
func (Config) GetValidatorSelectionMode ¶
func (Config) GetValidatorsAt ¶
func (*Config) IsQBFTConsensusAt ¶
IsQBFTConsensusAt checks if qbft consensus is enabled for the block height identified by the given header
func (Config) QBFTBlockNumber ¶
QBFTBlockNumber returns the qbftBlock fork block number, returns -1 if qbftBlock is not defined
type Core ¶
type Core interface { Start() error Stop() error IsProposer() bool // verify if a hash is the same as the proposed block in the current pending request // // this is useful when the engine is currently the proposer // // pending request is populated right at the preprepare stage so this would give us the earliest verification // to avoid any race condition of coming propagated blocks IsCurrentProposal(blockHash common.Hash) bool }
type Engine ¶
type Engine interface { Address() common.Address Author(header *types.Header) (common.Address, error) ExtractGenesisValidators(header *types.Header) ([]common.Address, error) Signers(header *types.Header) ([]common.Address, error) CommitHeader(header *types.Header, seals [][]byte, round *big.Int) error VerifyBlockProposal(chain consensus.ChainHeaderReader, block *types.Block, validators ValidatorSet) (time.Duration, error) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parents []*types.Header, validators ValidatorSet) error VerifyUncles(chain consensus.ChainReader, block *types.Block) error VerifySeal(chain consensus.ChainHeaderReader, header *types.Header, validators ValidatorSet) error Prepare(chain consensus.ChainHeaderReader, header *types.Header, validators ValidatorSet) error Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) Seal(chain consensus.ChainHeaderReader, block *types.Block, validators ValidatorSet) (*types.Block, error) SealHash(header *types.Header) common.Hash CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int WriteVote(header *types.Header, candidate common.Address, authorize bool) error ReadVote(header *types.Header) (candidate common.Address, authorize bool, err error) }
type FinalCommittedEvent ¶
type FinalCommittedEvent struct { }
FinalCommittedEvent is posted when a proposal is committed
type MessageEvent ¶
MessageEvent is posted for Istanbul engine communication
type Preprepare ¶
type Proposal ¶
type Proposal interface { // Number retrieves the sequence number of this proposal. Number() *big.Int // Hash retrieves the hash of this proposal. Hash() common.Hash EncodeRLP(w io.Writer) error DecodeRLP(s *rlp.Stream) error }
Proposal supports retrieving height and serialized block to be used during Istanbul consensus.
type ProposalSelector ¶
type ProposalSelector func(ValidatorSet, common.Address, uint64) Validator
type ProposerPolicy ¶
type ProposerPolicy struct { Id ProposerPolicyId // Could be RoundRobin or Sticky By ValidatorSortByFunc // func that defines how the ValidatorSet should be sorted // contains filtered or unexported fields }
ProposerPolicy represents the Validator Proposer Policy
func NewProposerPolicy ¶
func NewProposerPolicy(id ProposerPolicyId) *ProposerPolicy
func NewProposerPolicyByIdAndSortFunc ¶
func NewProposerPolicyByIdAndSortFunc(id ProposerPolicyId, by ValidatorSortByFunc) *ProposerPolicy
func NewRoundRobinProposerPolicy ¶
func NewRoundRobinProposerPolicy() *ProposerPolicy
NewRoundRobinProposerPolicy returns a RoundRobin ProposerPolicy with ValidatorSortByString as default sort function
func NewStickyProposerPolicy ¶
func NewStickyProposerPolicy() *ProposerPolicy
NewStickyProposerPolicy return a Sticky ProposerPolicy with ValidatorSortByString as default sort function
func (*ProposerPolicy) ClearRegistry ¶
func (p *ProposerPolicy) ClearRegistry()
ClearRegistry removes any ValidatorSet from the ProposerPolicy registry
func (*ProposerPolicy) MarshalTOML ¶
func (p *ProposerPolicy) MarshalTOML() (interface{}, error)
func (*ProposerPolicy) RegisterValidatorSet ¶
func (p *ProposerPolicy) RegisterValidatorSet(valSet ValidatorSet)
RegisterValidatorSet stores the given ValidatorSet in the policy registry
func (*ProposerPolicy) UnmarshalTOML ¶
func (p *ProposerPolicy) UnmarshalTOML(decode func(interface{}) error) error
func (*ProposerPolicy) Use ¶
func (p *ProposerPolicy) Use(v ValidatorSortByFunc)
Use sets the ValidatorSortByFunc for the given ProposerPolicy and sorts the validatorSets according to it
type ProposerPolicyId ¶
type ProposerPolicyId uint64
const ( RoundRobin ProposerPolicyId = iota Sticky )
type RequestEvent ¶
type RequestEvent struct {
Proposal Proposal
}
RequestEvent is posted to propose a proposal
type Subject ¶
func (*Subject) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.
type ValidatorSet ¶
type ValidatorSet interface { // Calculate the proposer CalcProposer(lastProposer common.Address, round uint64) // Return the validator size Size() int // Return the validator array List() []Validator // Get validator by index GetByIndex(i uint64) Validator // Get validator by given address GetByAddress(addr common.Address) (int, Validator) // Get current proposer GetProposer() Validator // Check whether the validator with given address is a proposer IsProposer(address common.Address) bool // Add validator AddValidator(address common.Address) bool // Remove validator RemoveValidator(address common.Address) bool // Copy validator set Copy() ValidatorSet // Get the maximum number of faulty nodes F() int // Get proposer policy Policy() ProposerPolicy // SortValidators sorts the validators based on the configured By function SortValidators() }
type ValidatorSortByFunc ¶
func ValidatorSortByByte ¶
func ValidatorSortByByte() ValidatorSortByFunc
func ValidatorSortByString ¶
func ValidatorSortByString() ValidatorSortByFunc
func (ValidatorSortByFunc) Sort ¶
func (by ValidatorSortByFunc) Sort(validators []Validator)
type Validators ¶
type Validators []Validator
type View ¶
View includes a round number and a sequence number. Sequence is the block number we'd like to commit. Each round has a number and is composed by 3 steps: preprepare, prepare and commit.
If the given block is not accepted by validators, a round change will occur and the validators start a new round with round+1.
func (*View) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.