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 VerifyBlockSignatures(chainConf protocol.ChainConf, ac protocol.AccessControlProvider, ...) error
- type BatchMsg
- type BatchMsgInterpreter
- type Committer
- type ConsensusTBFTImpl
- func (consensus *ConsensusTBFTImpl) Close() error
- func (consensus *ConsensusTBFTImpl) GetAllNodeInfos() []consensuspb.ConsensusNodeInfo
- func (consensus *ConsensusTBFTImpl) GetConsensusStateJSON() ([]byte, error)
- func (consensus *ConsensusTBFTImpl) GetConsensusType() consensuspb.ConsensusType
- func (consensus *ConsensusTBFTImpl) GetLastHeight() uint64
- func (consensus *ConsensusTBFTImpl) GetValidators() ([]string, error)
- func (consensus *ConsensusTBFTImpl) InitExtendHandler(handler protocol.ConsensusExtendHandler)
- func (consensus *ConsensusTBFTImpl) Start() error
- func (consensus *ConsensusTBFTImpl) Stop() error
- func (consensus *ConsensusTBFTImpl) Verify(consensusType consensuspb.ConsensusType, chainConfig *config.ChainConfig) error
- type Handler
- type HandlerManager
- type NetHandler
- type ParamsHandler
- func (p *ParamsHandler) Close()
- func (p *ParamsHandler) GetLastBlockProposer() string
- func (p *ParamsHandler) GetNewParams() (validators []string, timeoutPropose time.Duration, ...)
- func (p *ParamsHandler) InitExtendHandler(extendHandler protocol.ConsensusExtendHandler)
- func (nh *ParamsHandler) MsgTopic() msgbus.Topic
- func (p *ParamsHandler) Name() string
- func (nh *ParamsHandler) OnMessage(message *msgbus.Message)
- type ProposalHandler
- func (p *ProposalHandler) Close()
- func (p *ProposalHandler) MarshalProposal(proposal *tbftengine.Proposal) ([]byte, error)
- func (nh *ProposalHandler) MsgTopic() msgbus.Topic
- func (p *ProposalHandler) Name() string
- func (nh *ProposalHandler) OnMessage(message *msgbus.Message)
- func (p *ProposalHandler) UnmarshalProposal(b []byte) (*tbftengine.Proposal, error)
- type Verifier
- func (v *Verifier) Close()
- func (v *Verifier) MsgTopic() msgbus.Topic
- func (v *Verifier) Name() string
- func (v *Verifier) OnMessage(message *msgbus.Message)
- func (v *Verifier) SignBatchMsg(batchMsg tbftengine.BatchMsg) (interface{}, error)
- func (v *Verifier) SignProposal(proposal *tbftengine.Proposal) (interface{}, error)
- func (v *Verifier) SignVote(vote *enginePb.Vote) ([]byte, error)
- func (v *Verifier) VerifyBatchMsg(batchMsg tbftengine.BatchMsg) (*tbftengine.VerifyResult, error)
- func (v *Verifier) VerifyBlockWithRwSets(batchMsg tbftengine.BatchMsg, txsRwSet interface{}, vs *enginePb.VoteSet) error
- func (v *Verifier) VerifyProposal(proposal *tbftengine.Proposal) error
- func (v *Verifier) VerifyVote(voteProto *enginePb.Vote) error
- type WalHandler
Constants ¶
const ( // DefaultTimeoutPropose Timeout of waitting for a proposal before prevoting nil DefaultTimeoutPropose = 30 * time.Second // DefaultTimeoutProposeDelta Increased time delta of TimeoutPropose between rounds DefaultTimeoutProposeDelta = 1 * time.Second // DefaultTimeoutProposeOptimal optimal timeout of waitting for a proposal before prevoting nil DefaultTimeoutProposeOptimal = 2 * time.Second )
Variables ¶
var ( // ErrErrorHandler implements the error of handler init ErrErrorHandler = errors.New("the handler initialization error ") // ErrNoExistHandler implements the error of handler does not exist ErrNoExistHandler = errors.New("the handler does not exist") )
var ( // TBFT_propose_timeout_key implements the config key for chainconf TBFT_propose_timeout_key = "TBFT_propose_timeout" // TBFT_propose_delta_timeout_key implements the config key for chainconf TBFT_propose_delta_timeout_key = "TBFT_propose_delta_timeout" // TBFT_blocks_per_proposer implements the config key for chainconf TBFT_blocks_per_proposer = "TBFT_blocks_per_proposer" // TBFT_propose_timeout_optimal_key implements the config key for chainconf TBFT_propose_timeout_optimal_key = "TBFT_propose_timeout_optimal" // TBFT_propose_optimal_key implements the config key for chainconf TBFT_propose_optimal_key = "TBFT_propose_optimal" )
var AdditionalDataKey = "TBFTAddtionalDataKey"
AdditionalDataKey implements the block key for store tbft infos
var TBFTAddtionalDataKey = "TBFTAddtionalDataKey"
TBFTAddtionalDataKey implements the block key for store tbft infos
Functions ¶
func CopyBlock ¶ added in v3.0.1
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)
GetValidatorList get Validator List From Config @param chainConfig @param store Not currently in use @return validators @return err
func GetValidatorListFromConfig ¶
func GetValidatorListFromConfig(chainConfig *config.ChainConfig) (validators []string, err error)
GetValidatorListFromConfig get Validator List From Config @param chainConfig @return validators @return err
func InitLWS ¶
func InitLWS(config *config.ConsensusConfig, chainId, nodeId string) (lwsInstance *lws.Lws, walWriteMode wal_service.WalWriteMode, err error)
InitLWS initialize LWS @param config Consensus Config @param chainId @param nodeId @return lwsInstance @return walWriteMode @return err
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.
Types ¶
type BatchMsg ¶
type BatchMsg struct {
// contains filtered or unexported fields
}
BatchMsg the object to consensus
func (*BatchMsg) GetSetSignature ¶
func (b *BatchMsg) GetSetSignature() interface{}
GetSetSignature get sign of BatchMsg
func (*BatchMsg) Sequence ¶
Sequence return sequence of BatchMsg
type BatchMsgInterpreter ¶
type BatchMsgInterpreter struct {
// contains filtered or unexported fields
}
BatchMsgInterpreter implements the BatchMsgInterpreter interface of tbft-engine
func NewBatchMsgInterpreter ¶
func NewBatchMsgInterpreter(log *logger.CMLogger, size int) *BatchMsgInterpreter
NewBatchMsgInterpreter creates a new BatchMsgInterpreter instance
func (*BatchMsgInterpreter) Close ¶
func (b *BatchMsgInterpreter) Close()
Close cloe the BatchMsgInterpreter
func (*BatchMsgInterpreter) MsgTopic ¶ added in v3.0.1
func (b *BatchMsgInterpreter) MsgTopic() msgbus.Topic
MsgTopic indicated the BatchMsgInterpreter need to receive ProposedBlock
func (*BatchMsgInterpreter) Name ¶
func (b *BatchMsgInterpreter) Name() string
Name return BatchMsgInterpreter name
func (*BatchMsgInterpreter) OnMessage ¶
func (b *BatchMsgInterpreter) OnMessage(message *msgbus.Message)
OnMessage received msg from handlerManager.
func (*BatchMsgInterpreter) PrepareBatchMsg ¶
func (b *BatchMsgInterpreter) PrepareBatchMsg() <-chan *tbftengine.ProposalBatchMsg
PrepareBatchMsg the tbft engine listens to this chan and fetch a BatchMsg for consensus
type Committer ¶
type Committer struct {
// contains filtered or unexported fields
}
Committer commit consensus object
func NewCommitter ¶
func NewCommitter(log *logger.CMLogger, msgBus msgbus.MessageBus, size int) *Committer
NewCommitter creates a new Committer instance
func (*Committer) Commit ¶
Commit commit consensus object
func (*Committer) CommitDone ¶
CommitDone complete the batchMsg commit and notify the consensus to start the next consensus
func (*Committer) MsgTopic ¶ added in v3.0.1
MsgTopic indicated the committer need to receive blockInfo
type ConsensusTBFTImpl ¶
type ConsensusTBFTImpl struct { Id string // contains filtered or unexported fields }
ConsensusTBFTImpl is the implementation of TBFT algorithm and it base on the tbft engine.
func New ¶
func New(config *consensusUtils.ConsensusImplConfig) (*ConsensusTBFTImpl, error)
New creates a tbft consensus instance
func (*ConsensusTBFTImpl) Close ¶ added in v3.0.1
func (consensus *ConsensusTBFTImpl) Close() error
Close implements the Close method of ConsensusEngine interface.
func (*ConsensusTBFTImpl) GetAllNodeInfos ¶
func (consensus *ConsensusTBFTImpl) GetAllNodeInfos() []consensuspb.ConsensusNodeInfo
GetAllNodeInfos get consensus nodes info @receiver consensus @return []protocol.ConsensusNodeInfo
func (*ConsensusTBFTImpl) GetConsensusStateJSON ¶
func (consensus *ConsensusTBFTImpl) GetConsensusStateJSON() ([]byte, error)
GetConsensusStateJSON get consensus status in json format @receiver consensus @return []byte @return error always return nil
func (*ConsensusTBFTImpl) GetConsensusType ¶
func (consensus *ConsensusTBFTImpl) GetConsensusType() consensuspb.ConsensusType
GetConsensusType get consensus type @receiver consensus @return uint64
func (*ConsensusTBFTImpl) GetLastHeight ¶
func (consensus *ConsensusTBFTImpl) GetLastHeight() uint64
GetLastHeight get current height from consensus state @receiver consensus @return uint64
func (*ConsensusTBFTImpl) GetValidators ¶
func (consensus *ConsensusTBFTImpl) GetValidators() ([]string, error)
GetValidators get validators from consensus state @receiver consensus @return []string validators @return error always return nil
func (*ConsensusTBFTImpl) InitExtendHandler ¶
func (consensus *ConsensusTBFTImpl) InitExtendHandler(handler protocol.ConsensusExtendHandler)
InitExtendHandler registered extendHandler
func (*ConsensusTBFTImpl) Start ¶
func (consensus *ConsensusTBFTImpl) Start() error
Start starts the tbft instance with tbft-engine the consensus module monitors the signal of the sync module, when the sync module synchronizes a relatively high block, it notifies the consensus module to start the consensus process
func (*ConsensusTBFTImpl) Stop ¶
func (consensus *ConsensusTBFTImpl) Stop() error
Stop implements the Stop method of ConsensusEngine interface.
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 Handler ¶
Handler implements handler Attributes management
type HandlerManager ¶
type HandlerManager struct { HandlerMap map[string]Handler TopicHandlersMap map[msgbus.Topic][]Handler // contains filtered or unexported fields }
HandlerManager implements manage each handler
func NewHandlerManager ¶
func NewHandlerManager(logger *logger.CMLogger, msgBus msgbus.MessageBus, consensusEngine *tbftengine.ConsensusEngine) *HandlerManager
NewHandlerManager creates a HandlerManager instance
func (*HandlerManager) OnMessage ¶ added in v3.0.1
func (hm *HandlerManager) OnMessage(message *msgbus.Message)
OnMessage implements the OnMessage method of msgbus.
func (*HandlerManager) OnQuit ¶ added in v3.0.1
func (hm *HandlerManager) OnQuit()
OnQuit implements the OnQuit method of msgbus.
func (*HandlerManager) Start ¶ added in v3.0.1
func (hm *HandlerManager) Start()
Start all the handlers in handlerManager
func (*HandlerManager) Stop ¶ added in v3.0.1
func (hm *HandlerManager) Stop()
Stop stop all the handlers in handlerManager
type NetHandler ¶
type NetHandler struct {
// contains filtered or unexported fields
}
NetHandler implements the NetHandler interface of tbft-engine
func NewNetHandler ¶
func NewNetHandler(msgBus msgbus.MessageBus, log *logger.CMLogger, size int, nodeId string, host *tbftengine.ConsensusEngine) *NetHandler
NewNetHandler create a NetHandler instance
func (*NetHandler) BroadCastNetMsg ¶
func (n *NetHandler) BroadCastNetMsg(payload []byte, to string) error
BroadCastNetMsg send consensus msg,If to is an empty string, send to all validators @receiver consensus @param msg @param to
func (*NetHandler) Listen ¶
func (n *NetHandler) Listen() <-chan interface{}
Listen the tbft engine listens to this chan and fetch a net message
func (*NetHandler) MsgTopic ¶ added in v3.0.1
func (n *NetHandler) MsgTopic() msgbus.Topic
MsgTopic indicated the NetHandler need to receive RecvConsensusMsg
func (*NetHandler) OnMessage ¶
func (n *NetHandler) OnMessage(message *msgbus.Message)
OnMessage implements the OnMessage method of msgbus.
type ParamsHandler ¶
type ParamsHandler struct {
// contains filtered or unexported fields
}
ParamsHandler implements the ParamsHandler interface of tbft-engine
func NewParamsHandler ¶
func NewParamsHandler(log *logger.CMLogger, chainConf protocol.ChainConf, netService protocol.NetService, ac protocol.AccessControlProvider, ledgerCache protocol.LedgerCache) *ParamsHandler
NewParamsHandler create a ParamsHandler instance
func (*ParamsHandler) GetLastBlockProposer ¶
func (p *ParamsHandler) GetLastBlockProposer() string
GetLastBlockProposer get node id of last block proposer
func (*ParamsHandler) GetNewParams ¶
func (p *ParamsHandler) GetNewParams() (validators []string, timeoutPropose time.Duration, timeoutProposeDelta time.Duration, tbftBlocksPerProposer uint64, proposeOptimal bool, timeoutProposeOptimal time.Duration, err error)
GetNewParams called at the beginning of a new consensus to get the parameters required by the consensus
func (*ParamsHandler) InitExtendHandler ¶ added in v3.0.1
func (p *ParamsHandler) InitExtendHandler(extendHandler protocol.ConsensusExtendHandler)
InitExtendHandler registered extendHandler
func (*ParamsHandler) MsgTopic ¶ added in v3.0.1
MsgTopic indicated the handler need to receive nothing
type ProposalHandler ¶
type ProposalHandler struct {
// contains filtered or unexported fields
}
ProposalHandler implements the Coder interface of tbft-engine
func NewProposalHandler ¶
func NewProposalHandler() *ProposalHandler
NewProposalHandler creates a new ProposalHandler instance
func (*ProposalHandler) MarshalProposal ¶
func (p *ProposalHandler) MarshalProposal(proposal *tbftengine.Proposal) ([]byte, error)
MarshalProposal implement the Proposal marshal
func (*ProposalHandler) MsgTopic ¶ added in v3.0.1
MsgTopic indicated the handler need to receive nothing
func (*ProposalHandler) Name ¶
func (p *ProposalHandler) Name() string
Name return ProposalHandler name
func (*ProposalHandler) OnMessage ¶ added in v3.0.1
OnMessage implements the OnMessage method of msgbus.
func (*ProposalHandler) UnmarshalProposal ¶
func (p *ProposalHandler) UnmarshalProposal(b []byte) (*tbftengine.Proposal, error)
UnmarshalProposal implement the Proposal unmarshal
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier implements the Verifier interface of tbft-engine
func NewVerifier ¶
func NewVerifier(log *logger.CMLogger, msgBus msgbus.MessageBus, signer protocol.SigningMember, ac protocol.AccessControlProvider, chainConf protocol.ChainConf, blockVerifier protocol.BlockVerifier, netService protocol.NetService) *Verifier
NewVerifier creates a new Verifier instance
func (*Verifier) MsgTopic ¶ added in v3.0.1
MsgTopic indicated the Verifier need to receive VerifyResult
func (*Verifier) OnMessage ¶
OnMessage implements the OnMessage method of msgbus.
func (*Verifier) SignBatchMsg ¶
func (v *Verifier) SignBatchMsg(batchMsg tbftengine.BatchMsg) (interface{}, error)
SignBatchMsg sign batchMsg
func (*Verifier) SignProposal ¶
func (v *Verifier) SignProposal(proposal *tbftengine.Proposal) (interface{}, error)
SignProposal sign proposal
func (*Verifier) SignVote ¶
SignVote sign vote
func (*Verifier) VerifyBatchMsg ¶
func (v *Verifier) VerifyBatchMsg(batchMsg tbftengine.BatchMsg) (*tbftengine.VerifyResult, error)
VerifyBatchMsg verify the batchMsg
func (*Verifier) VerifyBlockWithRwSets ¶
func (v *Verifier) VerifyBlockWithRwSets(batchMsg tbftengine.BatchMsg, txsRwSet interface{}, vs *enginePb.VoteSet) error
VerifyBlockWithRwSets proc VerifyBlockWithRwSets by core
func (*Verifier) VerifyProposal ¶
func (v *Verifier) VerifyProposal(proposal *tbftengine.Proposal) error
VerifyProposal verify the proposal
type WalHandler ¶
type WalHandler struct {
// contains filtered or unexported fields
}
WalHandler Implement wal operations to read and write consensus state
func NewWalHandler ¶
func NewWalHandler(log *logger.CMLogger, config *config.ConsensusConfig, chainId, nodeId string) *WalHandler
NewWalHandler creates a new WalHandler instance
func (*WalHandler) MsgTopic ¶ added in v3.0.1
MsgTopic indicated the handler need to receive nothing
func (*WalHandler) OnMessage ¶ added in v3.0.1
OnMessage implements the OnMessage method of msgbus.
func (*WalHandler) ReadLast ¶
func (w *WalHandler) ReadLast() (*tbftengine.WalEntry, error)
ReadLast read the latest wal content
func (*WalHandler) Write ¶
func (w *WalHandler) Write(walEntry *tbftengine.WalEntry) error
Write a consensus state in wal