Documentation
¶
Index ¶
- Constants
- Variables
- func GetCompact(number *big.Int) (uint32, bool)
- func NewPoWConsensus(cctx base.ConsensusCtx, ccfg base.ConsensusConfig) base.CommonConsensus
- func SetCompact(nCompact uint32) (*big.Int, bool, bool)
- type PoWConsensus
- func (pow *PoWConsensus) CalculateBlock(block ledger.BlockHandle) error
- func (pow *PoWConsensus) CheckMinerMatch(ctx xctx.Context, block ledger.BlockHandle) (bool, error)
- func (pow *PoWConsensus) CompeteMaster(height int64) (bool, bool, error)
- func (pow *PoWConsensus) GetConsensusStatus() (base.ConsensusStatus, error)
- func (pow *PoWConsensus) IsProofed(blockID []byte, targetBits uint32) bool
- func (pow *PoWConsensus) ParseConsensusStorage(block ledger.BlockHandle) (interface{}, error)
- func (pow *PoWConsensus) ProcessBeforeMiner(height, timestamp int64) ([]byte, []byte, error)
- func (pow *PoWConsensus) ProcessConfirmBlock(block ledger.BlockHandle) error
- func (pow *PoWConsensus) Start() error
- func (pow *PoWConsensus) Stop() error
- type PoWStatus
- type ValidatorsInfo
Constants ¶
View Source
const ( MAX_TRIES = 1 << 32 // mining时的最大尝试次数 BLOCK_BUF = 100 //newblock通道中的最大区块数量 )
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("CommonConsensus 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 base.ConsensusCtx, ccfg base.ConsensusConfig) base.CommonConsensus
NewPoWConsensus 初始化PoW共识实例
Types ¶
type PoWConsensus ¶
type PoWConsensus struct { base.ConsensusCtx // contains filtered or unexported fields }
PoWConsensus pow具体结构
func (*PoWConsensus) CalculateBlock ¶
func (pow *PoWConsensus) CalculateBlock(block ledger.BlockHandle) error
CalculateBlock 挖矿过程
func (*PoWConsensus) CheckMinerMatch ¶
func (pow *PoWConsensus) CheckMinerMatch(ctx xctx.Context, block ledger.BlockHandle) (bool, error)
CheckMinerMatch 验证区块,包括merkel根和hash
func (*PoWConsensus) CompeteMaster ¶
func (pow *PoWConsensus) CompeteMaster(height int64) (bool, bool, error)
CompeteMaster PoW单一节点都为矿工,故返回为true
func (*PoWConsensus) GetConsensusStatus ¶
func (pow *PoWConsensus) GetConsensusStatus() (base.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 ledger.BlockHandle) (interface{}, error)
ParseConsensusStorage PoW专有存储的逻辑,即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 ledger.BlockHandle) error
ProcessConfirmBlock 此处更新最新的block高度
type PoWStatus ¶
type PoWStatus struct {
// contains filtered or unexported fields
}
func (*PoWStatus) GetConsensusBeginInfo ¶
GetConsensusBeginInfo 返回该实例初始高度
func (*PoWStatus) GetConsensusName ¶
GetConsensusName 获取共识类型
func (*PoWStatus) GetCurrentTerm ¶
GetCurrentTerm 获取当前状态机term
func (*PoWStatus) GetCurrentValidatorsInfo ¶
GetCurrentValidatorsInfo 获取当前矿工信息
func (*PoWStatus) GetStepConsensusIndex ¶
GetStepConsensusIndex 获取共识item所在共识切片中的index
type ValidatorsInfo ¶
type ValidatorsInfo struct {
Validators []string `json:"validators"`
}
Click to show internal directories.
Click to hide internal directories.