pow

package
v0.0.0-...-b124b1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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

func GetCompact(number *big.Int) (uint32, bool)

GetCompact 将一个256bits的大数转换为一个target

func NewPoWConsensus

func NewPoWConsensus(cctx base.ConsensusCtx, ccfg base.ConsensusConfig) base.CommonConsensus

NewPoWConsensus 初始化PoW共识实例

func SetCompact

func SetCompact(nCompact uint32) (*big.Int, bool, bool)

SetCompact 将一个uint32的target转换为一个difficulty

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高度

func (*PoWConsensus) Start

func (pow *PoWConsensus) Start() error

Start 重启实例

func (*PoWConsensus) Stop

func (pow *PoWConsensus) Stop() error

Stop 立即停止当前挖矿

type PoWStatus

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

func (*PoWStatus) GetConsensusBeginInfo

func (s *PoWStatus) GetConsensusBeginInfo() int64

GetConsensusBeginInfo 返回该实例初始高度

func (*PoWStatus) GetConsensusName

func (s *PoWStatus) GetConsensusName() string

GetConsensusName 获取共识类型

func (*PoWStatus) GetCurrentTerm

func (s *PoWStatus) GetCurrentTerm() int64

GetCurrentTerm 获取当前状态机term

func (*PoWStatus) GetCurrentValidatorsInfo

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

GetCurrentValidatorsInfo 获取当前矿工信息

func (*PoWStatus) GetStepConsensusIndex

func (s *PoWStatus) GetStepConsensusIndex() int

GetStepConsensusIndex 获取共识item所在共识切片中的index

func (*PoWStatus) GetVersion

func (s *PoWStatus) 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