consensus

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

共识领域组件编程规范

1.领域上下文。

2.对外暴露接口。

3.驱动组件约束接口。

4.公共数据结构。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyConsensusListErr = errors.New("Consensus list of PluggableConsensus is empty.")
	EmptyConsensusName    = errors.New("Consensus name can not be empty")
	EmptyConfig           = errors.New("Config name can not be empty")
	UpdateTriggerError    = errors.New("Update trigger height invalid")
	BeginBlockIdErr       = errors.New("Consensus begin blockid err")
	BuildConsensusError   = errors.New("Build consensus Error")
	ConsensusNotRegister  = errors.New("Consensus hasn't been register. Please use consensus.Register({NAME},{FUNCTION_POINTER}) to register in consensusMap")
	ContractMngErr        = errors.New("Contract manager is empty.")
)

Functions

func NewPluginConsensus

func NewPluginConsensus(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) (base.ConsensusImplInterface, error)

NewPluginConsensus 新建可插拔共识实例

func Register

func Register(name string, f NewStepConsensus) error

Register 不同类型的共识需要提前完成注册

Types

type ConsensusInterface

type ConsensusInterface interface {
	// CompeteMaster 返回是否为矿工以及是否需要进行SyncBlock
	CompeteMaster(height int64) (bool, bool, error)
	// CheckMinerMatch 当前block是否合法
	CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockInterface) (bool, error)
	// ProcessBeforeMiner 开始挖矿前进行相应的处理, 返回truncate目标(如需裁剪), 返回写consensusStorage, 返回err
	ProcessBeforeMiner(timestamp int64) ([]byte, []byte, error)
	// CalculateBlock 矿工挖矿时共识需要做的工作, 如PoW时共识需要完成存在性证明
	CalculateBlock(block cctx.BlockInterface) error
	// ProcessConfirmBlock 用于确认块后进行相应的处理
	ProcessConfirmBlock(block cctx.BlockInterface) error
	// GetStatus 获取区块链共识信息
	GetConsensusStatus() (base.ConsensusStatus, error)
}

ConsensusInterface 定义了一个共识实例需要实现的接口,用于kernel外的调用

func NewPluggableConsensus

func NewPluggableConsensus(cCtx cctx.ConsensusCtx) (ConsensusInterface, error)

NewPluggableConsensus 初次创建PluggableConsensus实例,初始化cons列表

type NewStepConsensus

type NewStepConsensus func(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) base.ConsensusImplInterface

type PluggableConsensus

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

PluggableConsensus 实现了consensus_interface接口

func (*PluggableConsensus) CalculateBlock

func (pc *PluggableConsensus) CalculateBlock(block cctx.BlockInterface) error

CalculateBlock 矿工挖矿时共识需要做的工作, 如PoW时共识需要完成存在性证明

func (*PluggableConsensus) CheckMinerMatch

func (pc *PluggableConsensus) CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockInterface) (bool, error)

CheckMinerMatch 调用具体实例的CheckMinerMatch()

func (*PluggableConsensus) CompeteMaster

func (pc *PluggableConsensus) CompeteMaster(height int64) (bool, bool, error)

CompeteMaster 矿工检查当前自己是否需要挖矿 param: height仅为打印需要的标示,实际还是需要账本当前最高 的高度作为输入

func (*PluggableConsensus) GetConsensusStatus

func (pc *PluggableConsensus) GetConsensusStatus() (base.ConsensusStatus, error)

GetConsensusStatus 调用具体实例的GetConsensusStatus(),返回接口

func (*PluggableConsensus) ProcessBeforeMiner

func (pc *PluggableConsensus) ProcessBeforeMiner(timestamp int64) ([]byte, []byte, error)

ProcessBeforeMinerm调用具体实例的ProcessBeforeMiner()

func (*PluggableConsensus) ProcessConfirmBlock

func (pc *PluggableConsensus) ProcessConfirmBlock(block cctx.BlockInterface) error

ProcessConfirmBlock 调用具体实例的ProcessConfirmBlock()

Directories

Path Synopsis
明确定义该模块需要的上下文信息,方便代码阅读和理解
明确定义该模块需要的上下文信息,方便代码阅读和理解

Jump to

Keyboard shortcuts

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