mining

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: Unlicense Imports: 14 Imported by: 0

README

mining

ISC License GoDoc

Overview

This package contains an implementation of block construction for mining purposes. This package is currently a work in progress.

Installation and Updating

$ go get -u github.com/bindchain/core/mining

License

Package mining is licensed under the copyfree ISC License.

Documentation

Index

Constants

View Source
const (
	// MinHighPriority is the minimum priority value that allows a
	// transaction to be considered high priority.
	MinHighPriority = util.SatoshiPerBitcoin * 144.0 / 250

	// CoinbaseFlags is added to the coinbase script of a generated block and
	// is used to monitor BIP16 support as well as blocks that are generated
	// via pod.
	CoinbaseFlags = "/P2SH/pod/"
)
View Source
const (
	// UnminedHeight is the height used for the "block" height field of the contextual transaction information provided in a transaction store when it has not yet been mined into a block.
	UnminedHeight = 0x7fffffff
)

Variables

This section is empty.

Functions

func CalcPriority

func CalcPriority(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextBlockHeight int32) float64

CalcPriority returns a transaction priority given a transaction and the sum of each of its input values multiplied by their age (# of confirmations). Thus, the final formula for the priority is: sum(inputValue * inputAge) / adjustedTxSize

func MinimumMedianTime

func MinimumMedianTime(chainState *blockchain.BestState) time.Time

Types

type BlkTmplGenerator

type BlkTmplGenerator struct {
	Policy      *Policy
	ChainParams *netparams.Params
	TxSource    TxSource
	Chain       *blockchain.BlockChain
	TimeSource  blockchain.MedianTimeSource
	SigCache    *txscript.SigCache
	HashCache   *txscript.HashCache
	Algo        string
}

BlkTmplGenerator provides a type that can be used to generate block templates based on a given mining policy and source of transactions to choose from. It also houses additional state required in order to ensure the templates are built on top of the current best chain and adhere to the consensus rules.

func NewBlkTmplGenerator

func NewBlkTmplGenerator(policy *Policy, params *netparams.Params,
	txSource TxSource, chain *blockchain.BlockChain,
	timeSource blockchain.MedianTimeSource,
	sigCache *txscript.SigCache,
	hashCache *txscript.HashCache, algo string) *BlkTmplGenerator

func (*BlkTmplGenerator) BestSnapshot

func (g *BlkTmplGenerator) BestSnapshot() *blockchain.BestState

func (*BlkTmplGenerator) GetTxSource

func (g *BlkTmplGenerator) GetTxSource() TxSource

func (*BlkTmplGenerator) NewBlockTemplate

func (g *BlkTmplGenerator) NewBlockTemplate(workerNumber uint32, payToAddress util.
	Address, algo string) (*BlockTemplate, error)

func (*BlkTmplGenerator) UpdateBlockTime

func (g *BlkTmplGenerator) UpdateBlockTime(workerNumber uint32, msgBlock *wire.
	MsgBlock) error

func (*BlkTmplGenerator) UpdateExtraNonce

func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock,
	blockHeight int32, extraNonce uint64) error

UpdateExtraNonce updates the extra nonce in the coinbase script of the passed block by regenerating the coinbase script with the passed value and block height. It also recalculates and updates the new merkle root that results from changing the coinbase script.

type BlockTemplate

type BlockTemplate struct {
	// Block is a block that is ready to be solved by miners.  Thus, it is
	// completely valid with the exception of satisfying the proof-of-work
	// requirement.
	Block *wire.MsgBlock
	// Fees contains the amount of fees each transaction in the generated
	// template pays in base units.  Since the first transaction is the
	// coinbase, the first entry (offset 0) will contain the negative of the
	// sum of the fees of all other transactions.
	Fees []int64
	// SigOpCosts contains the number of signature operations each
	// transaction in the generated template performs.
	SigOpCosts []int64
	// Height is the height at which the block template connects to the main
	// chain.
	Height int32
	// ValidPayAddress indicates whether or not the template coinbase
	// pays to
	// an address or is redeemable by anyone.  See the documentation on
	// NewBlockTemplate for details on which this can be useful to generate
	// templates without a coinbase payment address.
	ValidPayAddress bool
	// WitnessCommitment is a commitment to the witness data (if any) within
	// the block. This field will only be populated once segregated witness
	// has been activated, and the block contains a transaction which has
	// witness data.
	WitnessCommitment []byte
}

BlockTemplate houses a block that has yet to be solved along with additional details about the fees and the number of signature operations for each transaction in the block.

type Policy

type Policy struct {
	// BlockMinWeight is the minimum block weight to be used when generating a block template.
	BlockMinWeight uint32
	// BlockMaxWeight is the maximum block weight to be used when generating a block template.
	BlockMaxWeight uint32
	// BlockMinWeight is the minimum block size to be used when generating a block template.
	BlockMinSize uint32
	// BlockMaxSize is the maximum block size 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 Satoshi/1000 bytes that is required for a transaction to be treated as free for mining purposes (block template generation).
	TxMinFreeFee util.Amount
}

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 TxDesc

type TxDesc struct {
	// Tx is the transaction associated with the entry.
	Tx *util.Tx
	// Added is the time when the entry was added to the source pool.
	Added time.Time
	// Height is the block height when the entry was added to the the
	// source pool.
	Height int32
	// Fee is the total fee the transaction associated with the entry pays.
	Fee int64
	// FeePerKB is the fee the transaction pays in Satoshi per 1000 bytes.
	FeePerKB int64
}

TxDesc is a descriptor about a transaction in a transaction source along with additional metadata.

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() []*TxDesc
	// HaveTransaction returns whether or not the passed transaction hash
	// exists in the source pool.
	HaveTransaction(hash *chainhash.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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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