consensus

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 9 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")
)

Functions

func Register

func Register(name string, f NewStepConsensus) error

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

Types

type ConsensusImplInterface added in v1.0.2

type ConsensusImplInterface interface {
	ConsensusInterface
	// 共识实例的启动逻辑
	// 系统合约
	Start() error
	// 共识实例的挂起逻辑, 另: 若共识实例发现绑定block结构有误,会直接停掉当前共识实例并panic
	Stop() error
	// 共识占用blockinterface的专有存储,特定共识需要提供parse接口,在此作为接口高亮
	ParseConsensusStorage(block cctx.BlockInterface) (interface{}, error)
}

ConsensusInterface 定义了一个共识实例需要实现的接口,用于bcs具体共识的实现

func NewPluginConsensus

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

NewPluginConsensus 新建可插拔共识实例

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(height, timestamp int64) ([]byte, []byte, error)
	// CalculateBlock 矿工挖矿时共识需要做的工作, 如PoW时共识需要完成存在性证明
	CalculateBlock(block cctx.BlockInterface) error
	// ProcessConfirmBlock 用于确认块后进行相应的处理
	ProcessConfirmBlock(block cctx.BlockInterface) error
	// GetStatus 获取区块链共识信息
	GetConsensusStatus() (ConsensusStatus, error)
}

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

type ConsensusStatus added in v1.0.2

type ConsensusStatus interface {
	// 获取共识版本号
	GetVersion() int64
	// pluggable consensus共识item起始高度
	GetConsensusBeginInfo() int64
	// 获取共识item所在consensus slice中的index
	GetStepConsensusIndex() int
	// 获取共识类型
	GetConsensusName() string
	// 获取当前状态机term
	GetCurrentTerm() int64
	// 获取当前矿工信息
	GetCurrentValidatorsInfo() []byte
}

ConsensusStatus 定义了一个共识实例需要返回的各种状态,需特定共识实例实现相应接口

type NewStepConsensus

type NewStepConsensus func(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) 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() (ConsensusStatus, error)

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

func (*PluggableConsensus) ProcessBeforeMiner

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

ProcessBeforeMinerm调用具体实例的ProcessBeforeMiner()

func (*PluggableConsensus) ProcessConfirmBlock

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

ProcessConfirmBlock 调用具体实例的ProcessConfirmBlock()

func (*PluggableConsensus) SwitchConsensus added in v1.0.2

func (pc *PluggableConsensus) SwitchConsensus(height int64) error

SwitchConsensus 用于共识升级时切换共识实例

type PluggableConsensusInterface added in v1.0.2

type PluggableConsensusInterface interface {
	ConsensusInterface
	SwitchConsensus(height int64) error
}

func NewPluggableConsensus

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

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

Directories

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

Jump to

Keyboard shortcuts

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