Documentation
¶
Index ¶
- Variables
- func NewPluginConsensus(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) (base.ConsensusImplInterface, error)
- func Register(name string, f NewStepConsensus) error
- type ConsensusInterface
- type NewStepConsensus
- type PluggableConsensus
- func (pc *PluggableConsensus) CalculateBlock(block cctx.BlockInterface) error
- func (pc *PluggableConsensus) CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockInterface) (bool, error)
- func (pc *PluggableConsensus) CompeteMaster(height int64) (bool, bool, error)
- func (pc *PluggableConsensus) GetConsensusStatus() (base.ConsensusStatus, error)
- func (pc *PluggableConsensus) ProcessBeforeMiner(timestamp int64) ([]byte, []byte, error)
- func (pc *PluggableConsensus) ProcessConfirmBlock(block cctx.BlockInterface) error
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 新建可插拔共识实例
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()
Click to show internal directories.
Click to hide internal directories.