Documentation ¶
Index ¶
- Variables
- func NewSingleConsensus(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) consensus.ConsensusImplInterface
- type SingleConfig
- type SingleConsensus
- func (s *SingleConsensus) CalculateBlock(block cctx.BlockInterface) error
- func (s *SingleConsensus) CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockInterface) (bool, error)
- func (s *SingleConsensus) CompeteMaster(height int64) (bool, bool, error)
- func (s *SingleConsensus) GetConsensusStatus() (consensus.ConsensusStatus, error)
- func (s *SingleConsensus) ParseConsensusStorage(block cctx.BlockInterface) (interface{}, error)
- func (s *SingleConsensus) ProcessBeforeMiner(height, timestamp int64) ([]byte, []byte, error)
- func (s *SingleConsensus) ProcessConfirmBlock(block cctx.BlockInterface) error
- func (s *SingleConsensus) Start() error
- func (s *SingleConsensus) Stop() error
- type SingleStatus
- type ValidatorsInfo
Constants ¶
This section is empty.
Variables ¶
var (
MinerAddressErr = errors.New("Block's proposer must be equal to its address.")
)
本次single改造支持single的升级,即Miner地址可变
Functions ¶
func NewSingleConsensus ¶
func NewSingleConsensus(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) consensus.ConsensusImplInterface
NewSingleConsensus 初始化实例
Types ¶
type SingleConfig ¶
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) 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"`
}