tbft

package module
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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")
)
View Source
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"
)
View Source
var AdditionalDataKey = "TBFTAddtionalDataKey"

AdditionalDataKey implements the block key for store tbft infos

View Source
var TBFTAddtionalDataKey = "TBFTAddtionalDataKey"

TBFTAddtionalDataKey implements the block key for store tbft infos

Functions

func CopyBlock added in v3.0.1

func CopyBlock(block *common.Block) *common.Block

CopyBlock generates a new block with a old block, internally using the same pointer

func CopyProposalWithBlockHeader

func CopyProposalWithBlockHeader(p *tbftpb.Proposal) *tbftpb.Proposal

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) Key

func (b *BatchMsg) Key() []byte

Key return key of BatchMsg

func (*BatchMsg) Sequence

func (b *BatchMsg) Sequence() uint64

Sequence return sequence of BatchMsg

func (*BatchMsg) SetSignature

func (b *BatchMsg) SetSignature(sign interface{})

SetSignature set BatchMsg sign

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) Close

func (c *Committer) Close()

Close cloe the Committer

func (*Committer) Commit

func (c *Committer) Commit(batchMsg tbftengine.BatchMsg, voteSet *tbftpb.VoteSet) error

Commit commit consensus object

func (*Committer) CommitDone

func (c *Committer) CommitDone() <-chan uint64

CommitDone complete the batchMsg commit and notify the consensus to start the next consensus

func (*Committer) MsgTopic added in v3.0.1

func (c *Committer) MsgTopic() msgbus.Topic

MsgTopic indicated the committer need to receive blockInfo

func (*Committer) Name

func (c *Committer) Name() string

Name return Committer name

func (*Committer) OnMessage

func (c *Committer) OnMessage(message *msgbus.Message)

OnMessage received msg from handlerManager.

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

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

type Handler interface {
	Name() string
	MsgTopic() msgbus.Topic
	OnMessage(*msgbus.Message)
	Close()
}

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) Close

func (n *NetHandler) Close()

Close cloe the NetHandler

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) Name

func (n *NetHandler) Name() string

Name return NetHandler name

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) Close

func (p *ParamsHandler) Close()

Close cloe the ParamsHandler

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

func (nh *ParamsHandler) MsgTopic() msgbus.Topic

MsgTopic indicated the handler need to receive nothing

func (*ParamsHandler) Name

func (p *ParamsHandler) Name() string

Name return ParamsHandler name

func (*ParamsHandler) OnMessage added in v3.0.1

func (nh *ParamsHandler) OnMessage(message *msgbus.Message)

OnMessage implements the OnMessage method of msgbus.

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) Close

func (p *ProposalHandler) Close()

Close cloe the ProposalHandler

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

func (nh *ProposalHandler) MsgTopic() msgbus.Topic

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

func (nh *ProposalHandler) OnMessage(message *msgbus.Message)

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) Close

func (v *Verifier) Close()

Close cloe the Verifier

func (*Verifier) MsgTopic added in v3.0.1

func (v *Verifier) MsgTopic() msgbus.Topic

MsgTopic indicated the Verifier need to receive VerifyResult

func (*Verifier) Name

func (v *Verifier) Name() string

Name return Verifier name

func (*Verifier) OnMessage

func (v *Verifier) OnMessage(message *msgbus.Message)

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

func (v *Verifier) SignVote(vote *enginePb.Vote) ([]byte, error)

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

func (*Verifier) VerifyVote

func (v *Verifier) VerifyVote(voteProto *enginePb.Vote) error

VerifyVote verify the vote

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) Close

func (w *WalHandler) Close()

Close cloe the WalHandler

func (*WalHandler) MsgTopic added in v3.0.1

func (nh *WalHandler) MsgTopic() msgbus.Topic

MsgTopic indicated the handler need to receive nothing

func (*WalHandler) Name

func (w *WalHandler) Name() string

Name return WalHandler name

func (*WalHandler) OnMessage added in v3.0.1

func (nh *WalHandler) OnMessage(message *msgbus.Message)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL