Documentation ¶
Index ¶
- Constants
- Variables
- func ProposalMsg(round int64, id []byte, justifyParent []byte) *types.ProposalMsg
- func ProtoFromConsMsg(msg MsgInfo) ([]byte, error)
- func TimeoutMsg(round int64, pround int64, pid []byte, idx int64) *types.TimeoutMsg
- func VoteMsg(round int64, id []byte, pround int64, pid []byte, to string) *types.VoteMsg
- type BlockTree
- func (t *BlockTree) ExecuteNInsert(qc QuorumCert) error
- func (t *BlockTree) GetCurrentHighQC() QuorumCert
- func (t *BlockTree) GetCurrentRoot() QuorumCert
- func (t *BlockTree) GetJustify() ([]byte, error)
- func (t *BlockTree) ProcessCommit(key string) error
- func (t *BlockTree) ProcessVote(qc QuorumCert, validators []PeerID) error
- func (t *BlockTree) Search(round int64, id []byte) (*bt.Node, error)
- type ConsensusConfig
- type DefaultElection
- type DefaultPacemaker
- type DefaultQuorumCert
- func (qc DefaultQuorumCert) ParentProposal() (int64, []byte, error)
- func (qc DefaultQuorumCert) Proposal() (int64, []byte, error)
- func (qc DefaultQuorumCert) Sender() string
- func (qc DefaultQuorumCert) Serialize() ([]byte, error)
- func (qc DefaultQuorumCert) Signatures(peerID string) (int, []byte, []byte, error)
- func (qc DefaultQuorumCert) String() string
- type DefaultSafetyRules
- type DefaultSign
- type DefaultTimeoutTicker
- type DeserializeQurumCert
- type MsgInfo
- type NewQurumCert
- type Pacemaker
- type PeerID
- type ProposerElection
- type QuorumCert
- type RoundTimeoutSet
- type RoundVoteSet
- type SafetyRules
- type SerializeID
- type State
- func (s *State) GetNextID() ([]byte, error)
- func (s *State) HandleFunc(chID int32, msgbytes []byte)
- func (s *State) NewRoundEvent(action string) error
- func (s *State) RegisterElection(election ProposerElection) error
- func (s *State) RegisterPaceMaker(pacemaker Pacemaker) error
- func (s *State) RegisterSaftyrules(safetyrules SafetyRules) error
- func (s *State) SetSwitch(p2p libs.Switch)
- func (s *State) Start()
- type StepValidators
- type TimeoutSet
- func (s *TimeoutSet) AddTimeout(round int64, idx int64, sender PeerID, validators []PeerID) error
- func (s *TimeoutSet) GetCurrentTimeoutIndex() int64
- func (s *TimeoutSet) GetTimeoutIdxMap() map[int64]int64
- func (s *TimeoutSet) HasTwoThirdsAny(round int64, idx int64) bool
- func (s *TimeoutSet) Reset(round int64, idx int64) error
- type TimeoutTicker
- type VoteSet
- type WAL
- type WALMessage
Constants ¶
const ( DeltaMillSec = 1000 TimeoutT = 4 * DeltaMillSec * time.Millisecond // 4delta round-trip MsgQueueSize = 1000 NoRollbackTmoIdx = 0 TimeoutProcess = "TIMEOUT" ProposalProcess = "PROPOSAL" VoteProcess = "VOTE" )
const ( TypeCollectVotes = 1 // "collect_votes_type" TypeNextRound = 2 // "next_round_type" MaxTimeoutSec = 60 * 60 )
Variables ¶
var ( ErrVoteSetOccupied = errors.New("round occupied") ErrComponentsOccupied = errors.New("components occupied") )
var (
ErrNilQC = errors.New("pacemaker meets a nil qc")
)
Functions ¶
func ProposalMsg ¶
func ProposalMsg(round int64, id []byte, justifyParent []byte) *types.ProposalMsg
func ProtoFromConsMsg ¶
func TimeoutMsg ¶
Types ¶
type BlockTree ¶
type BlockTree struct { DeserializeF DeserializeQurumCert NewQurumCertF NewQurumCert FF SerializeID // contains filtered or unexported fields }
BlockTree is an added storage to achieve consensus in a distributed system, main infomation like entries should be stored in different way.
func NewQCTree ¶
func NewQCTree(user PeerID, rootRound int64, rootID string, rootValue []byte, df DeserializeQurumCert, nf NewQurumCert, log libs.Logger) (*BlockTree, error)
func (*BlockTree) ExecuteNInsert ¶
func (t *BlockTree) ExecuteNInsert(qc QuorumCert) error
func (*BlockTree) GetCurrentHighQC ¶
func (t *BlockTree) GetCurrentHighQC() QuorumCert
func (*BlockTree) GetCurrentRoot ¶
func (t *BlockTree) GetCurrentRoot() QuorumCert
func (*BlockTree) GetJustify ¶
func (*BlockTree) ProcessCommit ¶
func (*BlockTree) ProcessVote ¶
func (t *BlockTree) ProcessVote(qc QuorumCert, validators []PeerID) error
type ConsensusConfig ¶
type ConsensusConfig struct { StartRound int64 StartTimeoutIdx int64 StartID string StartValue []byte StartValidators []PeerID }
----------------------------------------------------------------
type DefaultElection ¶
type DefaultElection struct {
// contains filtered or unexported fields
}
func NewDefaultElection ¶
func NewDefaultElection(start int64, init []PeerID) *DefaultElection
func (*DefaultElection) Leader ¶
func (e *DefaultElection) Leader(round int64, roundTimeoutIdxMap map[int64]int64) PeerID
Leader indicates that the system cannot rollback.
func (*DefaultElection) Validators ¶
func (e *DefaultElection) Validators(round int64, roundTimeoutIdxMap map[int64]int64) []PeerID
type DefaultPacemaker ¶
type DefaultPacemaker struct {
// contains filtered or unexported fields
}
func NewDefaultPacemaker ¶
func NewDefaultPacemaker(latest int64) *DefaultPacemaker
func (*DefaultPacemaker) AdvanceRound ¶
func (p *DefaultPacemaker) AdvanceRound(qc QuorumCert) error
func (*DefaultPacemaker) GetCurrentRound ¶
func (p *DefaultPacemaker) GetCurrentRound() int64
func (*DefaultPacemaker) ProcessTimeoutRound ¶
func (p *DefaultPacemaker) ProcessTimeoutRound(qc QuorumCert) error
ProcessTimeoutRound DefaultPacemaker cannot rollback.
type DefaultQuorumCert ¶
type DefaultQuorumCert struct { Round int64 `json:"round"` ID []byte `json:"id"` ParentRound int64 `json:"parent_round"` ParentID []byte `json:"parent_id"` SenderID string `json:"sender"` Signs map[string]DefaultSign `json:"signs"` }
DefaultQuorumCert is the canonical implementation of the QuorumCert interface
func (DefaultQuorumCert) ParentProposal ¶
func (qc DefaultQuorumCert) ParentProposal() (int64, []byte, error)
func (DefaultQuorumCert) Sender ¶
func (qc DefaultQuorumCert) Sender() string
func (DefaultQuorumCert) Serialize ¶
func (qc DefaultQuorumCert) Serialize() ([]byte, error)
func (DefaultQuorumCert) Signatures ¶
func (DefaultQuorumCert) String ¶
func (qc DefaultQuorumCert) String() string
type DefaultSafetyRules ¶
type DefaultSafetyRules struct {
// contains filtered or unexported fields
}
func NewDefaultSafetyRules ¶
func NewDefaultSafetyRules(point *State) *DefaultSafetyRules
func (*DefaultSafetyRules) CheckProposal ¶
func (s *DefaultSafetyRules) CheckProposal(new, parent QuorumCert) error
CheckProposal checks whether the proposal is valid: a. check the new proposal has a unique id & round, b. check the proposal's parent is in our tree, which means it's the one of children of the root,
func (*DefaultSafetyRules) CheckTimeout ¶
func (s *DefaultSafetyRules) CheckTimeout(qc QuorumCert) error
func (*DefaultSafetyRules) CheckVote ¶
func (s *DefaultSafetyRules) CheckVote(qc QuorumCert) error
func (*DefaultSafetyRules) UpdatePreferredRound ¶
func (s *DefaultSafetyRules) UpdatePreferredRound(round int64) error
type DefaultTimeoutTicker ¶
type DefaultTimeoutTicker struct {
// contains filtered or unexported fields
}
func (*DefaultTimeoutTicker) Chan ¶
func (t *DefaultTimeoutTicker) Chan() <-chan timeoutInfo
Chan returns a channel on which timeouts are sent.
func (*DefaultTimeoutTicker) ScheduleTimeout ¶
func (t *DefaultTimeoutTicker) ScheduleTimeout(ti timeoutInfo)
ScheduleTimeout schedules a new timeout by sending on the internal tickChan. The timeoutRoutine is always available to read from tickChan, so this won't block. The scheduling may fail if the timeoutRoutine has already scheduled a timeout for a later height/round/step.
func (*DefaultTimeoutTicker) Start ¶
func (t *DefaultTimeoutTicker) Start()
func (*DefaultTimeoutTicker) Stop ¶
func (t *DefaultTimeoutTicker) Stop()
type DeserializeQurumCert ¶
type DeserializeQurumCert func(input []byte) (qc QuorumCert, err error)
type MsgInfo ¶
Message is a message that can be sent and received within peers
func ConsMsgFromProto ¶
MsgFromProto takes a consensus proto message and returns the native hotstuff types
type NewQurumCert ¶
type Pacemaker ¶
type Pacemaker interface { // GetCurrentRound return current round of this node. GetCurrentRound() int64 // AdvanceRound increase the round number when the input is valid, // it will invoke next_round_event(). AdvanceRound(qc QuorumCert) error // ProcessTimeoutRound decides the next round when the node has enough timeoutMSG, // developer can choose different procedures like advance_round only or rollback to the previous round, // it will invoke next_round_event(). // When the builder can accept a recyclic round, which means the next round of round A can also be round A under timeout situation, // the next round is calculated by the specific election. Conversely it should return round + 1 when the system cannot rollback. ProcessTimeoutRound(qc QuorumCert) error }
PacemakerInterface is the interface of Pacemaker. It responsible for generating a new round. We assume Pacemaker in all correct replicas will have synchronized leadership after GST. Safty is entirelydecoupled from liveness by any potential instantiation of Packmaker. Different consensus have different pacemaker implement.
type ProposerElection ¶
type ProposerElection interface { // roundTimeoutIdxMap map[int64]int64 is an index-look-up map // stores the timeout times in the same round of a rollback system. // round-timeoutidx can specialize the unique round on the system. Validators(round int64, roundTimeoutIdxMap map[int64]int64) []PeerID Leader(round int64, roundTimeoutIdxMap map[int64]int64) PeerID // User can dynamically change the validators at runtime by the commands if needed. Update(round int64, next []PeerID) error }
type QuorumCert ¶
type QuorumCert interface { Proposal() (round int64, id []byte, err error) // QC's id shoud be unique. ParentProposal() (round int64, id []byte, err error) Sender() (senderID string) Signatures(peerID string) (signType int, sign []byte, pk []byte, err error) Serialize() ([]byte, error) String() string }
func DefaultDeserialize ¶
func DefaultDeserialize(input []byte) (QuorumCert, error)
func NewDefaultQuorumCert ¶
type RoundTimeoutSet ¶
type RoundTimeoutSet struct {
// contains filtered or unexported fields
}
type RoundVoteSet ¶
type RoundVoteSet struct {
// contains filtered or unexported fields
}
type SafetyRules ¶
type SafetyRules interface { UpdatePreferredRound(round int64) error CheckProposal(new, parent QuorumCert) error CheckVote(qc QuorumCert) error CheckTimeout(qc QuorumCert) error }
type SerializeID ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State handles execution of the hotstuff consensus algorithm. It processes votes and proposals, and upon reaching agreement, commits blocks to the storage and executes them against the application. The internal state machine receives input from peers, the internal validator, and from a timer.
func NewState ¶
func NewState(name PeerID, cc crypto.CryptoClient, timeout TimeoutTicker, logger libs.Logger, cfg *ConsensusConfig) (*State, error)
func (*State) HandleFunc ¶
Handle define consensus reactor function, NOTE: chID is ignored if it's unknown.
func (*State) NewRoundEvent ¶
NewRoundEvent starts a new timer for the next round and broadcasts the proposal msg when the host is the leader.
func (*State) RegisterElection ¶
func (s *State) RegisterElection(election ProposerElection) error
func (*State) RegisterPaceMaker ¶
func (*State) RegisterSaftyrules ¶
func (s *State) RegisterSaftyrules(safetyrules SafetyRules) error
type StepValidators ¶
type TimeoutSet ¶
type TimeoutSet struct {
// contains filtered or unexported fields
}
func NewTimeoutSet ¶
func NewTimeoutSet(rootRound int64, latestTimeoutIndex int64) *TimeoutSet
TODO: load from wal
func (*TimeoutSet) AddTimeout ¶
when the rollback strategy is loaded, timeout round can be similar with the previous timeout round (see a timeout round a of the leader a has came out, the system will rollback and rebuild round a which leader may be leader a too), so we use index flag to make timeout unique among the others.
func (*TimeoutSet) GetCurrentTimeoutIndex ¶
func (s *TimeoutSet) GetCurrentTimeoutIndex() int64
func (*TimeoutSet) GetTimeoutIdxMap ¶
func (s *TimeoutSet) GetTimeoutIdxMap() map[int64]int64
func (*TimeoutSet) HasTwoThirdsAny ¶
func (s *TimeoutSet) HasTwoThirdsAny(round int64, idx int64) bool
type TimeoutTicker ¶
type TimeoutTicker interface { Start() Stop() 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.
func NewDefaultTimeoutTicker ¶
func NewDefaultTimeoutTicker(logger libs.Logger) TimeoutTicker
NewDefaultTimeoutTicker returns a new DefaultTimeoutTicker and invoke timeoutTicker.Start().
type VoteSet ¶
type VoteSet struct {
// contains filtered or unexported fields
}
type WAL ¶
type WAL interface { Write(WALMessage) error WriteSync(WALMessage) error FlushAndSync() error SearchForEndHeight(height int64) (rd io.ReadCloser, found bool, err error) // service methods Start() error Stop() error Wait() }
WAL is an interface for any write-ahead logger.
type WALMessage ¶
type WALMessage interface{}