Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Core
- type ErrVoteConflictingVotes
- type HeightVoteSet
- func (hvs *HeightVoteSet) AddVote(vote *message.Vote) (added bool, err error)
- func (hvs *HeightVoteSet) Height() int64
- func (hvs *HeightVoteSet) POLInfo() (polRound int, polData message.ProposedData)
- func (hvs *HeightVoteSet) Precommits(round int) *VoteSet
- func (hvs *HeightVoteSet) Prevotes(round int) *VoteSet
- func (hvs *HeightVoteSet) Reset(height int64, valSet *Validators, b *message.ProposedData)
- func (hvs *HeightVoteSet) Round() int
- func (hvs *HeightVoteSet) SetRound(round int)
- func (hvs *HeightVoteSet) String() string
- func (hvs *HeightVoteSet) StringIndented(indent string) string
- type RoundState
- type RoundStepType
- type RoundVoteSet
- type StateSync
- type TimeoutTicker
- type Validators
- func (v *Validators) GetSelfPubKey() message.PubKey
- func (v *Validators) GetTotalVotingPower() int64
- func (v *Validators) GetValidatorNum() int
- func (v *Validators) GetVotingPower(address *message.PubKey) int64
- func (v *Validators) Sign(msg message.ConsensusMessage)
- func (v *Validators) VerifySignature(msg message.ConsensusMessage) bool
- type VoteSet
- func (voteSet *VoteSet) AddVote(vote *message.Vote) (added bool, err error)
- func (voteSet *VoteSet) HasAll() bool
- func (voteSet *VoteSet) HasTwoThirdsAny() bool
- func (voteSet *VoteSet) HasTwoThirdsMajority() bool
- func (voteSet *VoteSet) Height() int64
- func (voteSet *VoteSet) IsCommit() bool
- func (voteSet *VoteSet) MakeCommit() *message.Commit
- func (voteSet *VoteSet) MakeFetchVotesReq() *message.FetchVotesReq
- func (voteSet *VoteSet) MakeFetchVotesRsp(req *message.FetchVotesReq) *message.FetchVotesRsp
- func (voteSet *VoteSet) MinorQuorum() (message.ProposedData, bool)
- func (voteSet *VoteSet) Round() int
- func (voteSet *VoteSet) String() string
- func (voteSet *VoteSet) StringIndented(indent string) string
- func (voteSet *VoteSet) TwoThirdsMajority() (proposed message.ProposedData, ok bool)
- func (voteSet *VoteSet) Type() byte
Constants ¶
const ( RoundStepNewHeight = RoundStepType(0x01) // Wait til CommitTime + timeoutCommit RoundStepNewRound = RoundStepType(0x02) // Setup new round and go to RoundStepPropose RoundStepPropose = RoundStepType(0x03) // Did propose, gossip proposal RoundStepPrevote = RoundStepType(0x04) // Did prevote, gossip prevotes RoundStepPrevoteFetch = RoundStepType(0x05) // Waiting for 2/3 Any prevotes, fetch votes every second RoundStepPrevoteWait = RoundStepType(0x06) // Did receive any +2/3 prevotes, start timeout RoundStepPrecommit = RoundStepType(0x07) // Did precommit, gossip precommits RoundStepPrecommitFetch = RoundStepType(0x08) // Waiting for 2/3 Any precommits RoundStepPrecommitWait = RoundStepType(0x09) // Did receive any +2/3 precommits, start timeout RoundStepCommit = RoundStepType(0x0a) // Entered commit state machine )
RoundStepType
Variables ¶
var ( ErrVoteUnexpectedStep = errors.New("Unexpected step") ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index") ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address") ErrVoteInvalidSignature = errors.New("Invalid signature") ErrVoteInvalidBlockHash = errors.New("Invalid block hash") ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature") ErrVoteNil = errors.New("Nil vote") ErrVoteMismatchedBase = errors.New("Invalid base") ErrVoteHeightMismatch = errors.New("Error vote height mismatch") ErrVoteInvalidRound = errors.New("Invalid round") ErrInvalidProposer = errors.New("Error invalid proposer") ErrInvalidProposalSignature = errors.New("Error invalid proposal signature") ErrInvalidProposalPOLRound = errors.New("Error invalid proposal POL round") ErrAddingVote = errors.New("Error adding vote") )
var FetchInterval = time.Second
var (
GotVoteFromUnwantedRoundError = errors.New("Peer has sent a vote that does not match our round for more than one round")
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
TimeoutPropose time.Duration `mapstructure:"timeout_propose"`
TimeoutProposeDelta time.Duration `mapstructure:"timeout_propose_delta"`
TimeoutPrevote time.Duration `mapstructure:"timeout_prevote"`
TimeoutPrevoteDelta time.Duration `mapstructure:"timeout_prevote_delta"`
TimeoutPrecommit time.Duration `mapstructure:"timeout_precommit"`
TimeoutPrecommitDelta time.Duration `mapstructure:"timeout_precommit_delta"`
TimeoutCommit time.Duration `mapstructure:"timeout_commit"`
// Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default configuration for the consensus service
func TestConfig ¶
func TestConfig() *Config
TestConfig returns a configuration for testing the consensus service
func (*Config) Commit ¶
Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits for a single block (ie. a commit).
func (*Config) Precommit ¶
Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
func (*Config) Prevote ¶
Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
func (*Config) ValidateBasic ¶
ValidateBasic performs basic validation (checking param bounds, etc.) and returns an error if any check fails.
type Core ¶
type Core struct {
RoundState
sync.RWMutex
sync.WaitGroup
// contains filtered or unexported fields
}
func NewCore ¶
func NewCore(vals custom.ICommittee, pVal custom.IPrivValidator) *Core
func (*Core) GetLastCommit ¶
func (*Core) GetRoundState ¶
func (c *Core) GetRoundState() *RoundState
GetRoundState returns a shallow copy of the internal consensus state.
type ErrVoteConflictingVotes ¶
type ErrVoteConflictingVotes struct {
}
func NewConflictingVoteError ¶
func NewConflictingVoteError() *ErrVoteConflictingVotes
func (*ErrVoteConflictingVotes) Error ¶
func (err *ErrVoteConflictingVotes) Error() string
type HeightVoteSet ¶
type HeightVoteSet struct {
// contains filtered or unexported fields
}
Keeps track of all VoteSets from round 0 to round 'round'.
Also keeps track of up to one RoundVoteSet greater than 'round' from each peer, to facilitate catchup syncing of commits.
A commit is +2/3 precommits for a block at a round, but which round is not known in advance, so when a peer provides a precommit for a round greater than mtx.round, we create a new entry in roundVoteSets but also remember the peer to prevent abuse.
func NewHeightVoteSet ¶
func NewHeightVoteSet(height int64, valSet *Validators, b *message.ProposedData) *HeightVoteSet
func (*HeightVoteSet) AddVote ¶
func (hvs *HeightVoteSet) AddVote(vote *message.Vote) (added bool, err error)
Duplicate votes return added=false, err=nil. By convention, peerID is "" if origin is self.
func (*HeightVoteSet) Height ¶
func (hvs *HeightVoteSet) Height() int64
func (*HeightVoteSet) POLInfo ¶
func (hvs *HeightVoteSet) POLInfo() (polRound int, polData message.ProposedData)
Last round and blockID that has +2/3 prevotes for a particular block or nil. Returns -1 if no such round exists.
func (*HeightVoteSet) Precommits ¶
func (hvs *HeightVoteSet) Precommits(round int) *VoteSet
func (*HeightVoteSet) Prevotes ¶
func (hvs *HeightVoteSet) Prevotes(round int) *VoteSet
func (*HeightVoteSet) Reset ¶
func (hvs *HeightVoteSet) Reset(height int64, valSet *Validators, b *message.ProposedData)
func (*HeightVoteSet) Round ¶
func (hvs *HeightVoteSet) Round() int
func (*HeightVoteSet) SetRound ¶
func (hvs *HeightVoteSet) SetRound(round int)
Create more RoundVoteSets up to round.
func (*HeightVoteSet) String ¶
func (hvs *HeightVoteSet) String() string
func (*HeightVoteSet) StringIndented ¶
func (hvs *HeightVoteSet) StringIndented(indent string) string
type RoundState ¶
type RoundState struct {
Height int64
Round int
Step RoundStepType
StartTime time.Time
CommitTime time.Time // Subjective time when +2/3 precommits for Block at Round were found
Proposal *message.Vote
LockedRound int
LockedProposal *message.Vote
Votes *HeightVoteSet
CommitRound int
LastCommit *VoteSet // Last precommits at Height-1
// contains filtered or unexported fields
}
RoundState defines the internal consensus state. NOTE: Not thread safe. Should only be manipulated by functions downstream of the cs.receiveRoutine
func (*RoundState) StringIndented ¶
func (rs *RoundState) StringIndented(indent string) string
StringIndented returns a string
func (*RoundState) StringShort ¶
func (rs *RoundState) StringShort() string
StringShort returns a string
type RoundStepType ¶
type RoundStepType uint8 // These must be numeric, ordered.
RoundStepType enumerates the state of the consensus state machine
func (RoundStepType) IsValid ¶
func (rs RoundStepType) IsValid() bool
IsValid returns true if the step is valid, false if unknown/undefined.
type RoundVoteSet ¶
type StateSync ¶
type StateSync struct {
// contains filtered or unexported fields
}
func NewStateSync ¶
type TimeoutTicker ¶
type TimeoutTicker interface {
Start() error
Stop() error
Chan() <-chan timeoutInfo // on which to receive a timeout
ScheduleTimeout(ti timeoutInfo) // reset the timer
}
TimeoutTicker is a timer that schedules timeouts conditional on the height/round/step in the timeoutInfo. The timeoutInfo.Duration may be non-positive.
func NewTimeoutTicker ¶
func NewTimeoutTicker(c *Core) TimeoutTicker
NewTimeoutTicker returns a new TimeoutTicker.
type Validators ¶
type Validators struct {
sync.RWMutex
CustomValidators custom.ICommittee
// contains filtered or unexported fields
}
func NewValidators ¶
func NewValidators(val custom.ICommittee, pVal custom.IPrivValidator) *Validators
func (*Validators) GetSelfPubKey ¶
func (v *Validators) GetSelfPubKey() message.PubKey
func (*Validators) GetTotalVotingPower ¶
func (v *Validators) GetTotalVotingPower() int64
func (*Validators) GetValidatorNum ¶
func (v *Validators) GetValidatorNum() int
func (*Validators) GetVotingPower ¶
func (v *Validators) GetVotingPower(address *message.PubKey) int64
func (*Validators) Sign ¶
func (v *Validators) Sign(msg message.ConsensusMessage)
func (*Validators) VerifySignature ¶
func (v *Validators) VerifySignature(msg message.ConsensusMessage) bool
type VoteSet ¶
type VoteSet struct {
// contains filtered or unexported fields
}
VoteSet helps collect signatures from validators at each height+round for a predefined vote type.
We need VoteSet to be able to keep track of conflicting votes when validators double-sign. Yet, we can't keep track of *all* the votes seen, as that could be a DoS attack vector.
NOTE: Assumes that the sum total of voting power does not exceed MaxUInt64.
func NewVoteSet ¶
func NewVoteSet(height int64, round int, type_ message.VoteType, valSet *Validators, b *message.ProposedData) *VoteSet
Constructs a new VoteSet struct used to accumulate votes for given height/round.
func (*VoteSet) AddVote ¶
Returns added=true if vote is valid and new. Otherwise returns err=ErrVote[
UnexpectedStep | InvalidIndex | InvalidAddress | InvalidSignature | InvalidBlockHash | ConflictingVotes ]
Duplicate votes return added=false, err=nil. Conflicting votes return added=*, err=ErrVoteConflictingVotes. NOTE: vote should not be mutated after adding. NOTE: VoteSet must not be nil NOTE: Vote must not be nil
func (*VoteSet) HasTwoThirdsAny ¶
func (*VoteSet) HasTwoThirdsMajority ¶
func (*VoteSet) MakeCommit ¶
func (*VoteSet) MakeFetchVotesReq ¶
func (voteSet *VoteSet) MakeFetchVotesReq() *message.FetchVotesReq
func (*VoteSet) MakeFetchVotesRsp ¶
func (voteSet *VoteSet) MakeFetchVotesRsp(req *message.FetchVotesReq) *message.FetchVotesRsp
func (*VoteSet) MinorQuorum ¶
func (voteSet *VoteSet) MinorQuorum() (message.ProposedData, bool)
func (*VoteSet) StringIndented ¶
func (*VoteSet) TwoThirdsMajority ¶
func (voteSet *VoteSet) TwoThirdsMajority() (proposed message.ProposedData, ok bool)
If there was a +2/3 majority for blockID, return blockID and true. Else, return the empty BlockID{} and false.

