mining

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: ISC Imports: 23 Imported by: 1

README

mining

Build Status ISC License GoDoc

Overview

This package is currently a work in progress.

Installation and Updating

$ go get -u gitlab.com/jaxnet/jaxnetd/shards/mempool

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       = chaincfg.HaberStornettaPerJAXNETCoin * 144.0 / 250
	MinHighPriorityBeacon = chaincfg.HaberStornettaPerJAXNETCoin * 144.0 / 250
	MinHighPriorityShard  = chaincfg.JuroPerJAXCoin * 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 jaxnetd.
	CoinbaseFlags = "/P2SH/jaxnetd/"
)
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 AddWitnessCommitment added in v0.4.2

func AddWitnessCommitment(coinbaseTx *jaxutil.Tx, blockTxns []*jaxutil.Tx) []byte

AddWitnessCommitment adds the witness commitment as an OP_RETURN outpout within the coinbase tx. The raw commitment is returned. nolint: gocritic

func CalcPriority

func CalcPriority(tx *wire.MsgTx, utxoView *chaindata.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 nolint: gomnd

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func MinimumMedianTime

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

MinimumMedianTime returns the minimum allowed timestamp for a block building on the end of the provided best chain. In particular, it is one second after the median timestamp of the last several blocks per the chain consensus rules.

func UseLogger

func UseLogger(logger zerolog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlkTmplGenerator

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

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,
	chainCtx chainctx.IChainCtx,
	txSource TxSource,
	chain *blockchain.BlockChain) *BlkTmplGenerator

NewBlkTmplGenerator returns a new block template generator for the given policy using transactions from the provided transaction source.

The additional state-related fields are required in order to ensure the templates are built on top of the current best chain and adhere to the consensus rules.

func (*BlkTmplGenerator) BestSnapshot

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

BestSnapshot returns information about the current best chain block and related state as of the current point in time using the chain instance associated with the block template generator. The returned state must be treated as immutable since it is shared by all callers.

This function is safe for concurrent access.

func (*BlkTmplGenerator) NewBlockTemplate

func (g *BlkTmplGenerator) NewBlockTemplate(payToAddress jaxutil.Address, burnReward int) (*chaindata.BlockTemplate, error)

func (*BlkTmplGenerator) TxSource

func (g *BlkTmplGenerator) TxSource() TxSource

TxSource returns the associated transaction source.

This function is safe for concurrent access.

func (*BlkTmplGenerator) UpdateBlockTime

func (g *BlkTmplGenerator) UpdateBlockTime(msgBlock *wire.MsgBlock) 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.

func (*BlkTmplGenerator) UpdateExtraNonce

func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight int32,
	shardID uint32, 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 GBTWorkState

type GBTWorkState struct {
	sync.Mutex

	LastGenerated time.Time

	Template *chaindata.BlockTemplate

	Generator *BlkTmplGenerator
	// contains filtered or unexported fields
}

GBTWorkState houses state that is used in between multiple RPC invocations to getBlockTemplate.

func NewGbtWorkState

func NewGbtWorkState(timeSource chaindata.MedianTimeSource, generator *BlkTmplGenerator,
	miningAddrs []jaxutil.Address) *GBTWorkState

NewGbtWorkState returns a new instance of a GBTWorkState with all internal fields initialized and ready to use.

func (*GBTWorkState) BlockTemplate

func (state *GBTWorkState) BlockTemplate(bestState *chaindata.BestState,
	useCoinbaseValue bool, burnReward int) (chaindata.BlockTemplate, error)

func (*GBTWorkState) BlockTemplateResult added in v0.4.3

func (state *GBTWorkState) BlockTemplateResult(useCoinbaseValue bool, submitOld *bool) (*jaxjson.GetBlockTemplateResult, error)

BlockTemplateResult returns the current block template associated with the state as a jaxjson.GetBeaconBlockTemplateResult that is ready to be encoded to JSON and returned to the caller.

This function MUST be called with the state locked.

func (*GBTWorkState) CoinbaseData

func (state *GBTWorkState) CoinbaseData(template *chaindata.BlockTemplate, useCoinbaseValue bool) (*coinbaseData, error)

nolint: golint, revive

func (*GBTWorkState) NotifyBlockConnected

func (state *GBTWorkState) NotifyBlockConnected(blockHash *chainhash.Hash)

NotifyBlockConnected uses the newly-connected block to notify any long poll clients with a new block template when their existing block template is stale due to the newly connected block.

func (*GBTWorkState) NotifyLongPollers

func (state *GBTWorkState) NotifyLongPollers(latestHash *chainhash.Hash, lastGenerated time.Time)

NotifyLongPollers notifies any channels that have been registered to be notified when block templates are stale.

This function MUST be called with the state locked.

func (*GBTWorkState) NotifyMempoolTx

func (state *GBTWorkState) NotifyMempoolTx(lastUpdated time.Time)

NotifyMempoolTx uses the new last updated time for the transaction memory pool to notify any long poll clients with a new block template when their existing block template is stale due to enough time passing and the contents of the memory pool changing.

func (*GBTWorkState) TemplateUpdateChan

func (state *GBTWorkState) TemplateUpdateChan(prevHash *chainhash.Hash, lastGenerated int64) chan struct{}

TemplateUpdateChan returns a channel that will be closed once the block template associated with the passed previous hash and last generated time is stale. The function will return existing channels for duplicate parameters which allows multiple clients to wait for the same block template without requiring a different channel for each client.

This function MUST be called with the state locked.

func (*GBTWorkState) TransformTxs

func (state *GBTWorkState) TransformTxs(template *chaindata.BlockTemplate) ([]jaxjson.GetBlockTemplateResultTx, error)

func (*GBTWorkState) UpdateBlockTemplate

func (state *GBTWorkState) UpdateBlockTemplate(bestState *chaindata.BestState,
	useCoinbaseValue bool, burnRewardFlags int) error

UpdateBlockTemplate creates or updates a block template for the work state. A new block template will be generated when the current best block has changed or the transactions in the memory pool have been updated and it has been long enough since the last template was generated. Otherwise, the timestamp for the existing block template is updated (and possibly the difficulty on testnet per the consesus rules). Finally, if the useCoinbaseValue flag is false and the existing block template does not already contain a valid payment address, the block template will be updated with a randomly selected payment address from the list of configured addresses.

This function MUST be called with the state locked. nolint: gosec

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 jaxutil.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 *jaxutil.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