Documentation ¶
Index ¶
- Constants
- Variables
- func GetCompact(number *big.Int) (uint32, bool)
- func NewPoWConsensus(cCtx context.ConsensusCtx, cCfg def.ConsensusConfig) consensus.ConsensusImplInterface
- func SetCompact(nCompact uint32) (*big.Int, bool, bool)
- type PoWConfig
- type PoWConsensus
- func (pow *PoWConsensus) CalculateBlock(block context.BlockInterface) error
- func (pow *PoWConsensus) CheckMinerMatch(ctx xcontext.XContext, block context.BlockInterface) (bool, error)
- func (pow *PoWConsensus) CompeteMaster(height int64) (bool, bool, error)
- func (pow *PoWConsensus) GetConsensusStatus() (consensus.ConsensusStatus, error)
- func (pow *PoWConsensus) IsProofed(blockID []byte, targetBits uint32) bool
- func (pow *PoWConsensus) ParseConsensusStorage(block context.BlockInterface) (interface{}, error)
- func (pow *PoWConsensus) ProcessBeforeMiner(height, timestamp int64) ([]byte, []byte, error)
- func (pow *PoWConsensus) ProcessConfirmBlock(block context.BlockInterface) error
- func (pow *PoWConsensus) Start() error
- func (pow *PoWConsensus) Stop() error
- type PoWStatus
- type PoWStorage
- type ValidatorsInfo
Constants ¶
View Source
const ( MAX_TRIES = 1 << 32 // mining时的最大尝试次数 BLOCK_BUF = 100 )
Variables ¶
View Source
var ( PoWBlockItemErr = errors.New("invalid block structure, pls check item nonce & targetbits") OODMineErr = errors.New("mining height is out of date") TryTooMuchMineErr = errors.New("mining max tries threshold") InternalErr = errors.New("Consensus module found internal error") BlockSignErr = errors.New("invalid block sign") MakeBlockErr = errors.New("make blockid err") )
Functions ¶
func GetCompact ¶
GetCompact 将一个256bits的大数转换为一个target
func NewPoWConsensus ¶
func NewPoWConsensus(cCtx context.ConsensusCtx, cCfg def.ConsensusConfig) consensus.ConsensusImplInterface
NewPoWConsensus 初始化实例
Types ¶
type PoWConfig ¶
type PoWConfig struct { DefaultTarget uint32 `json:"defaultTarget"` AdjustHeightGap int32 `json:"adjustHeightGap"` ExpectedPeriodMilSec int32 `json:"expectedPeriod"` MaxTarget uint32 `json:"maxTarget"` }
PoWConfig pow需要解析的创始块解析格式
根据Bitcoin推荐 AdjustHeightGap: 2016, MaxTarget: 0x1d00FFFF, DefaultTarget: 0x207FFFFF
type PoWConsensus ¶
type PoWConsensus struct { context.ConsensusCtx // contains filtered or unexported fields }
PoWConsensus pow具体结构
func (*PoWConsensus) CalculateBlock ¶
func (pow *PoWConsensus) CalculateBlock(block context.BlockInterface) error
CalculateBlock 挖矿过程
func (*PoWConsensus) CheckMinerMatch ¶
func (pow *PoWConsensus) CheckMinerMatch(ctx xcontext.XContext, block context.BlockInterface) (bool, error)
CheckMinerMatch 验证区块,包括merkel根和hash ATTENTION: TODO: 上层需要先检查VerifyMerkle(block)
func (*PoWConsensus) CompeteMaster ¶
func (pow *PoWConsensus) CompeteMaster(height int64) (bool, bool, error)
CompeteMaster PoW单一节点都为矿工,故返回为true
func (*PoWConsensus) GetConsensusStatus ¶
func (pow *PoWConsensus) GetConsensusStatus() (consensus.ConsensusStatus, error)
GetConsensusStatus 获取pow实例状态
func (*PoWConsensus) IsProofed ¶
func (pow *PoWConsensus) IsProofed(blockID []byte, targetBits uint32) bool
IsProofed check workload proof
func (*PoWConsensus) ParseConsensusStorage ¶
func (pow *PoWConsensus) ParseConsensusStorage(block context.BlockInterface) (interface{}, error)
ParseConsensusStorage PoW parse专有存储的逻辑,即targetBits
func (*PoWConsensus) ProcessBeforeMiner ¶
func (pow *PoWConsensus) ProcessBeforeMiner(height, timestamp int64) ([]byte, []byte, error)
ProcessBeforeMiner 更新下一次pow挖矿时的targetBits
func (*PoWConsensus) ProcessConfirmBlock ¶
func (pow *PoWConsensus) ProcessConfirmBlock(block context.BlockInterface) error
ProcessConfirmBlock 此处更新最新的block高度
type PoWStatus ¶
type PoWStatus struct {
// contains filtered or unexported fields
}
PoWStatus 实现了ConsensusStatus接口
func (*PoWStatus) GetConsensusBeginInfo ¶
GetConsensusBeginInfo 返回该实例初始高度
func (*PoWStatus) GetConsensusName ¶
GetConsensusName 获取共识类型
func (*PoWStatus) GetCurrentTerm ¶
GetCurrentTerm 获取当前状态机term
func (*PoWStatus) GetCurrentValidatorsInfo ¶
GetCurrentValidatorsInfo 获取当前矿工信息
func (*PoWStatus) GetStepConsensusIndex ¶
GetStepConsensusIndex 获取共识item所在consensus slice中的index
type PoWStorage ¶
type PoWStorage struct { // TargetBits 以一个uint32类型解析,16进制格式为0xFFFFFFFF // 真正difficulty按照Bitcoin标准转化,将TargetBits转换为一个uint256 bits的大数 TargetBits uint32 `json:"targetBits,omitempty"` }
目前未定义pb结构 PoWStorage pow占用block中consensusStorage json串的格式
type ValidatorsInfo ¶
type ValidatorsInfo struct {
Validators []string `json:"validators"`
}
Click to show internal directories.
Click to hide internal directories.