mining

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: ISC Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTransactionsRoot

func CalculateTransactionsRoot(coinbaseTx string, merklePath []string, witnessRoot string, extraNonce uint64) (*hash.Hash, error)

func DoCalculateTransactionsRoot

func DoCalculateTransactionsRoot(coinbaseTx *types.Transaction, merklePath []*hash.Hash, witnessRoot *hash.Hash, extraNonce uint64) (*hash.Hash, error)

func IsSupportCoinbaseFlagsDynamic

func IsSupportCoinbaseFlagsDynamic(coinbaseTx *types.Transaction) bool

func MedianAdjustedTime

func MedianAdjustedTime(bc *blockchain.BlockChain, timeSource blockchain.MedianTimeSource) time.Time

medianAdjustedTime returns the current time adjusted

func MinimumMedianTime

func MinimumMedianTime(bc *blockchain.BlockChain) time.Time

Allowed timestamp for a block building on the end of the provided best chain.

func NewBlockTemplate

func NewBlockTemplate(policy *Policy, params *params.Params,
	sigCache *txscript.SigCache, txSource TxSource, timeSource blockchain.MedianTimeSource,
	blockManager *blkmgr.BlockManager, payToAddress types.Address, parents []*hash.Hash, powType pow.PowType, coinbaseFlags CoinbaseFlags) (*types.BlockTemplate, error)

func StandardCoinbaseScript

func StandardCoinbaseScript(nextBlockHeight uint64, extraNonce uint64, extraData string, flags CoinbaseFlags) ([]byte, error)

func UpdateBlockTime

func UpdateBlockTime(msgBlock *types.Block, chain *blockchain.BlockChain, timeSource blockchain.MedianTimeSource,
	activeNetParams *params.Params) error

UpdateBlockTime updates the timestamp in the header of the passed block to the current time while taking into account the median time of the last several blocks to ensure the new time is after that time per the chain consensus rules. Finally, it will update the target difficulty if needed based on the new time for the test networks since their target difficulty can change based upon time.

Types

type CoinbaseFlags

type CoinbaseFlags string

coinbaseFlags is some extra data appended to the coinbase script sig.

const (
	CoinbaseFlagsStatic  CoinbaseFlags = "/qitmeer/"
	CoinbaseFlagsDynamic CoinbaseFlags = "/qng/"
)

type MiningErrorCode

type MiningErrorCode int

MiningErrorCode identifies a kind of error.

const (
	// ErrNotEnoughVoters indicates that there were not enough voters to
	// build a block on top of HEAD.
	ErrNotEnoughVoters MiningErrorCode = iota

	// ErrFailedToGetGeneration specifies that the current generation for
	// a block could not be obtained from blockchain.
	ErrFailedToGetGeneration

	// ErrGetStakeDifficulty indicates that the current stake difficulty
	// could not be obtained.
	ErrGetStakeDifficulty

	// ErrGetStakeDifficulty indicates that the current top block of the
	// blockchain could not be obtained.
	ErrGetTopBlock

	// ErrCreatingCoinbase indicates that there was a problem generating
	// the coinbase.
	ErrCreatingCoinbase

	// ErrGettingMedianTime indicates that the server was unable to get the
	// median adjusted time for the network.
	ErrGettingMedianTime

	// ErrGettingDifficulty indicates that there was an error getting the
	// PoW difficulty.
	ErrGettingDifficulty

	// ErrTransactionAppend indicates there was a problem adding a msgtx
	// to a msgblock.
	ErrTransactionAppend

	// ErrCheckConnectBlock indicates that a newly created block template
	// failed blockchain.CheckBlockSanity.
	ErrCheckBlockSanity

	// ErrCheckConnectBlock indicates that a newly created block template
	// failed blockchain.CheckConnectBlock.
	ErrCheckConnectBlock

	// ErrCoinbaseLengthOverflow indicates that a coinbase length was overflowed,
	// probably of a result of incrementing extranonce.
	ErrCoinbaseLengthOverflow

	// ErrFraudProofIndex indicates that there was an error finding the index
	// for a fraud proof.
	ErrFraudProofIndex

	// ErrFetchTxStore indicates a transaction store failed to fetch.
	ErrFetchTxStore
)

These constants are used to identify a specific RuleError.

func (MiningErrorCode) String

func (e MiningErrorCode) String() string

String returns the MiningErrorCode as a human-readable name.

type MiningRuleError

type MiningRuleError struct {
	ErrorCode   MiningErrorCode // Describes the kind of error
	Description string          // Human readable description of the issue
}

MiningRuleError identifies a rule violation. It is used to indicate that processing of a block or transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and access the MiningErrorCode field to ascertain the specific reason for the rule violation.

func (MiningRuleError) Error

func (e MiningRuleError) Error() string

Error satisfies the error interface and prints human-readable errors.

func (MiningRuleError) GetCode

func (e MiningRuleError) GetCode() MiningErrorCode

GetCode satisfies the error interface and prints human-readable errors.

type Policy

type Policy struct {
	// BlockMinSize is the minimum block size in bytes to be used when
	// generating a block template.
	BlockMinSize uint32

	// BlockMaxSize is the maximum block size in bytes to be used when
	// generating a block template.
	BlockMaxSize uint32

	// BlockPrioritySize is the size in bytes for high-priority / low-fee
	// transactions to be used when generating a block template.
	BlockPrioritySize uint32

	// TxMinFreeFee is the minimum fee in Atoms/1000 bytes that is
	// required for a transaction to be treated as free for mining purposes
	// (block template generation).
	TxMinFreeFee int64

	// TxTimeScope is the allow tx time scope with server time
	TxTimeScope int64

	// StandardVerifyFlags defines the function to retrieve the flags to
	// use for verifying scripts for the block after the current best block.
	// It must set the verification flags properly depending on the result
	// of any agendas that affect them.
	//
	// This function must be safe for concurrent access.
	StandardVerifyFlags func() (txscript.ScriptFlags, error)

	// CoinbaseGenerator
	CoinbaseGenerator *coinbase.CoinbaseGenerator
}

Policy houses the policy (configuration parameters) which is used to control the generation of block templates. See the documentation for NewBlockTemplate for more details on each of these parameters are used.

type TxSource

type TxSource interface {
	// LastUpdated returns the last time a transaction was added to or
	// removed from the source pool.
	LastUpdated() time.Time

	// MiningDescs returns a slice of mining descriptors for all the
	// transactions in the source pool.
	MiningDescs() []*types.TxDesc

	// HaveTransaction returns whether or not the passed transaction hash
	// exists in the source pool.
	HaveTransaction(hash *hash.Hash) bool

	// HaveAllTransactions returns whether or not all of the passed
	// transaction hashes exist in the source pool.
	HaveAllTransactions(hashes []hash.Hash) bool
}

TxSource represents a source of transactions to consider for inclusion in new blocks.

The interface contract requires that all of these methods are safe for concurrent access with respect to the source.

type WeightedRandQueue

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

The Queue for weighted rand tx

func (*WeightedRandQueue) Len

func (wq *WeightedRandQueue) Len() int

The length of WeightedRandQueue

func (*WeightedRandQueue) Pop

func (wq *WeightedRandQueue) Pop() *WeightedRandTx

Pop item from WeightedRandQueue

func (*WeightedRandQueue) Push

func (wq *WeightedRandQueue) Push(tx *WeightedRandTx)

Push item to WeightedRandQueue

type WeightedRandTx

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

weighted random tx

Jump to

Keyboard shortcuts

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