tbft_engine

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 1

README

长安链TBFT开源共识引擎

长安链TBFT共识引擎是长安链(ChainMaker)团队以TBFT共识算法作为核心自研的区块链共识算法引擎,它的目标是允许开发者轻松创建自己定义的基于TBFT共识算法的区块链,是长安链对区块链社区开源贡献的一部分。

长安链TBFT共识引擎专注于共识算法本身,不关心共识之外的其他实现,如网络通信、验签、共识内容、持久化等。开发者可以实现引擎对外提供的接口,启动自定义的节点,从而能够快速搭建一条基于TBFT共识算法实现的区块链。

Documentation

Index

Constants

View Source
const (
	// DefaultBlocksPerProposer The number of blocks each proposer can propose
	DefaultBlocksPerProposer = uint64(1)
	// TimeoutPrevote Timeout of waiting for >2/3 prevote
	TimeoutPrevote = 30 * time.Second
	// TimeoutPrevoteDelta Increased time delta of TimeoutPrevote between round
	TimeoutPrevoteDelta = 1 * time.Second
	// TimeoutPrecommit Timeout of waiting for >2/3 precommit
	TimeoutPrecommit = 30 * time.Second
	// TimeoutPrecommitDelta Increased time delta of TimeoutPrecommit between round
	TimeoutPrecommitDelta = 1 * time.Second
	// TimeoutCommit Timeout to wait for precommite
	TimeoutCommit = 30 * time.Second
	// TimeDisconnet the duration of node disconnectio(3000ms)
	TimeDisconnet = 3000
)
View Source
const (
	TypeRemoteTBFTState = 1
	TypeLocalTBFTState  = 2
)
View Source
const (
	// TimerInterval 定时器间隔
	TimerInterval = 500 * time.Millisecond
	// MessageBufferSize 缓存消息大小
	MessageBufferSize = 10240

	// StatusBroadcasterTbft TBFT状态广播器ID
	StatusBroadcasterTbft = "TBFT"
	// InterceptorTbft 标识
	InterceptorTbft = 0
)

Variables

View Source
var (
	ErrorInvalidParameter  = errors.New("invalid parameter")
	ErrorBroadcasterExist  = errors.New("broadcaster exist")
	ErrorDecoderExist      = errors.New("decoder exist")
	ErrorNetHandlerExist   = errors.New("netHandler exist")
	ErrorInterceptorExist  = errors.New("interceptor exist")
	ErrorRunRepeatedly     = errors.New("run repeatedly")
	ErrorNotRunning        = errors.New("not running")
	ErrorRemoterExist      = errors.New("remoter exist")
	ErrorRemoterNotExist   = errors.New("remoter not exist")
	ErrorRemoterEqualLocal = errors.New("remoter equal local")
)
View Source
var (
	ErrVoteNil              = errors.New("nil vote")
	ErrUnexceptedStep       = errors.New("unexpected step")
	ErrInvalidValidator     = errors.New("invalid validator")
	ErrVoteForDifferentHash = errors.New("vote for different hash")
)
View Source
var (
	ErrInvalidIndex = errors.New("invalid index")
)

Functions

func CurrentTimeMillisSeconds

func CurrentTimeMillisSeconds() int64

CurrentTimeMillisSeconds return current unix timestamp in milliseconds

func IsNil

func IsNil(i interface{}) bool

func NewValidatorSet

func NewValidatorSet(logger Logger, validators []string, blocksPerProposer uint64) *validatorSet

newValidatorSet @Description: create a new validator set @param logger @param validators @param blocksPerProposer @return *validatorSet

func NewVote

func NewVote(typ tbftpb.VoteType, voter string, height uint64, round int32, hash []byte) *tbftpb.Vote

NewVote create a new Vote instance

func VerifyRoundQc

func VerifyRoundQc(logger Logger, verifier Verifier,
	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 BatchMsg

type BatchMsg interface {
	// BatchMsg的索引
	Sequence() uint64
	// 获取BatchMsg的Key
	Key() []byte
	// 获取BatchMsg签名
	GetSetSignature() interface{}
	// 设置BatchMsg签名
	SetSignature(interface{})
}

共识内容

type BatchMsgInterpreter

type BatchMsgInterpreter interface {
	// TBFT引擎通过监听此chan, 获取一个BatchMsg进行共识
	PrepareBatchMsg() <-chan *ProposalBatchMsg
}

共识内容处理器 实现共识内容的定义

type BlockVotes

type BlockVotes struct {
	Votes map[string]*tbftpb.Vote
	Sum   uint64
}

BlockVotes traces the vote from different voter

func NewBlockVotes

func NewBlockVotes() *BlockVotes

NewBlockVotes creates a new BlockVotes instance

func (*BlockVotes) ToProto

func (bv *BlockVotes) ToProto() *tbftpb.BlockVotes

ToProto serializes the BlockVotes instance

type Broadcast

type Broadcast func(*Node, *Node) (interface{}, error)

Broadcast 广播器

type Coder

type Coder interface {
	// 实现Proposal的marshal
	MarshalProposal(*Proposal) ([]byte, error)
	// 实现Proposal的unmarshal
	UnmarshalProposal([]byte) (*Proposal, error)
}

共识Proposal处理器 实现共识内容的定义

type Committer

type Committer interface {
	// 提交batchMsg
	Commit(BatchMsg, *tbftpb.VoteSet) error
	// 完成batchMsg提交,通知共识开始下一个共识
	CommitDone() <-chan uint64
}

提交者(持久化)

type ConsensusEngine added in v1.0.2

type ConsensusEngine struct {
	sync.RWMutex

	// node id
	Id string

	// Current Consensus State
	*ConsensusState

	// channel for notifying the user of the completion of the commit
	CommitFinishC chan interface{}

	// Timeout = TimeoutPropose + TimeoutProposeDelta * round
	TimeoutPropose        time.Duration
	TimeoutProposeDelta   time.Duration
	TimeoutProposeOptimal time.Duration
	ProposeOptimal        bool
	ProposeOptimalTimer   *time.Timer
	// contains filtered or unexported fields
}

ConsensusEngine is the implementation of TBFT algorithm and it implements the ConsensusEngine interface.

func NewNode

func NewNode(logger Logger, id, chainId string, height uint64, validators []string) (*ConsensusEngine, error)

NewNode creates a tbft consensus instance

func (*ConsensusEngine) AddTimeout added in v1.0.2

func (consensus *ConsensusEngine) AddTimeout(duration time.Duration, height uint64, round int32,
	step tbftpb.Step)

AddTimeout adds timeout event to timeScheduler

func (*ConsensusEngine) CommitTimeout added in v1.0.2

func (consensus *ConsensusEngine) CommitTimeout(round int32) time.Duration

CommitTimeout returns timeout to wait for precommiting at `round`

func (*ConsensusEngine) Data added in v1.0.2

func (consensus *ConsensusEngine) Data() interface{}

Data @Description: return Status Data(ConsistentEngine) @receiver consensus @return interface{}

func (*ConsensusEngine) GetConsensusStateJSON added in v1.0.2

func (consensus *ConsensusEngine) GetConsensusStateJSON() ([]byte, error)

GetConsensusStateJSON @Description: Get consensus status in json format @receiver consensus @return []byte @return error always return nil

func (*ConsensusEngine) GetLastHeight added in v1.0.2

func (consensus *ConsensusEngine) GetLastHeight() uint64

GetLastHeight @Description: Get current height from consensus state @receiver consensus @return uint64

func (*ConsensusEngine) GetValidators added in v1.0.2

func (consensus *ConsensusEngine) GetValidators() ([]string, error)

GetValidators @Description: Get validators from consensus state @receiver consensus @return []string validators @return error always return nil

func (*ConsensusEngine) InitConsistentEngine added in v1.0.2

func (consensus *ConsensusEngine) InitConsistentEngine()

InitConsistentEngine @Description: Init ConsistentEngine @receiver consensus

func (*ConsensusEngine) NewTBFTProposal added in v1.0.2

func (consensus *ConsensusEngine) NewTBFTProposal(proposal *Proposal, marshal bool) *TBFTProposal

NewTBFTProposal create tbft proposal instance

func (*ConsensusEngine) PrecommitTimeout added in v1.0.2

func (consensus *ConsensusEngine) PrecommitTimeout(round int32) time.Duration

PrecommitTimeout returns timeout to wait for precommiting at `round`

func (*ConsensusEngine) PrevoteTimeout added in v1.0.2

func (consensus *ConsensusEngine) PrevoteTimeout(round int32) time.Duration

PrevoteTimeout returns timeout to wait for prevoting at `round`

func (*ConsensusEngine) ProposeState added in v1.0.2

func (consensus *ConsensusEngine) ProposeState() <-chan bool

func (*ConsensusEngine) ProposeTimeout added in v1.0.2

func (consensus *ConsensusEngine) ProposeTimeout(round int32) time.Duration

ProposeTimeout returns timeout to wait for proposing at `round`

func (*ConsensusEngine) RegisterCommitter added in v1.0.2

func (consensus *ConsensusEngine) RegisterCommitter(committer Committer) error

func (*ConsensusEngine) RegisterInterpreter added in v1.0.2

func (consensus *ConsensusEngine) RegisterInterpreter(batchMsgInterpreter BatchMsgInterpreter) error

func (*ConsensusEngine) RegisterLogger added in v1.0.2

func (consensus *ConsensusEngine) RegisterLogger(logger Logger) error

func (*ConsensusEngine) RegisterNetHandler added in v1.0.2

func (consensus *ConsensusEngine) RegisterNetHandler(netHandler NetHandler) error

func (*ConsensusEngine) RegisterParamsHandler added in v1.0.2

func (consensus *ConsensusEngine) RegisterParamsHandler(paramsHandler ParamsHandler) error

func (*ConsensusEngine) RegisterProposalCoder added in v1.0.2

func (consensus *ConsensusEngine) RegisterProposalCoder(proposalHandler Coder) error

func (*ConsensusEngine) RegisterVerifyHandler added in v1.0.2

func (consensus *ConsensusEngine) RegisterVerifyHandler(verifier Verifier) error

func (*ConsensusEngine) RegisterWalHandler added in v1.0.2

func (consensus *ConsensusEngine) RegisterWalHandler(walHandler WalHandler) error

func (*ConsensusEngine) RollBack added in v1.0.2

func (consensus *ConsensusEngine) RollBack() <-chan *ConsensusRollBack

func (*ConsensusEngine) Start added in v1.0.2

func (consensus *ConsensusEngine) Start(ctx context.Context) 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 (*ConsensusEngine) StartConsistentEngine added in v1.0.2

func (consensus *ConsensusEngine) StartConsistentEngine() error

StartConsistentEngine @Description: Start ConsistentEngine @receiver consensus

func (*ConsensusEngine) Status added in v1.0.2

func (consensus *ConsensusEngine) Status() *tbftpb.Status

func (*ConsensusEngine) Stop added in v1.0.2

func (consensus *ConsensusEngine) Stop() error

Stop implements the Stop method of ConsensusEngine interface.

func (*ConsensusEngine) ToProto added in v1.0.2

func (consensus *ConsensusEngine) ToProto() *tbftpb.ConsensusState

ToProto @Description: Copy *ConsensusState to *tbftpb.ConsensusState @receiver consensus @return *tbftpb.ConsensusState

func (*ConsensusEngine) Type added in v1.0.2

func (consensus *ConsensusEngine) Type() int8

Type @Description: return Status Type(ConsistentEngine) @receiver consensus @return int

func (*ConsensusEngine) Update added in v1.0.2

func (consensus *ConsensusEngine) Update(state Status)

Update @Description: Update state @receiver consensus @param state

type ConsensusFutureMsg

type ConsensusFutureMsg struct {
	Proposal map[int32]*Proposal
	// contains filtered or unexported fields
}

ConsensusFutureMsg @Description: represents the consensus msg of future

func NewConsensusFutureMsg

func NewConsensusFutureMsg(logger Logger, height uint64, round int32,
	validators *validatorSet) *ConsensusFutureMsg

NewConsensusFutureMsg creates a new future msg instance

type ConsensusFutureMsgCache

type ConsensusFutureMsgCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConsensusFutureMsgCache @Description: Cache future consensus msg

type ConsensusMsg

type ConsensusMsg struct {
	Type tbftpb.TBFTMsgType
	Msg  interface{}
}

type ConsensusRollBack

type ConsensusRollBack struct {
	Sequence      uint64
	Proposal      *Proposal
	VerifyFailTxs *VerifyFailTxs
}

type ConsensusState

type ConsensusState struct {

	// node id
	Id string
	// current height
	Height uint64
	// current round
	Round int32
	// current step
	Step tbftpb.Step

	// proposal
	Proposal *TBFTProposal
	// verifing proposal
	VerifingProposal *TBFTProposal
	LockedRound      int32
	// locked proposal
	LockedProposal *Proposal
	ValidRound     int32
	// valid proposal
	ValidProposal *Proposal
	// contains filtered or unexported fields
}

ConsensusState represents the consensus state of the node

func NewConsensusState

func NewConsensusState(logger Logger, id string) *ConsensusState

NewConsensusState creates a new ConsensusState instance

type ConsistentEngine

type ConsistentEngine interface {

	// Start 启动一致性引擎
	// ctx 后续扩展用,启动失败返回error
	Start(ctx context.Context) error

	// Stop 停止一致性引擎
	// ctx 后续扩展用,,停止失败返回error
	Stop(ctx context.Context) error

	// AddBroadcaster 添加状态广播器(如一个tbft状态广播器)
	// id 广播器标识,需要保证唯一性
	// broadcast 广播器,需要用户自己实现(如:tbft广播器、maxbft广播器)
	AddBroadcaster(id string, broadcast *StatusBroadcaster) error

	// UpdateNodeStatus 更新本地状态
	// id 节点标识,需要保证唯一性
	// node 需要更新的节点信息(包含节点状态,节点状态可以有多种)
	UpdateNodeStatus(id string, node *Node) error

	// PutRemoter 添加节点
	// id 节点标识,需要保证唯一性
	// node 需要添加的节点信息(包含节点状态,节点状态可以有多种)
	PutRemoter(id string, node *Node) error

	// RemoveRemoter 删除节点
	// id 节点标识,当节点不存在时返回错误消息
	RemoveRemoter(id string) error

	// RegisterStatusCoder 注册状态解析器
	// decoderType 解析器标识,需要保证唯一性
	// decoder 需要添加的解析器,由用户实现(如:tbft解析器)
	RegisterStatusCoder(decoderType int8, decoder *StatusDecoder) error

	// RegisterStatusInterceptor 注册过滤器
	// interceptorType 过滤器标识,需要保证唯一性
	// interceptor 需要添加的过滤器,由用户实现(如:tbft过滤器)
	RegisterStatusInterceptor(interceptorType int8, interceptor *StatusInterceptor) error
	//
	RegisterNetHandle(netHandler NetHandler) error
}

ConsistentEngine 一致性引擎,用于节点间(共识状态)信息同步

type CtxKey added in v1.0.2

type CtxKey string
const (
	ContextStartHeight CtxKey = "ContextStartHeight"
)

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
}

日志操作处理器

type Message

type Message interface {

	// Send 一致性引擎对外发送数据
	// payload 需要发送的消息
	Send(payload interface{})

	// Receive 一致性引擎接收外部数据
	// 返回接收到的消息
	Receive() interface{}

	AddNetMsg(interface{})
}

Message 用户一致性引擎于其他模块(如tbft/maxbft)数据交互

type NetHandler

type NetHandler interface {
	// 发送消息
	// to是发送给指导者,to为""则是广播给所有节点
	BroadCastNetMsg([]byte, string) error
	// TBFT引擎通过监听此chan,可以获取到接收到的网络消息
	Listen() <-chan interface{}
}

网络处理器 实现共识消息的收发处理

type Node

type Node struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Node 节点信息(local/remoter)

func (*Node) ID

func (l *Node) ID() string

func (*Node) Statuses

func (l *Node) Statuses() map[int8]Status

func (*Node) UpdateStatus

func (l *Node) UpdateStatus(s Status)

UpdateStatus 更新节点状态

type ParamsHandler

type ParamsHandler interface {
	// 新的一次共识开始时调用,获取共识需要的参数
	GetNewParams() (validators []string, timeoutPropose time.Duration,
		timeoutProposeDelta time.Duration, tbftBlocksPerProposer uint64,
		proposeOptimal bool, TimeoutProposeOptimal time.Duration, err error)
	GetLastBlockProposer() string
}

共识参数处理器 每次共识开始时的获取新的共识参数

type Proposal

type Proposal struct {
	Proposer  string
	Sequence  uint64
	Round     int32
	Content   BatchMsg
	Key       []byte
	Signature interface{}
	TxsRwSet  interface{}
	Qc        []*tbftpb.Vote
}

Proposal defined a consesensus proposal which can be gossiped to other node and can be serilized for persistent store.

func NewProposal

func NewProposal(voter string, height uint64, round int32, key []byte, content BatchMsg) *Proposal

NewProposal create a new Proposal

type ProposalBatchMsg

type ProposalBatchMsg struct {
	BatchMsg    BatchMsg
	CutBatchMsg BatchMsg
	TxsRwSet    interface{}
}

type RemoteState

type RemoteState struct {
	sync.RWMutex
	//node id
	Id string
	//current height
	Height uint64
	// current round
	Round int32
	// current step
	Step tbftpb.Step

	// proposal
	Proposal         []byte
	VerifingProposal []byte
	LockedRound      int32
	// locked proposal
	LockedProposal *tbftpb.Proposal
	ValidRound     int32
	// valid proposal
	ValidProposal *tbftpb.Proposal
	RoundVoteSet  *roundVoteSet
}

RemoteState @Description: Validator status, validator and remote are the same

func (*RemoteState) Data

func (r *RemoteState) Data() interface{}

func (*RemoteState) Type

func (r *RemoteState) Type() int8

func (*RemoteState) Update

func (r *RemoteState) Update(state Status)

type Status

type Status interface {

	// Type 状态类型
	Type() int8

	// Data 状态内容
	Data() interface{}

	// Update 更新状态
	Update(status Status)
}

Status 节点共识状态

type StatusBroadcaster

type StatusBroadcaster struct {
	// contains filtered or unexported fields
}

func NewTBFTStatusBroadcaster

func NewTBFTStatusBroadcaster(log Logger) *StatusBroadcaster

func (*StatusBroadcaster) ID

func (tsb *StatusBroadcaster) ID() string

func (*StatusBroadcaster) IsRunning

func (tsb *StatusBroadcaster) IsRunning() bool

func (*StatusBroadcaster) PreBroadcaster

func (tsb *StatusBroadcaster) PreBroadcaster() Broadcast

PreBroadcaster 消息广播前做前置处理,如状态校验/判断是否要发送消息等

func (*StatusBroadcaster) Start

func (tsb *StatusBroadcaster) Start() error

func (*StatusBroadcaster) Stop

func (tsb *StatusBroadcaster) Stop() error

func (*StatusBroadcaster) TimePattern

func (tsb *StatusBroadcaster) TimePattern() interface{}

TimePattern 状态广播触发模式

type StatusConsistentEngine

type StatusConsistentEngine struct {
	// contains filtered or unexported fields
}

StatusConsistentEngine 一致性引擎实现

func NewConsistentService

func NewConsistentService(local *Node,
	msg Message,
	log Logger) *StatusConsistentEngine

NewConsistentService nolint: unused

func (*StatusConsistentEngine) AddBroadcaster

func (e *StatusConsistentEngine) AddBroadcaster(id string, broadcaster *StatusBroadcaster) error

func (*StatusConsistentEngine) PutRemoter

func (e *StatusConsistentEngine) PutRemoter(id string, node *Node) error

func (*StatusConsistentEngine) RegisterNetHandle

func (e *StatusConsistentEngine) RegisterNetHandle(netHandler NetHandler) error

func (*StatusConsistentEngine) RegisterStatusCoder

func (e *StatusConsistentEngine) RegisterStatusCoder(decoder *StatusDecoder) error

func (*StatusConsistentEngine) RegisterStatusInterceptor

func (e *StatusConsistentEngine) RegisterStatusInterceptor(interceptorType int8, interceptor *StatusInterceptor) error

func (*StatusConsistentEngine) RemoveRemoter

func (e *StatusConsistentEngine) RemoveRemoter(id string) error

func (*StatusConsistentEngine) Start

func (*StatusConsistentEngine) Stop

func (*StatusConsistentEngine) UpdateNodeStatus

func (e *StatusConsistentEngine) UpdateNodeStatus(id string, node *Node) error

UpdateNodeStatus 更新本地状态

type StatusDecoder

type StatusDecoder struct {
	// contains filtered or unexported fields
}

func (*StatusDecoder) Decode

func (tD *StatusDecoder) Decode(d interface{}) interface{}

Decode 解析消息,返回节点状态

type StatusInterceptor

type StatusInterceptor struct {
}

func (*StatusInterceptor) Handle

func (tsb *StatusInterceptor) Handle(status Status) error

type TBFTConsensuEngine

type TBFTConsensuEngine interface {
	// 开始
	Start(ctx context.Context) error
	// 结束
	Stop() error
	// 注册网络处理器
	RegisterNetHandler(NetHandler) error
	// 注册共识内容处理器
	RegisterInterpreter(BatchMsgInterpreter) error
	// 注册共识验证器
	RegisterVerifyHandler(Verifier) error
	// 注册wal处理器
	RegisterWalHandler(WalHandler) error
	// 注册提交处理器
	RegisterCommitter(Committer) error
	// 注册日志处理器
	RegisterLogger(Logger) error
	// 注册共识参数处理器
	RegisterParamsHandler(ParamsHandler) error
	// 注册共识Proposal处理器
	RegisterProposalCoder(Coder) error
	// 获取共识状态
	Status() *tbftpb.Status
	// 通知调用者发起提案
	ProposeState() <-chan bool
	// 通知调用者这一轮共识失败
	RollBack() <-chan *ConsensusRollBack
}

TBFTConsensuEngine tbft共识算法引擎接口

type TBFTProposal

type TBFTProposal struct {
	PbMsg *Proposal
	// byte format *tbftpb.Proposal
	Bytes []byte
}

type TbftConsistentMessage

type TbftConsistentMessage struct {
	// contains filtered or unexported fields
}

func NewTbftConsistentMessage

func NewTbftConsistentMessage(log Logger, netHandler NetHandler) *TbftConsistentMessage

func (*TbftConsistentMessage) AddNetMsg

func (m *TbftConsistentMessage) AddNetMsg(payload interface{})

func (*TbftConsistentMessage) OnQuit

func (m *TbftConsistentMessage) OnQuit()

func (*TbftConsistentMessage) Receive

func (m *TbftConsistentMessage) Receive() interface{}

func (*TbftConsistentMessage) Send

func (m *TbftConsistentMessage) Send(payload interface{})

type Verifier

type Verifier interface {
	// 对Proposal签名
	SignProposal(*Proposal) (interface{}, error)
	// 对BatchMsg签名
	SignBatchMsg(BatchMsg) (interface{}, error)
	// 对vote签名
	SignVote(*tbftpb.Vote) ([]byte, error)
	// 验证Proposal
	VerifyProposal(*Proposal) error
	// 验证BatchMsg
	VerifyBatchMsg(BatchMsg) (*VerifyResult, error)
	// 通过读写集验证BatchMsg
	VerifyBlockWithRwSets(BatchMsg, interface{}, *tbftpb.VoteSet) error
	// 验证vote
	VerifyVote(*tbftpb.Vote) error
}

共识验证器 实现Proposal和Vote的签名和验签

type VerifyFailTxs

type VerifyFailTxs struct {
	Sequence  uint64
	BlockHash []byte
	TxIds     []string
}

type VerifyResult

type VerifyResult struct {
	VerifiedBatchMsg BatchMsg
	Code             tbftpb.VerifyResult_Code
	Msg              string
	TxsRwSet         interface{}
	VerifyFailTxs    []string
}

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, voteType tbftpb.VoteType, height uint64, round int32,
	validators *validatorSet) *VoteSet

NewVoteSet creates a new VoteSet instance

func NewVoteSetFromProto

func NewVoteSetFromProto(logger Logger, vsProto *tbftpb.VoteSet, validators *validatorSet) *VoteSet

NewVoteSetFromProto creates a new VoteSet instance from pb

func VerifyQcFromVotes

func VerifyQcFromVotes(logger Logger, verifier Verifier, vs []*tbftpb.Vote,
	validators *validatorSet, voteType tbftpb.VoteType) (*VoteSet, error)

VerifyQcFromVotes verifies whether the signatures in votes verify that the maj32 of the votes error when verify successfully, and return corresponding error when failed.

func (*VoteSet) AddVote

func (vs *VoteSet) AddVote(vote *tbftpb.Vote, countInvalidTx bool) (added bool, err error)

AddVote adds a vote to the VoteSet

func (*VoteSet) AddVoteForConsistent

func (vs *VoteSet) AddVoteForConsistent(vote *tbftpb.Vote) (added bool, err error)

AddVoteForConsistent adds a vote to the VoteSet

func (*VoteSet) HasTwoThirdsMajority

func (vs *VoteSet) HasTwoThirdsMajority() (majority bool)

HasTwoThirdsMajority shoule used when the mutex has been lock

func (*VoteSet) Size

func (vs *VoteSet) Size() int32

Size returns the size of the VoteSet

func (*VoteSet) String

func (vs *VoteSet) String() string

func (*VoteSet) ToProto

func (vs *VoteSet) ToProto() *tbftpb.VoteSet

ToProto serializes the VoteSet instance

type WalEntry

type WalEntry struct {
	WalEntryType tbftpb.WalEntryType
	Sequence     uint64
	Proposal     *Proposal
}

WalEntry defined wal types

type WalHandler

type WalHandler interface {
	Write(*WalEntry) error
	// 读取一个最新的wal内容
	// tbft引擎启动时恢复只需要一个最新的wal内容
	ReadLast() (*WalEntry, error)
}

wal处理器 实现读写共识消息的wal操作

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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