chained_bft

package
v0.0.0-...-56f3d1a Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

View Source
const (
	StrictInternal     = 3
	PermissiveInternal = 6
)
View Source
const (
	// DefaultNetMsgChanSize is the default size of network msg channel
	DefaultNetMsgChanSize = 1000
)

Variables

View Source
var (
	EmptyVoteSignErr   = errors.New("No signature in vote.")
	InvalidVoteAddr    = errors.New("Vote address is not a validator in the target validators.")
	InvalidVoteSign    = errors.New("Vote sign is invalid compared with its publicKey")
	TooLowVoteView     = errors.New("Vote received is lower than local lastVoteRound.")
	TooLowVParentView  = errors.New("Vote's parent received is lower than local preferredRound.")
	TooLowProposalView = errors.New("Proposal received is lower than local lastVoteRound.")
	EmptyParentQC      = errors.New("Parent qc is empty.")
	NoEnoughVotes      = errors.New("Parent qc doesn't have enough votes.")
	EmptyParentNode    = errors.New("Parent's node is empty.")
	EmptyValidators    = errors.New("Justify validators are empty.")
)
View Source
var (
	ErrTooLowNewView      = errors.New("nextView is lower than local pacemaker's currentView")
	ErrP2PInternalErr     = errors.New("internal err in p2p module")
	ErrTooLowNewProposal  = errors.New("proposal is lower than local pacemaker's currentView")
	ErrEmptyHighQC        = errors.New("no valid highQC in qcTree")
	ErrSameProposalNotify = errors.New("same proposal has been made")
	ErrJustifyVotesEmpty  = errors.New("justify qc's votes are empty")
	ErrEmptyTarget        = errors.New("target parameter is empty")
	ErrRegisterErr        = errors.New("register to p2p error")
)
View Source
var (
	ErrNilQC = errors.New("pacemaker meets a nil qc")
)

Functions

This section is empty.

Types

type DefaultPaceMaker

type DefaultPaceMaker struct {
	CurrentView int64
}

DefaultPaceMaker 是一个PacemakerInterface的默认实现,我们与PacemakerInterface放置在一起,方便查看 PacemakerInterface的新实现直接直接替代DefaultPaceMaker即可 The Pacemaker keeps track of votes and of time. TODO: the Pacemaker broadcasts a TimeoutMsg notification.

func (*DefaultPaceMaker) AdvanceView

func (p *DefaultPaceMaker) AdvanceView(qc storage.QuorumCertInterface) (bool, error)

func (*DefaultPaceMaker) GetCurrentView

func (p *DefaultPaceMaker) GetCurrentView() int64

type DefaultSaftyRules

type DefaultSaftyRules struct {
	Crypto *cCrypto.CBFTCrypto
	QcTree *storage.QCPendingTree

	Log logs.Logger
	// contains filtered or unexported fields
}

func (*DefaultSaftyRules) CalVotesThreshold

func (s *DefaultSaftyRules) CalVotesThreshold(input, sum int) bool

func (*DefaultSaftyRules) CheckPacemaker

func (s *DefaultSaftyRules) CheckPacemaker(pending int64, local int64) bool

CheckPacemaker 注意: 由于本smr支持不同节点产生同一round, 因此下述round比较和leader比较与原文(验证Proposal的Round是否和pacemaker的Round相等)并不同。 仅需proposal round不超过范围即可

func (*DefaultSaftyRules) CheckProposal

func (s *DefaultSaftyRules) CheckProposal(proposal, parent storage.QuorumCertInterface, justifyValidators []string) error

CheckProposalMsg 原IsQuorumCertValidate 判断justify,即需check的block的parentQC是否合法 需要注意的是,在上层bcs的实现中,由于共识操纵了账本回滚。因此实际上safetyrules需要proposalRound和parentRound严格相邻的 因此在此proposal和parent的QC稍微宽松检查

func (*DefaultSaftyRules) CheckVote

func (s *DefaultSaftyRules) CheckVote(qc storage.QuorumCertInterface, logid string, validators []string) error

CheckVote 检查logid、voteInfoHash是否正确

func (*DefaultSaftyRules) UpdatePreferredRound

func (s *DefaultSaftyRules) UpdatePreferredRound(round int64) bool

func (*DefaultSaftyRules) VoteProposal

func (s *DefaultSaftyRules) VoteProposal(proposalId []byte, proposalRound int64, parentQc storage.QuorumCertInterface) bool

VoteProposal 返回是否需要发送voteMsg给下一个Leader DefaultSaftyRules 并没有严格比对proposalRound和parentRound的相邻自增关系 但需要注意的是,在上层bcs的实现中,由于共识操纵了账本回滚。因此实际上safetyrules需要proposalRound和parentRound严格相邻的 因此由于账本的可回滚性,因此lastVoteRound和preferredRound比对时,仅需比对新来的数据是否小于local数据-3即可 此处-3代表数据已经落盘

type PacemakerInterface

type PacemakerInterface interface {
	// CurrentView return current view of this node.
	GetCurrentView() int64
	// 原NextNewProposal,generate new proposal directly.
	AdvanceView(qc storage.QuorumCertInterface) (bool, 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 entirely decoupled from liveness by any potential instantiation of Packmaker. Different consensus have different pacemaker implement

type ProposerElectionInterface

type ProposerElectionInterface interface {
	// 获取指定round的主节点Address, 注意, 若存在validators变更, 则需要在此处进行addrToIntAddr的更新操作
	GetLeader(round int64) string
	// 获取指定round的候选人节点Address
	GetValidators(round int64) []string
}

type Smr

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

smr 组装了三个模块: pacemaker、saftyrules和propose election smr有自己的存储即PendingTree 原本的ChainedBft(联结smr和本地账本,在preferredVote被确认后, 触发账本commit操作) 被替代成smr和上层bcs账本的·组合实现,以减少不必要的代码,考虑到chained-bft暂无扩展性 注意:本smr的round并不是强自增唯一的,不同节点可能产生相同round(考虑到上层账本的块可回滚)

func NewSmr

func NewSmr(bcName, address string, log logs.Logger, p2p cctx.P2pCtxInConsensus, cryptoClient *cCrypto.CBFTCrypto, pacemaker PacemakerInterface,
	saftyrules saftyRulesInterface, election ProposerElectionInterface, qcTree *storage.QCPendingTree) *Smr

func (*Smr) CheckProposal

func (s *Smr) CheckProposal(block cctx.BlockInterface, justify storage.QuorumCertInterface, validators []string) error

func (*Smr) GetAddress

func (s *Smr) GetAddress() string

func (*Smr) GetCurrentView

func (s *Smr) GetCurrentView() int64

func (*Smr) GetRootQC

func (s *Smr) GetRootQC() storage.QuorumCertInterface

GetRootQC 查询状态树的Root节点,Root节点已经被账本commit

func (*Smr) KeepUpWithBlock

func (s *Smr) KeepUpWithBlock(block cctx.BlockInterface, justify storage.QuorumCertInterface, validators []string) error

func (*Smr) LoadVotes

func (s *Smr) LoadVotes(proposalId []byte, signs []*chainedBftPb.QuorumCertSign)

func (*Smr) ProcessProposal

func (s *Smr) ProcessProposal(viewNumber int64, proposalID []byte, parentID []byte, validatesIpInfo []string) error

ProcessProposal 即Chained-HotStuff的NewView阶段,LibraBFT的process_proposal阶段 对于一个认为自己当前是Leader的节点,它试图生成一个新的提案,即一个新的QC,并广播 本节点产生一个Proposal,该proposal包含一个最新的round, 最新的proposalId,一个parentQC,并将该消息组合成一个ProposalMsg消息给所有节点 全部完成后leader更新本地localProposal

func (*Smr) RegisterToNetwork

func (s *Smr) RegisterToNetwork() error

RegisterToNetwork register msg handler to p2p network

func (*Smr) ResetProposerStatus

func (s *Smr) ResetProposerStatus(tipBlock cctx.BlockInterface,
	queryBlockFunc func(blkId []byte) (ledger.BlockHandle, error),
	validators []string) (bool, storage.QuorumCertInterface, error)

func (*Smr) Start

func (s *Smr) Start()

Start used to start smr instance and process msg

func (*Smr) Stop

func (s *Smr) Stop()

stop used to stop smr instance

func (*Smr) UnRegisterToNetwork

func (s *Smr) UnRegisterToNetwork()

UnRegisterToNetwork unregister msg handler to p2p network

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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