Documentation
¶
Index ¶
- Constants
- Variables
- func CopyBlock(block *common.Block) *common.Block
- func CopyProposalWithBlockHeader(p *tbftpb.Proposal) *tbftpb.Proposal
- func GetValidatorList(chainConfig *config.ChainConfig, store protocol.BlockchainStore) (validators []string, err error)
- func GetValidatorListFromConfig(chainConfig *config.ChainConfig) (validators []string, err error)
- func InitLWS(config *config.ConsensusConfig, chainId, nodeId string) (lwsInstance *lws.Lws, walWriteMode wal_service.WalWriteMode, err error)
- func NewProposal(voter string, height uint64, round int32, polRound int32, block *common.Block) *tbftpb.Proposal
- func NewProposalBlock(block *common.Block, txsRwSet map[string]*common.TxRWSet) *consensuspb.ProposalBlock
- func NewVote(typ tbftpb.VoteType, voter string, height uint64, round int32, hash []byte) *tbftpb.Vote
- func VerifyBlockSignatures(chainConf protocol.ChainConf, ac protocol.AccessControlProvider, ...) error
- func VerifyRoundQc(logger *logger.CMLogger, ac protocol.AccessControlProvider, ...) error
- type BlockVotes
- type ConsensusMsg
- type ConsensusState
- type ConsensusTBFTImpl
- func (consensus *ConsensusTBFTImpl) AddTimeout(duration time.Duration, height uint64, round int32, step tbftpb.Step)
- func (consensus *ConsensusTBFTImpl) CommitTimeout(round int32) time.Duration
- func (consensus *ConsensusTBFTImpl) GetConsensusStateJSON() ([]byte, error)
- func (consensus *ConsensusTBFTImpl) GetLastHeight() uint64
- func (consensus *ConsensusTBFTImpl) GetValidators() ([]string, error)
- func (consensus *ConsensusTBFTImpl) InitExtendHandler(handler protocol.ConsensusExtendHandler)
- func (consensus *ConsensusTBFTImpl) OnMessage(message *msgbus.Message)
- func (consensus *ConsensusTBFTImpl) OnQuit()
- func (consensus *ConsensusTBFTImpl) PrecommitTimeout(round int32) time.Duration
- func (consensus *ConsensusTBFTImpl) PrevoteTimeout(round int32) time.Duration
- func (consensus *ConsensusTBFTImpl) ProposeTimeout(round int32) time.Duration
- func (consensus *ConsensusTBFTImpl) Start() error
- func (consensus *ConsensusTBFTImpl) Stop() error
- func (consensus *ConsensusTBFTImpl) ToGossipStateProto() *tbftpb.GossipState
- func (consensus *ConsensusTBFTImpl) ToProto() *tbftpb.ConsensusState
- func (consensus *ConsensusTBFTImpl) Verify(consensusType consensuspb.ConsensusType, chainConfig *config.ChainConfig) error
- type PeerSendState
- type PeerStateService
- type TBFTProposal
- type VoteSet
Constants ¶
const ( DefaultTimeoutPropose = 30 * time.Second // Timeout of waitting for a proposal before prevoting nil DefaultTimeoutProposeDelta = 1 * time.Second // Increased time delta of TimeoutPropose between rounds DefaultBlocksPerProposer = uint64(1) // The number of blocks each proposer can propose TimeoutPrevote = 30 * time.Second // Timeout of waitting for >2/3 prevote TimeoutPrevoteDelta = 1 * time.Second // Increased time delta of TimeoutPrevote between round TimeoutPrecommit = 30 * time.Second // Timeout of waitting for >2/3 precommit TimeoutPrecommitDelta = 1 * time.Second // Increased time delta of TimeoutPrecommit between round TimeoutCommit = 30 * time.Second )
Variables ¶
var ( TBFTAddtionalDataKey = "TBFTAddtionalDataKey" TBFT_propose_timeout_key = "TBFT_propose_timeout" TBFT_propose_delta_timeout_key = "TBFT_propose_delta_timeout" TBFT_blocks_per_proposer = "TBFT_blocks_per_proposer" )
var ( ErrVoteNil = errors.New("nil vote") ErrUnexceptedStep = errors.New("unexpected step") ErrInvalidValidator = errors.New("invalid validator") ErrVoteForDifferentHash = errors.New("vote for different hash") )
var (
ErrInvalidIndex = errors.New("invalid index")
)
Functions ¶
func CopyBlock ¶
CopyBlock generates a new block with a old block, internally using the same pointer
func CopyProposalWithBlockHeader ¶
CopyProposalWithBlockHeader create a new Proposal instance for sign and verify
func GetValidatorList ¶
func GetValidatorList(chainConfig *config.ChainConfig, store protocol.BlockchainStore) (validators []string, err error)
func GetValidatorListFromConfig ¶
func GetValidatorListFromConfig(chainConfig *config.ChainConfig) (validators []string, err error)
func InitLWS ¶
func InitLWS(config *config.ConsensusConfig, chainId, nodeId string) (lwsInstance *lws.Lws, walWriteMode wal_service.WalWriteMode, err error)
func NewProposal ¶
func NewProposal(voter string, height uint64, round int32, polRound int32, block *common.Block) *tbftpb.Proposal
NewProposal create a new Proposal
func NewProposalBlock ¶
func NewProposalBlock(block *common.Block, txsRwSet map[string]*common.TxRWSet) *consensuspb.ProposalBlock
NewProposalBlock create a new ProposalBlock
func NewVote ¶
func NewVote(typ tbftpb.VoteType, voter string, height uint64, round int32, hash []byte) *tbftpb.Vote
NewVote create a new Vote instance
func VerifyBlockSignatures ¶
func VerifyBlockSignatures(chainConf protocol.ChainConf, ac protocol.AccessControlProvider, block *common.Block, store protocol.BlockchainStore, validatorListFunc consensus_utils.ValidatorListFunc) error
VerifyBlockSignatures verifies whether the signatures in block is qulified with the consensus algorithm. It should return nil error when verify successfully, and return corresponding error when failed.
func VerifyRoundQc ¶
func VerifyRoundQc(logger *logger.CMLogger, ac protocol.AccessControlProvider, validators *validatorSet, roundQC *tbftpb.RoundQC) error
VerifyRoundQc verifies whether the signatures in roundQC verify that the Qc is nil hash and the maj32 of the voteSet error when verify successfully, and return corresponding error when failed.
Types ¶
type BlockVotes ¶
BlockVotes traces the vote from different voter
func NewBlockVotes ¶
func NewBlockVotes() *BlockVotes
NewBlockVotes creates a new BlockVotes instance
func NewBlockVotesFromProto ¶
func NewBlockVotesFromProto(bvProto *tbftpb.BlockVotes) *BlockVotes
NewBlockVotesFromProto creates a new BlockVotes instance from pb
func (*BlockVotes) ToProto ¶
func (bv *BlockVotes) ToProto() *tbftpb.BlockVotes
ToProto serializes the BlockVotes instance
type ConsensusMsg ¶
type ConsensusMsg struct { Type tbftpb.TBFTMsgType Msg interface{} }
type ConsensusState ¶
type ConsensusState struct { Id string Height uint64 Round int32 Step tbftpb.Step Proposal *TBFTProposal // proposal VerifingProposal *TBFTProposal // verifing proposal LockedRound int32 LockedProposal *tbftpb.Proposal // locked proposal ValidRound int32 ValidProposal *tbftpb.Proposal // valid proposal TriggeredTimeoutPrecommit bool // flag that triggers a precommit timeout TriggeredTimeoutPrevote bool // flag that triggers a prevote timeout // contains filtered or unexported fields }
ConsensusState represents the consensus state of the node
func NewConsensusState ¶
func NewConsensusState(logger *logger.CMLogger, id string) *ConsensusState
NewConsensusState creates a new ConsensusState instance
type ConsensusTBFTImpl ¶
type ConsensusTBFTImpl struct { sync.RWMutex Id string *ConsensusState TimeoutPropose time.Duration TimeoutProposeDelta time.Duration // contains filtered or unexported fields }
ConsensusTBFTImpl is the implementation of TBFT algorithm and it implements the ConsensusEngine interface.
func New ¶
func New(config *consensusUtils.ConsensusImplConfig) (*ConsensusTBFTImpl, error)
New creates a tbft consensus instance
func (*ConsensusTBFTImpl) AddTimeout ¶
func (consensus *ConsensusTBFTImpl) AddTimeout(duration time.Duration, height uint64, round int32, step tbftpb.Step)
AddTimeout adds timeout event to timeScheduler
func (*ConsensusTBFTImpl) CommitTimeout ¶
func (consensus *ConsensusTBFTImpl) CommitTimeout(round int32) time.Duration
CommitTimeout returns timeout to wait for precommiting at `round`
func (*ConsensusTBFTImpl) GetConsensusStateJSON ¶
func (consensus *ConsensusTBFTImpl) GetConsensusStateJSON() ([]byte, error)
func (*ConsensusTBFTImpl) GetLastHeight ¶
func (consensus *ConsensusTBFTImpl) GetLastHeight() uint64
func (*ConsensusTBFTImpl) GetValidators ¶
func (consensus *ConsensusTBFTImpl) GetValidators() ([]string, error)
func (*ConsensusTBFTImpl) InitExtendHandler ¶
func (consensus *ConsensusTBFTImpl) InitExtendHandler(handler protocol.ConsensusExtendHandler)
func (*ConsensusTBFTImpl) OnMessage ¶
func (consensus *ConsensusTBFTImpl) OnMessage(message *msgbus.Message)
3. when receive commit block, send block to commitBlockC commitBlockC <- block
func (*ConsensusTBFTImpl) OnQuit ¶
func (consensus *ConsensusTBFTImpl) OnQuit()
func (*ConsensusTBFTImpl) PrecommitTimeout ¶
func (consensus *ConsensusTBFTImpl) PrecommitTimeout(round int32) time.Duration
PrecommitTimeout returns timeout to wait for precommiting at `round`
func (*ConsensusTBFTImpl) PrevoteTimeout ¶
func (consensus *ConsensusTBFTImpl) PrevoteTimeout(round int32) time.Duration
PrevoteTimeout returns timeout to wait for prevoting at `round`
func (*ConsensusTBFTImpl) ProposeTimeout ¶
func (consensus *ConsensusTBFTImpl) ProposeTimeout(round int32) time.Duration
ProposeTimeout returns timeout to wait for proposing at `round`
func (*ConsensusTBFTImpl) Start ¶
func (consensus *ConsensusTBFTImpl) Start() error
Start starts the tbft instance with: 1. Register to message bus for subscribing topics 2. Start background goroutinues for processing events 3. Start timeScheduler for processing timeout shedule
func (*ConsensusTBFTImpl) Stop ¶
func (consensus *ConsensusTBFTImpl) Stop() error
Stop implements the Stop method of ConsensusEngine interface.
func (*ConsensusTBFTImpl) ToGossipStateProto ¶
func (consensus *ConsensusTBFTImpl) ToGossipStateProto() *tbftpb.GossipState
func (*ConsensusTBFTImpl) ToProto ¶
func (consensus *ConsensusTBFTImpl) ToProto() *tbftpb.ConsensusState
func (*ConsensusTBFTImpl) Verify ¶
func (consensus *ConsensusTBFTImpl) Verify(consensusType consensuspb.ConsensusType, chainConfig *config.ChainConfig) error
Verify implements interface of struct Verifier, This interface is used to verify the validity of parameters, it executes before consensus.
type PeerSendState ¶
type PeerSendState struct { Height int64 Round int64 TriggerTime int64 // The timestamp of sending proposals at the same height TriggerCount int64 // The count of sending proposals at the same height // contains filtered or unexported fields }
func NewPeerSendState ¶
func NewPeerSendState(logger *logger.CMLogger) *PeerSendState
NewPeerSendState create a PeerSendState instance
type PeerStateService ¶
type PeerStateService struct { sync.Mutex Id string Height uint64 Round int32 Step tbftpb.Step Proposal []byte // proposal VerifingProposal []byte LockedRound int32 LockedProposal *tbftpb.Proposal // locked proposal ValidRound int32 ValidProposal *tbftpb.Proposal // valid proposal RoundVoteSet *roundVoteSet *PeerSendState // contains filtered or unexported fields }
PeerStateService represents the consensus state of peer node
func NewPeerStateService ¶
func NewPeerStateService(logger *logger.CMLogger, id string, tbftImpl *ConsensusTBFTImpl) *PeerStateService
NewPeerStateService create a PeerStateService instance
func (*PeerStateService) GetFetchQCC ¶
func (pcs *PeerStateService) GetFetchQCC() chan<- *tbftpb.FetchRoundQC
GetFetchQCC return the fetchQC channel
func (*PeerStateService) GetStateC ¶
func (pcs *PeerStateService) GetStateC() chan<- *tbftpb.GossipState
GetStateC return the stateC channel
type TBFTProposal ¶
func NewTBFTProposal ¶
func NewTBFTProposal(proposal *tbftpb.Proposal, marshal bool) *TBFTProposal
NewTBFTProposal create tbft proposal instance
func (*TBFTProposal) Marshal ¶
func (p *TBFTProposal) Marshal()
Marshal marshal the proposal and not care the old bytes
type VoteSet ¶
type VoteSet struct { Type tbftpb.VoteType Height uint64 Round int32 Sum uint64 Maj23 []byte Votes map[string]*tbftpb.Vote VotesByBlock map[string]*BlockVotes // contains filtered or unexported fields }
VoteSet wraps tbftpb.VoteSet and validatorSet
func NewVoteSet ¶
func NewVoteSet(logger *logger.CMLogger, voteType tbftpb.VoteType, height uint64, round int32, validators *validatorSet) *VoteSet
NewVoteSet creates a new VoteSet instance
func NewVoteSetFromProto ¶
func NewVoteSetFromProto(logger *logger.CMLogger, vsProto *tbftpb.VoteSet, validators *validatorSet) *VoteSet
NewVoteSetFromProto creates a new VoteSet instance from pb
func (*VoteSet) HasTwoThirdsMajority ¶
HasTwoThirdsMajority shoule used when the mutex has been lock