Documentation ¶
Index ¶
- Constants
- Variables
- func CheckVerifierSignature(verSet VerifierSet, data []byte, sig []byte) (common.Address, error)
- func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)
- func RLPHash(v interface{}) (hash common.Hash)
- type BFTConfig
- type FinalCommittedEvent
- type MessageEvent
- type Preprepare
- type Proposal
- type ProposalSelector
- type ProposerPolicy
- type Request
- type RequestEvent
- type Server
- type Subject
- type Verifier
- type VerifierSet
- type Verifiers
- type View
Constants ¶
View Source
const WitnessSize = 8
Variables ¶
View Source
var ( // current validator set. ErrAddressUnauthorized = errors.New("unauthorized address") // ErrEngineStopped is returned if the engine is stopped ErrEngineStopped = errors.New("stopped engine") // ErrEngineStarted is returned if the engine is already started ErrEngineStarted = errors.New("started engine") )
View Source
var DefaultConfig = &BFTConfig{ RequestTimeout: 10000, BlockPeriod: common.BFTBlockInterval, ProposerPolicy: RoundRobin, Epoch: common.CheckInterval, }
Functions ¶
func CheckVerifierSignature ¶
CheckVerifierSignature check the validator in or not in the verset by signature
func GetSignatureAddress ¶
GetSignatureAddress gets the signer address from the signature
Types ¶
type BFTConfig ¶
type BFTConfig struct { RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Bft round in milliseconds. BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive 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 }
type FinalCommittedEvent ¶
type FinalCommittedEvent struct { }
type MessageEvent ¶
type MessageEvent struct {
Payload []byte
}
type Preprepare ¶
type ProposalSelector ¶
type ProposalSelector func(VerifierSet, common.Address, uint64) Verifier
type ProposerPolicy ¶
type ProposerPolicy uint64
const ( RoundRobin ProposerPolicy = iota // in a round robin setting, proposer will change in very block and round change. Sticky // with sticky property, propose will change only when a round change happens. )
type RequestEvent ¶
type RequestEvent struct {
Proposal Proposal
}
type Server ¶
type Server interface { Address() common.Address // Verifiers returns the Verifier set Verifiers(proposal Proposal) VerifierSet // EventMux returns the event mux in backend EventMux() *event.TypeMux // Broadcast sends a message to all Verifiers (include self) Broadcast(valSet VerifierSet, payload []byte) error // Gossip sends a message to all Verifiers (exclude self) Gossip(valSet VerifierSet, payload []byte) error // Commit delivers an approved proposal to backend. // The delivered proposal will be put into blockchain. Commit(proposal Proposal, seals [][]byte) error // Verify verifies the proposal. If a consensus.ErrBlockCreateTimeOld 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) // CheckSignature verifies the signature by checking if it's signed by // the given Verifier 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) bool // GetProposer returns the proposer of the given block height GetProposer(height uint64) common.Address // ParentVerifiers returns the Verifier set of the given proposal's parent block ParentVerifiers(proposal Proposal) VerifierSet // HasBadBlock returns whether the block with the hash is a bad block HasBadProposal(hash common.Hash) bool }
type Subject ¶
func (*Subject) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.
type VerifierSet ¶
type VerifierSet interface { // Calculate the proposer CalcProposer(lastProposer common.Address, round uint64) // Return the Verifier size Size() int // Return the Verifier array List() []Verifier // Get Verifier by index GetVerByIndex(i uint64) Verifier // Get Verifier by given address GetVerByAddress(addr common.Address) (int, Verifier) // Get current proposer GetProposer() Verifier // Check whether the Verifier with given address is a proposer IsProposer(address common.Address) bool // Add Verifier AddVerifier(address common.Address) bool // Remove Verifier RemoveVerifier(address common.Address) bool // Copy Verifier set Copy() VerifierSet // Get the maximum number of faulty nodes F() int // Get proposer policy Policy() ProposerPolicy }
type Verifiers ¶
type Verifiers []Verifier
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.
Click to show internal directories.
Click to hide internal directories.