forest

package
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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProposalData

func NewProposalData(parentBlkView, currBlkView, blkHeight uint64, blkHash, preBlkHash string) *maxbft.ProposalData

NewProposalData constructs and returns a new mock proposal

Types

type AddedEventFunc

type AddedEventFunc func(proposal *ProposalContainer)

AddedEventFunc 有添加提案事件发生时,回调的监听事件处理器

type BlockContainer

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

BlockContainer used to assemble a block and its corresponding qc

func NewBlockContainer

func NewBlockContainer(block *common.Block) *BlockContainer

NewBlockContainer returns a new BlockContainer object

func (*BlockContainer) GetBlock

func (c *BlockContainer) GetBlock() *common.Block

GetBlock gets the block from the BlockContainer

func (*BlockContainer) GetQC

func (c *BlockContainer) GetQC() *maxbft.QuorumCert

GetQC gets the qc from the BlockContainer

func (*BlockContainer) Hash

func (c *BlockContainer) Hash() []byte

Hash returns the block hash

func (*BlockContainer) Height

func (c *BlockContainer) Height() uint64

Height returns the block height

func (*BlockContainer) Key

func (c *BlockContainer) Key() string

Key returns the string of the block hash

func (*BlockContainer) SetQC

func (c *BlockContainer) SetQC(justifyQC *maxbft.QuorumCert)

SetQC sets a qc for the BlockContainer

func (*BlockContainer) View

func (c *BlockContainer) View() uint64

View returns the qc view from the BlockContainer

type CachedForest

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

CachedForest 基于cache实现的forest

func NewForest

func NewForest(root *CachedForestNode, commiter protocol.BlockCommitter, logger protocol.Logger) *CachedForest

NewForest initials and returns a new CachedForest object

func (*CachedForest) AddPendingProposal

func (f *CachedForest) AddPendingProposal(proposal *maxbft.ProposalData)

AddPendingProposal add proposal that the consensus engine is working on

func (*CachedForest) AddProposal

func (f *CachedForest) AddProposal(proposal *maxbft.ProposalData, replay bool) error

AddProposal adds proposal to forest

func (*CachedForest) DelPendingProposal

func (f *CachedForest) DelPendingProposal(blkHash string)

DelPendingProposal after the proposal is processed, delete the record

func (*CachedForest) FinalView

func (f *CachedForest) FinalView() uint64

FinalView 返回FinalView

func (*CachedForest) GetFinalBlock

func (f *CachedForest) GetFinalBlock() *BlockContainer

GetFinalBlock 返回finalQC

func (*CachedForest) GetGenericHeight

func (f *CachedForest) GetGenericHeight() uint64

GetGenericHeight 返回forest当前缓存的最高提案高度

func (*CachedForest) GetGenericQC

func (f *CachedForest) GetGenericQC() *maxbft.QuorumCert

GetGenericQC 返回GenericQC

func (*CachedForest) GetLatest3Ancestors

func (f *CachedForest) GetLatest3Ancestors(proposal *maxbft.ProposalData) []ForestNoder

GetLatest3Ancestors Gets the last three uncommitted ancestor blocks of the node The number of ancestors may be less than 3 or there are no uncommitted ancestor blocks for current proposal

func (*CachedForest) GetLockedQC

func (f *CachedForest) GetLockedQC() *BlockContainer

GetLockedQC 返回LockedQC

func (*CachedForest) GetProposalByHash

func (f *CachedForest) GetProposalByHash(blockId string) *maxbft.ProposalData

GetProposalByHash 依据blockId查询提案

func (*CachedForest) GetProposalByView

func (f *CachedForest) GetProposalByView(view uint64) *maxbft.ProposalData

GetProposalByView 根据视图获取对应的提案,不存在则返回nil

func (*CachedForest) HasProposal

func (f *CachedForest) HasProposal(blockID string) bool

HasProposal 判断指定Proposal是否存在

func (*CachedForest) IsProposalPending added in v3.0.1

func (f *CachedForest) IsProposalPending(blkHash string) bool

IsProposalPending checks the proposal specified by the given block hash is in processing or not

func (*CachedForest) Node

func (f *CachedForest) Node(key string) ForestNoder

Node 获取指定节点

func (*CachedForest) RegisterAddedEventFunc

func (f *CachedForest) RegisterAddedEventFunc(fn AddedEventFunc)

RegisterAddedEventFunc 注册添加区块事件函数

func (*CachedForest) RegisterFinalEventFunc

func (f *CachedForest) RegisterFinalEventFunc(fn FinalEventFunc)

RegisterFinalEventFunc 注册Final区块事件函数

func (*CachedForest) Root

func (f *CachedForest) Root() ForestNoder

Root 返回根节点

func (*CachedForest) Start

func (f *CachedForest) Start()

Start the service in the background

func (*CachedForest) Stop

func (f *CachedForest) Stop()

Stop Close the channel to exit goroutine inside the component

func (*CachedForest) SwitchEpoch

func (f *CachedForest) SwitchEpoch(root *CachedForestNode)

SwitchEpoch Sets the state of the new epoch

func (*CachedForest) UpdateStatesByProposal

func (f *CachedForest) UpdateStatesByProposal(proposal *maxbft.ProposalData, validBlock bool) (
	[]*ProposalContainer, error)

UpdateStatesByProposal 使用提案携带的QC更新forest状态

func (*CachedForest) UpdateStatesByQC

func (f *CachedForest) UpdateStatesByQC(qc *maxbft.QuorumCert) error

UpdateStatesByQC 使用QC更新状态

type CachedForestNode

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

CachedForestNode defines a forest node

func NewCachedForestNode

func NewCachedForestNode(data *ProposalContainer) *CachedForestNode

NewCachedForestNode initials and returns a new CachedForestNode object

func (*CachedForestNode) AddChild

func (n *CachedForestNode) AddChild(child ForestNoder)

AddChild adds a child node to a forest node

func (*CachedForestNode) Children

func (n *CachedForestNode) Children() []ForestNoder

Children returns all children of a forest node

func (*CachedForestNode) ClearChildren

func (n *CachedForestNode) ClearChildren()

ClearChildren clears all children of a forest node

func (*CachedForestNode) Data

Data returns the data of a forest node

func (*CachedForestNode) FromOtherNodes

func (n *CachedForestNode) FromOtherNodes() bool

FromOtherNodes returns that the node is from other nodes' response or not

func (*CachedForestNode) Height

func (n *CachedForestNode) Height() uint64

Height returns the block height of a forest node

func (*CachedForestNode) Key

func (n *CachedForestNode) Key() string

Key returns the string of the block hash of the forest node

func (*CachedForestNode) Parent

func (n *CachedForestNode) Parent() ForestNoder

Parent returns the parent node of the forest node

func (*CachedForestNode) ParentKey

func (n *CachedForestNode) ParentKey() string

ParentKey returns the string of the pre block hash of the forest node

func (*CachedForestNode) SetParent

func (n *CachedForestNode) SetParent(parent ForestNoder)

SetParent sets parent node of a forest node

func (*CachedForestNode) View

func (n *CachedForestNode) View() uint64

View returns the view of a forest node

type FinalEventFunc

type FinalEventFunc func(proposal *ProposalContainer)

FinalEventFunc 有提交事件发生时,回调的监听事件处理器

type ForestNoder

type ForestNoder interface {
	// AddChild 添加子节点
	AddChild(child ForestNoder)

	// ClearChildren 清理所有子节点
	ClearChildren()

	// SetParent 设置当前节点的父节点
	// 可以设置为nil
	SetParent(parent ForestNoder)

	// Parent 返回当前节点父节点
	Parent() ForestNoder

	// Data 返回节点中存储的数据
	Data() *ProposalContainer

	// Children 返回节点所有的子节点集合
	Children() []ForestNoder

	// Key 返回当前节点的Key
	Key() string

	// ParentKey 返回节点的父Key
	ParentKey() string

	Height() uint64

	View() uint64
}

ForestNoder defines a forest node

type Forester

type Forester interface {
	// Stop exit goroutine inside the component
	Stop()
	Start()

	// RegisterFinalEventFunc 注册final事件函数
	RegisterFinalEventFunc(fn FinalEventFunc)

	// RegisterAddedEventFunc 注册添加的事件函数
	RegisterAddedEventFunc(fn AddedEventFunc)

	// GetGenericQC 返回GenericQC
	GetGenericQC() *maxbft.QuorumCert

	// GetGenericHeight 返回当前区块高度,正常情况下当前区块高度等于GenericQC的高度+1
	// 在以下两种情况下,当前区块高度与GenericQC的高度一致:
	// 1)初始化的时候
	// 2)随GenericQC一起收到的proposal没有被验证通过的时候
	GetGenericHeight() uint64

	// GetLockedQC 返回LockedQC
	GetLockedQC() *BlockContainer

	// GetFinalBlock 返回FinalBlock
	GetFinalBlock() *BlockContainer

	// FinalView 返回Final视图ID
	FinalView() uint64

	// HasProposal 判断blockID对应提案是否存在
	HasProposal(blockID string) bool

	// GetProposalByView 根据视图获取提案
	GetProposalByView(view uint64) *maxbft.ProposalData

	// GetProposalByHash 依据blockId获取提案
	GetProposalByHash(blockId string) *maxbft.ProposalData

	// GetLatest3Ancestors Gets the last three uncommitted ancestor blocks of the node
	// The number of ancestors may be less than 3 or there are no uncommitted ancestor
	// blocks for current proposal
	GetLatest3Ancestors(proposal *maxbft.ProposalData) []ForestNoder

	// Node 返回节点
	Node(key string) ForestNoder

	// Root 返回根节点
	Root() ForestNoder

	// UpdateStatesByProposal 仅使用提案携带的QC更新共识状态,并不将提案添加到forest中,
	// 更新genericQC、lockedQC、 提交符合three-chain的区块,更新finalQC,返回被提交的区块数据
	// 若ProposalContainer数组为空表示没有提交任何区块,不为空表示提交了部分区块。
	// 或当提案的父块不存在时,返回错误
	UpdateStatesByProposal(proposal *maxbft.ProposalData, validBlock bool) ([]*ProposalContainer, error)

	// AddProposal 添加提案,
	// replay true表示提案加载自wal,false表示提案从共识流程中获得
	AddProposal(proposal *maxbft.ProposalData, replay bool) error

	// UpdateStatesByQC 将QC添加至它对应的区块中,更新genericQC
	UpdateStatesByQC(qc *maxbft.QuorumCert) error

	// SwitchEpoch Set the state of the new epoch
	SwitchEpoch(root *CachedForestNode)

	//	DelPendingProposal After the proposal is processed, delete the record
	DelPendingProposal(blkHash string)

	//	AddPendingProposal Add proposal that the consensus engine is working on
	AddPendingProposal(proposal *maxbft.ProposalData)

	// IsProposalPending checks the proposal with a specified block hash is in processing or not
	IsProposalPending(blkHash string) bool
}

Forester defines a nodes forest to maintain proposals that have been preliminary processed

type InnerNodeCache

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

InnerNodeCache defines an inner node cache

func NewInnerNodeCache

func NewInnerNodeCache() *InnerNodeCache

NewInnerNodeCache returns a new InnerNodeCache

func (*InnerNodeCache) AddNode

func (c *InnerNodeCache) AddNode(node ForestNoder)

AddNode adds a node to the cache

func (*InnerNodeCache) Delete

func (c *InnerNodeCache) Delete(key string, view uint64)

Delete deletes a node from the cache

func (*InnerNodeCache) NodeByHash

func (c *InnerNodeCache) NodeByHash(hash string) ForestNoder

NodeByHash returns the node with the specified block hash

func (*InnerNodeCache) NodeByView

func (c *InnerNodeCache) NodeByView(view uint64) ForestNoder

NodeByView returns the node with the specified view

type ProposalContainer

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

ProposalContainer used to assemble a proposal and its corresponding BlockContainer

func GenesisProposalContainer

func GenesisProposalContainer() *ProposalContainer

GenesisProposalContainer genesis a mock proposal container

func NewProposalContainer

func NewProposalContainer(proposal *maxbft.ProposalData, useQC bool, fromOtherNodes bool) *ProposalContainer

NewProposalContainer 创建ProposalContainer useQC表示是否使用该proposal中的QC,通常是不使用的,仅仅当该proposal已经在账本中,并且是第一次加载时使用

func (*ProposalContainer) BlockContainer

func (p *ProposalContainer) BlockContainer() *BlockContainer

BlockContainer returns the block container of the proposal container

func (*ProposalContainer) GetProposalQC

func (p *ProposalContainer) GetProposalQC() *maxbft.QuorumCert

GetProposalQC returns the justify qc of the proposal in the container

func (*ProposalContainer) GetProposalQCHeight

func (p *ProposalContainer) GetProposalQCHeight() uint64

GetProposalQCHeight returns the qc height of the container

func (*ProposalContainer) GetProposalQCView

func (p *ProposalContainer) GetProposalQCView() uint64

GetProposalQCView returns the qc view of the container

func (*ProposalContainer) Height

func (p *ProposalContainer) Height() uint64

Height returns the block height of the container

func (*ProposalContainer) Key

func (p *ProposalContainer) Key() string

Key returns the block hash string

func (*ProposalContainer) ParentKey

func (p *ProposalContainer) ParentKey() string

ParentKey returns the pre block hash string

func (*ProposalContainer) Proposal

func (p *ProposalContainer) Proposal() *maxbft.ProposalData

Proposal returns the proposal of the container

func (*ProposalContainer) ProposalData

func (p *ProposalContainer) ProposalData() *maxbft.ProposalData

ProposalData returns the proposal of the container

func (*ProposalContainer) UpdateChildProposal

func (p *ProposalContainer) UpdateChildProposal(childProposal *ProposalContainer)

UpdateChildProposal updates qc by a child proposal's justify qc

func (*ProposalContainer) UpdateQC

func (p *ProposalContainer) UpdateQC(qc *maxbft.QuorumCert)

UpdateQC updates qc in the container

func (*ProposalContainer) View

func (p *ProposalContainer) View() uint64

View returns the view of the proposal in the container

type ProposalLivenessAndSafeCheckError

type ProposalLivenessAndSafeCheckError struct {
	// 区块高度
	BlockHeight uint64
	// 视图ID
	View uint64
	// 区块Hash
	BlockHash []byte
}

ProposalLivenessAndSafeCheckError defines an error for activity and safety check

func NewProposalLivenessAndSafeCheckError

func NewProposalLivenessAndSafeCheckError(blockHeight, view uint64,
	blockHash []byte) *ProposalLivenessAndSafeCheckError

NewProposalLivenessAndSafeCheckError returns a new ProposalLivenessAndSafeCheckError object

func (*ProposalLivenessAndSafeCheckError) Error

Error returns the string of the error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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