consensus

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.")

	ErrInvalidConfig  = errors.New("config should be an empty JSON when rolling back an old one, or try an upper version")
	ErrInvalidVersion = errors.New("version should be an upper one when upgrading a new one, or try an empty config JSON when you need rollback")
)

Functions

func CheckConsensusVersion

func CheckConsensusVersion(hisMap map[int]def.ConsensusConfig, cfg *def.ConsensusConfig) error

CheckConsensusConfig 同名配置文件检查: 1. 若历史相同version,则直接返回历史cfg 2. 若不存在,需要比历史最大值大 3. 将合法的配置写到map中

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