single

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: 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MinerAddressErr = errors.New("Block's proposer must be equal to its address.")
)

本次single改造支持single的升级,即Miner地址可变

Functions

func NewSingleConsensus

NewSingleConsensus 初始化实例

Types

type SingleConfig

type SingleConfig struct {
	Miner string `json:"miner"`
	// 单位为毫秒
	Period  int64 `json:"period"`
	Version int64 `json:"version"`
}

type SingleConsensus

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

SingleConsensus single为单点出块的共识逻辑

func (*SingleConsensus) CalculateBlock

func (s *SingleConsensus) CalculateBlock(block cctx.BlockInterface) error

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

func (*SingleConsensus) CheckMinerMatch

func (s *SingleConsensus) CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockInterface) (bool, error)

CheckMinerMatch 查看block是否合法 ATTENTION: TODO: 上层需要先检查VerifyMerkle(block)

func (*SingleConsensus) CompeteMaster

func (s *SingleConsensus) CompeteMaster(height int64) (bool, bool, error)

CompeteMaster 返回是否为矿工以及是否需要进行SyncBlock 该函数返回两个bool,第一个表示是否当前应当出块,第二个表示是否当前需要向其他节点同步区块

func (*SingleConsensus) GetConsensusStatus

func (s *SingleConsensus) GetConsensusStatus() (consensus.ConsensusStatus, error)

GetStatus 获取区块链共识信息

func (*SingleConsensus) ParseConsensusStorage

func (s *SingleConsensus) ParseConsensusStorage(block cctx.BlockInterface) (interface{}, error)

ParseConsensusStorage 共识占用blockinterface的专有存储,特定共识需要提供parse接口,在此作为接口高亮 Single共识没有用到区块存储信息, 故返回空

func (*SingleConsensus) ProcessBeforeMiner

func (s *SingleConsensus) ProcessBeforeMiner(height, timestamp int64) ([]byte, []byte, error)

ProcessBeforeMiner 开始挖矿前进行相应的处理, 返回是否需要truncate, 返回写consensusStorage, 返回err

func (*SingleConsensus) ProcessConfirmBlock

func (s *SingleConsensus) ProcessConfirmBlock(block cctx.BlockInterface) error

ProcessConfirmBlock 用于确认块后进行相应的处理

func (*SingleConsensus) Start

func (s *SingleConsensus) Start() error

共识实例的启动逻辑

func (*SingleConsensus) Stop

func (s *SingleConsensus) Stop() error

共识实例的挂起逻辑, 另: 若共识实例发现绑定block结构有误,会直接停掉当前共识实例并panic

type SingleStatus

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

func (*SingleStatus) GetConsensusBeginInfo

func (s *SingleStatus) GetConsensusBeginInfo() int64

GetConsensusBeginInfo 返回该实例初始高度

func (*SingleStatus) GetConsensusName

func (s *SingleStatus) GetConsensusName() string

GetConsensusName 获取共识类型

func (*SingleStatus) GetCurrentTerm

func (s *SingleStatus) GetCurrentTerm() int64

GetCurrentTerm 获取当前状态机term

func (*SingleStatus) GetCurrentValidatorsInfo

func (s *SingleStatus) GetCurrentValidatorsInfo() []byte

GetCurrentValidatorsInfo 获取当前矿工信息

func (*SingleStatus) GetStepConsensusIndex

func (s *SingleStatus) GetStepConsensusIndex() int

GetStepConsensusIndex 获取共识item所在consensus slice中的index

func (*SingleStatus) GetVersion

func (s *SingleStatus) GetVersion() int64

GetVersion 返回pow所在共识version

type ValidatorsInfo

type ValidatorsInfo struct {
	Validators []string `json:"validators"`
}

Jump to

Keyboard shortcuts

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