mempool

package
v0.22.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: ISC Imports: 28 Imported by: 11

README

mempool

Build Status ISC License GoDoc

Package mempool provides a policy-enforced pool of unmined bitcoin transactions.

A key responsibility of the bitcoin network is mining user-generated transactions into blocks. In order to facilitate this, the mining process relies on having a readily-available source of transactions to include in a block that is being solved.

At a high level, this package satisfies that requirement by providing an in-memory pool of fully validated transactions that can also optionally be further filtered based upon a configurable policy.

One of the policy configuration options controls whether or not "standard" transactions are accepted. In essence, a "standard" transaction is one that satisfies a fairly strict set of requirements that are largely intended to help provide fair use of the system to all users. It is important to note that what is considered a "standard" transaction changes over time. For some insight, at the time of this writing, an example of some of the criteria that are required for a transaction to be considered standard are that it is of the most-recently supported version, finalized, does not exceed a specific size, and only consists of specific script forms.

Since this package does not deal with other bitcoin specifics such as network communication and transaction relay, it returns a list of transactions that were accepted which gives the caller a high level of flexibility in how they want to proceed. Typically, this will involve things such as relaying the transactions to other peers on the network and notifying the mining process that new transactions are available.

This package has intentionally been designed so it can be used as a standalone package for any projects needing the ability create an in-memory pool of bitcoin transactions that are not only valid by consensus rules, but also adhere to a configurable policy.

Feature Overview

The following is a quick overview of the major features. It is not intended to be an exhaustive list.

  • Maintain a pool of fully validated transactions
    • Reject non-fully-spent duplicate transactions
    • Reject coinbase transactions
    • Reject double spends (both from the chain and other transactions in pool)
    • Reject invalid transactions according to the network consensus rules
    • Full script execution and validation with signature cache support
    • Individual transaction query support
  • Orphan transaction support (transactions that spend from unknown outputs)
    • Configurable limits (see transaction acceptance policy)
    • Automatic addition of orphan transactions that are no longer orphans as new transactions are added to the pool
    • Individual orphan transaction query support
  • Configurable transaction acceptance policy
    • Option to accept or reject standard transactions
    • Minimum relay fee required from every new transaction
    • Max signature operations per transaction
    • Max orphan transaction size
    • Max number of orphan transactions allowed
  • Additional metadata tracking for each transaction
    • Timestamp when the transaction was added to the pool
    • Most recent block height when the transaction was added to the pool
    • The fee the transaction pays
  • Manual control of transaction removal
    • Recursive removal of all dependent transactions

Installation and Updating

$ go get -u github.com/gcash/bchd/mempool

License

Package mempool is licensed under the copyfree ISC License.

Documentation

Overview

Package mempool provides a policy-enforced pool of unmined bitcoin cash transactions.

A key responsibility of the bitcoin cash network is mining user-generated transactions into blocks. In order to facilitate this, the mining process relies on having a readily-available source of transactions to include in a block that is being solved.

At a high level, this package satisfies that requirement by providing an in-memory pool of fully validated transactions that can also optionally be further filtered based upon a configurable policy.

One of the policy configuration options controls whether or not "standard" transactions are accepted. In essence, a "standard" transaction is one that satisfies a fairly strict set of requirements that are largely intended to help provide fair use of the system to all users. It is important to note that what is considered a "standard" transaction changes over time. For some insight, at the time of this writing, an example of SOME of the criteria that are required for a transaction to be considered standard are that it is of the most-recently supported version, finalized, does not exceed a specific size, and only consists of specific script forms.

Since this package does not deal with other bitcoin cash specifics such as network communication and transaction relay, it returns a list of transactions that were accepted which gives the caller a high level of flexibility in how they want to proceed. Typically, this will involve things such as relaying the transactions to other peers on the network and notifying the mining process that new transactions are available.

Feature Overview

The following is a quick overview of the major features. It is not intended to be an exhaustive list.

  • Maintain a pool of fully validated transactions
  • Reject non-fully-spent duplicate transactions
  • Reject coinbase transactions
  • Reject double spends (both from the chain and other transactions in pool)
  • Reject invalid transactions according to the network consensus rules
  • Full script execution and validation with signature cache support
  • Individual transaction query support
  • Orphan transaction support (transactions that spend from unknown outputs)
  • Configurable limits (see transaction acceptance policy)
  • Automatic addition of orphan transactions that are no longer orphans as new transactions are added to the pool
  • Individual orphan transaction query support
  • Configurable transaction acceptance policy
  • Option to accept or reject standard transactions
  • Minimum relay fee required from every new transaction
  • Max signature operations per transaction
  • Max orphan transaction size
  • Max number of orphan transactions allowed
  • Additional metadata tracking for each transaction
  • Timestamp when the transaction was added to the pool
  • Most recent block height when the transaction was added to the pool
  • The fee the transaction pays
  • Manual control of transaction removal
  • Recursive removal of all dependent transactions

Errors

Errors returned by this package are either the raw errors provided by underlying calls or of type mempool.RuleError. Since there are two classes of rules (mempool acceptance rules and blockchain (consensus) acceptance rules), the mempool.RuleError type contains a single Err field which will, in turn, either be a mempool.TxRuleError or a blockchain.RuleError, or a mempool.HighFeeError for a fee above the caller's limit. The first indicates a violation of mempool acceptance rules while the second indicates a violation of consensus acceptance rules. This allows the caller to easily differentiate between unexpected errors, such as database errors, versus errors due to rule violations through type assertions. In addition, callers can programmatically determine the specific rule violation by type asserting the Err field to one of the aforementioned types and examining their underlying ErrorCode field. RejectReason returns the short reason Bitcoin Cash Node gives for a rule violation, such as txn-mempool-conflict, and BlockRejectReason the reason for a block, which submitblock returns. As in Bitcoin Cash Node, a transaction whose input script fails only standard script flags it does not count as mandatory is refused as nonstandard, with a mempool.TxRuleError, while the blockchain.RuleError of a script that also fails without them holds the script engine's error.

Index

Constants

View Source
const (
	// DefaultMaxDSProofOrphans is the default number of orphan double spend
	// proofs kept.  Up to a quarter more are kept before the oldest are
	// removed.
	DefaultMaxDSProofOrphans = 65535

	// DefaultDSProofOrphanTTL is how long an orphan double spend proof is
	// kept before it expires.
	DefaultDSProofOrphanTTL = 90 * time.Second
)
View Source
const (

	// DefaultEstimateFeeMaxRollback is the default number of rollbacks
	// allowed by the fee estimator for orphaned blocks.
	DefaultEstimateFeeMaxRollback = 2

	// DefaultEstimateFeeMinRegisteredBlocks is the default minimum
	// number of blocks which must be observed by the fee estimator before
	// it will provide fee estimations.
	DefaultEstimateFeeMinRegisteredBlocks = 3
)
View Source
const (

	// DefaultMinRelayTxFee is the minimum fee rate a transaction must pay
	// to be relayed and mined.  This value is in Satoshi/1000 bytes.
	DefaultMinRelayTxFee = bchutil.Amount(1000)

	// DefaultDustRelayFee is the fee rate, in Satoshi/1000 bytes, that
	// outputs are judged dust by: BCHN's default -dustrelayfee.  It does
	// not follow the minimum relay fee, so raising that does not refuse
	// outputs BCHN relays.
	DefaultDustRelayFee = bchutil.Amount(1000)
)

Variables

View Source
var ErrDSProofSearchLimit = errors.New("double spend proof search limit reached")

ErrDSProofSearchLimit is returned when the search of a transaction's unconfirmed ancestors stops at its depth or size limit.

View Source
var (
	// EstimateFeeDatabaseKey is the key that we use to
	// store the fee estimator in the database.
	EstimateFeeDatabaseKey = []byte("estimatefee")
)

Functions

func BlockRejectReason added in v0.22.3

func BlockRejectReason(err error, blockVersion int32) string

BlockRejectReason returns the BIP0022 reason for a block that breaks the rule err reports, which submitblock returns and reject messages carry. Where Bitcoin Cash Node rejects a block for the same reason, its reason string is used. blockVersion is the version of the block, which the reason for a version that is too old gives, as BCHN's does. An error that is not a rule error, or a rule without a reason, gives "rejected: " and the error text.

func CheckInputsStandard added in v0.20.0

func CheckInputsStandard(tx *bchutil.Tx, utxoView *blockchain.UtxoViewpoint, scriptFlags txscript.ScriptFlags) error

func CheckTransactionStandard added in v0.20.0

func CheckTransactionStandard(tx *bchutil.Tx, height int32, medianTimePast time.Time, dustRelayFee bchutil.Amount,
	maxTxVersion int32, upgrade9Active bool, upgrade12Active bool) error

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func ErrToRejectErr

func ErrToRejectErr(err error) (wire.RejectCode, string)

ErrToRejectErr examines the underlying type of the error and returns a reject code and string appropriate to be sent in a wire.MsgReject message.

func RejectReason added in v0.22.3

func RejectReason(err error) string

RejectReason returns the short reason Bitcoin Cash Node gives when it refuses a transaction for the rule violation err reports, such as "txn-mempool-conflict", or an empty string when err is not a rule violation.

func UseLogger

func UseLogger(logger bchlog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BchPerKilobyte

type BchPerKilobyte float64

BchPerKilobyte is number with units of bitcoins per kilobyte.

type Config

type Config struct {
	// Policy defines the various mempool configuration options related
	// to policy.
	Policy Policy

	// ChainParams identifies which chain parameters the txpool is
	// associated with.
	ChainParams *chaincfg.Params

	// FetchUtxoView defines the function to use to fetch unspent
	// transaction output information.
	FetchUtxoView func(*bchutil.Tx) (*blockchain.UtxoViewpoint, error)

	// FetchUtxoEntryUncached looks up an output in the utxo set without
	// adding it, or its absence, to the utxo cache.  The coins named by
	// double spend proofs are looked up with it.  When it is nil,
	// FetchUtxoView is used.
	FetchUtxoEntryUncached func(wire.OutPoint) (*blockchain.UtxoEntry, error)

	// BestHeight defines the function to use to access the block height of
	// the current best chain.
	BestHeight func() int32

	// MedianTimePast defines the function to use in order to access the
	// median time past calculated from the point-of-view of the current
	// chain tip within the best chain.
	MedianTimePast func() time.Time

	// CalcSequenceLock defines the function to use in order to generate
	// the current sequence lock for the given transaction using the passed
	// utxo view.
	CalcSequenceLock func(*bchutil.Tx, *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error)

	// IsDeploymentActive returns true if the target deploymentID is
	// active, and false otherwise. The mempool uses this function to gauge
	// if transactions using new to be soft-forked rules should be allowed
	// into the mempool or not.
	IsDeploymentActive func(deploymentID uint32) (bool, error)

	// SigCache defines a signature cache to use.
	SigCache *txscript.SigCache

	// HashCache defines the transaction hash mid-state cache to use.
	HashCache *txscript.HashCache

	// AddrIndex defines the optional address index instance to use for
	// indexing the unconfirmed transactions in the memory pool.
	// This can be nil if the address index is not enabled.
	AddrIndex *indexers.AddrIndex

	// FeeEstimatator provides a feeEstimator. If it is not nil, the mempool
	// records all new transactions it observes into the feeEstimator.
	FeeEstimator *FeeEstimator

	// DisableDSProofs turns off the creation and handling of double spend
	// proofs.
	DisableDSProofs bool

	// OnDSProof is called, without the mempool lock held, when a double
	// spend proof becomes associated with the memory pool transaction tx.
	OnDSProof func(proof *wire.MsgDSProof, tx *bchutil.Tx)

	// OnBadDSProofs is called, without the mempool lock held, with the
	// peers that sent orphan double spend proofs which turned out to be
	// invalid.
	OnBadDSProofs func(peers []Tag)
}

Config is a descriptor containing the memory pool configuration.

type DSProofDesc added in v0.22.3

type DSProofDesc struct {
	Proof *wire.MsgDSProof
	Hash  chainhash.Hash

	// TxHash is the memory pool transaction spending the proof's outpoint,
	// or nil for an orphan.
	TxHash *chainhash.Hash
}

DSProofDesc describes a double spend proof known to the memory pool.

type DSProofResult added in v0.22.3

type DSProofResult int

DSProofResult is the outcome of processing a double spend proof received from a peer.

const (
	// DSProofAccepted means the proof was valid and associated with a
	// memory pool transaction.
	DSProofAccepted DSProofResult = iota

	// DSProofOrphan means the proof was stored as an orphan because the
	// output it spends or a transaction spending that output is missing.
	DSProofOrphan

	// DSProofIgnored means the proof was dropped because the transaction
	// spending its outpoint already has a proof, or because double spend
	// proofs are disabled.
	DSProofIgnored
)

func (DSProofResult) String added in v0.22.3

func (r DSProofResult) String() string

String returns the result in human-readable form.

type FeeEstimator

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

FeeEstimator manages the data necessary to create fee estimations. It is safe for concurrent access.

func NewFeeEstimator

func NewFeeEstimator(maxRollback, minRegisteredBlocks uint32) *FeeEstimator

NewFeeEstimator creates a FeeEstimator for which at most maxRollback blocks can be unregistered and which returns an error unless minRegisteredBlocks have been registered with it.

func RestoreFeeEstimator

func RestoreFeeEstimator(data FeeEstimatorState) (*FeeEstimator, error)

RestoreFeeEstimator takes a FeeEstimatorState that was previously returned by Save and restores it to a FeeEstimator

func (*FeeEstimator) EstimateFee

func (ef *FeeEstimator) EstimateFee(numBlocks uint32) (BchPerKilobyte, error)

EstimateFee estimates the fee per byte to have a tx confirmed a given number of blocks from now.

func (*FeeEstimator) LastKnownHeight

func (ef *FeeEstimator) LastKnownHeight() int32

LastKnownHeight returns the height of the last block which was registered.

func (*FeeEstimator) ObserveTransaction

func (ef *FeeEstimator) ObserveTransaction(t *TxDesc)

ObserveTransaction is called when a new transaction is observed in the mempool.

func (*FeeEstimator) RegisterBlock

func (ef *FeeEstimator) RegisterBlock(block *bchutil.Block) error

RegisterBlock informs the fee estimator of a new block to take into account.

func (*FeeEstimator) Rollback

func (ef *FeeEstimator) Rollback(hash *chainhash.Hash) error

Rollback unregisters a recently registered block from the FeeEstimator. This can be used to reverse the effect of an orphaned block on the fee estimator. The maximum number of rollbacks allowed is given by maxRollbacks.

Note: not everything can be rolled back because some transactions are deleted if they have been observed too long ago. That means the result of Rollback won't always be exactly the same as if the last block had not happened, but it should be close enough.

func (*FeeEstimator) Save

func (ef *FeeEstimator) Save() FeeEstimatorState

Save records the current state of the FeeEstimator to a []byte that can be restored later.

type FeeEstimatorState

type FeeEstimatorState []byte

FeeEstimatorState represents a saved FeeEstimator that can be restored with data from an earlier session of the program.

type HighFeeError added in v0.22.3

type HighFeeError struct {
	Fee    int64 // The fee paid by the transaction in satoshis
	MaxFee int64 // The maximum fee allowed in satoshis
}

HighFeeError identifies a transaction that pays more fees than the caller allows.

func (HighFeeError) Error added in v0.22.3

func (e HighFeeError) Error() string

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

type MempoolAcceptResult added in v0.22.3

type MempoolAcceptResult struct {
	// MissingParents holds the unknown parents of an orphan transaction.
	// The other fields are only set when it is empty.
	MissingParents []*chainhash.Hash

	// Fee is the fee paid by the transaction in satoshis.
	Fee int64

	// SigChecks is the number of signature checks done by its inputs.
	SigChecks uint32
	// contains filtered or unexported fields
}

MempoolAcceptResult describes a transaction that passed the mempool acceptance checks.

type Policy

type Policy struct {
	// MaxTxVersion is the transaction version that the mempool should
	// accept.  All transactions above this version are rejected as
	// non-standard.
	MaxTxVersion int32

	// AcceptNonStd defines whether to accept non-standard transactions. If
	// true, non-standard transactions will be accepted into the mempool.
	// Otherwise, all non-standard transactions will be rejected.
	AcceptNonStd bool

	// MaxOrphanTxs is the maximum number of orphan transactions
	// that can be queued.
	MaxOrphanTxs int

	// MaxOrphanTxSize is the maximum size allowed for orphan transactions.
	// This helps prevent memory exhaustion attacks from sending a lot of
	// of big orphans.
	MaxOrphanTxSize int

	// LimitSigChecks applies an additional standardness limit to the number
	// of signature checks in each transaction.
	LimitSigChecks bool

	// MinRelayTxFee defines the minimum fee rate in Satoshi/kB a new
	// transaction must pay to be accepted.
	MinRelayTxFee bchutil.Amount
}

Policy houses the policy (configuration parameters) which is used to control the mempool.

type RuleError

type RuleError struct {
	Err error
}

RuleError identifies a rule violation. It is used to indicate that processing of a 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 use the Err field to access the underlying error, which will be either a TxRuleError or a blockchain.RuleError.

func (RuleError) Error

func (e RuleError) Error() string

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

type SatoshiPerByte

type SatoshiPerByte float64

SatoshiPerByte is number with units of satoshis per byte.

func NewSatoshiPerByte

func NewSatoshiPerByte(fee bchutil.Amount, size uint32) SatoshiPerByte

NewSatoshiPerByte creates a SatoshiPerByte from an Amount and a size in bytes.

func (SatoshiPerByte) Fee

func (rate SatoshiPerByte) Fee(size uint32) bchutil.Amount

Fee returns the fee for a transaction of a given size for the given fee rate.

func (SatoshiPerByte) ToBchPerKb

func (rate SatoshiPerByte) ToBchPerKb() BchPerKilobyte

ToBchPerKb returns a float value that represents the given SatoshiPerByte converted to satoshis per kb.

type Tag

type Tag uint64

Tag represents an identifier to use for tagging orphan transactions. The caller may choose any scheme it desires, however it is common to use peer IDs so that orphans can be identified by which peer first relayed them.

type TxDesc

type TxDesc struct {
	mining.TxDesc
	// contains filtered or unexported fields
}

TxDesc is a descriptor containing a transaction in the mempool along with additional metadata.

type TxPool

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

TxPool is used as a source of transactions that need to be mined into blocks and relayed to other peers. It is safe for concurrent access from multiple peers.

func New

func New(cfg *Config) *TxPool

New returns a new memory pool for validating and storing standalone transactions until they are mined into a block.

func (*TxPool) CheckMempoolAcceptance added in v0.22.3

func (mp *TxPool) CheckMempoolAcceptance(tx *bchutil.Tx, maxFee bchutil.Amount) (*MempoolAcceptResult, error)

CheckMempoolAcceptance runs the checks that ProcessTransaction runs for a transaction submitted without orphan handling, without adding the transaction to the pool. A positive maxFee rejects transactions that pay more fees than that.

This function is safe for concurrent access.

func (*TxPool) CheckSpend

func (mp *TxPool) CheckSpend(op wire.OutPoint) *bchutil.Tx

CheckSpend checks whether the passed outpoint is already spent by a transaction in the mempool. If that's the case the spending transaction will be returned, if not nil will be returned.

func (*TxPool) Count

func (mp *TxPool) Count() int

Count returns the number of transactions in the main pool. It does not include the orphan pool.

This function is safe for concurrent access.

func (*TxPool) DSProofByHash added in v0.22.3

func (mp *TxPool) DSProofByHash(hash *chainhash.Hash) (*DSProofDesc, []chainhash.Hash)

DSProofByHash returns the proof with the given id, including orphans, and the descendants of the transaction it is for.

This function is safe for concurrent access.

func (*TxPool) DSProofByOutPoint added in v0.22.3

func (mp *TxPool) DSProofByOutPoint(op wire.OutPoint) (*DSProofDesc, []chainhash.Hash)

DSProofByOutPoint returns the proof of the memory pool transaction spending op, or when no transaction spends it, an orphan proof for it.

This function is safe for concurrent access.

func (*TxPool) DSProofByTx added in v0.22.3

func (mp *TxPool) DSProofByTx(txHash *chainhash.Hash, recursive bool) (desc *DSProofDesc,
	descendants []chainhash.Hash, path []chainhash.Hash, err error)

DSProofByTx returns the proof of a memory pool transaction. When recursive is set and the transaction has none, its unconfirmed ancestors are searched as well, and path lists the transactions from txHash to the one with the proof. The search fails with ErrDSProofSearchLimit after dsProofLookupMaxTxs ancestors.

This function is safe for concurrent access.

func (*TxPool) DSProofScore added in v0.22.3

func (mp *TxPool) DSProofScore(txHash *chainhash.Hash) (float64, error)

DSProofScore returns how far a memory pool transaction can be trusted not to be double spent: 1 when neither it nor an unconfirmed ancestor has a proof and proofs are possible for all of them, 0 when one has a proof or one cannot have a proof, and 0.25 when an input does not sign all inputs and outputs or the ancestors are too many to check.

This function is safe for concurrent access.

func (*TxPool) DSProofs added in v0.22.3

func (mp *TxPool) DSProofs(includeOrphans bool) []*DSProofDesc

DSProofs returns the proofs associated with memory pool transactions, and the orphans too when includeOrphans is set.

This function is safe for concurrent access.

func (*TxPool) DSProofsEnabled added in v0.22.3

func (mp *TxPool) DSProofsEnabled() bool

DSProofsEnabled returns whether double spend proofs are enabled.

func (*TxPool) DecodeCompressedBlock

func (mp *TxPool) DecodeCompressedBlock(iBlock interface{}) (*wire.MsgBlock, error)

DecodeCompressedBlock takes in a block interface and attempts to decode it according to know block compressing algorithms. If successful it returns the complete block.

func (*TxPool) Expire added in v0.22.3

func (mp *TxPool) Expire() int

Expire removes the transactions that entered the pool longer ago than BCHN's default -mempoolexpiry of two weeks, with the transactions that spend them, and returns how many it removed. Transactions a reorg put back below the minimum relay fee are never mined, so this is what removes them.

This function is safe for concurrent access.

func (*TxPool) ExpireDSProofOrphans added in v0.22.3

func (mp *TxPool) ExpireDSProofOrphans() []Tag

ExpireDSProofOrphans removes the orphan proofs that have been waiting for longer than the orphan TTL and returns the peers that sent them.

This function is safe for concurrent access.

func (*TxPool) FetchDSProof added in v0.22.3

func (mp *TxPool) FetchDSProof(hash *chainhash.Hash) (*wire.MsgDSProof, error)

FetchDSProof returns the proof with the given id, including orphans.

This function is safe for concurrent access.

func (*TxPool) FetchInputUtxos

func (mp *TxPool) FetchInputUtxos(tx *bchutil.Tx) (*blockchain.UtxoViewpoint, error)

FetchInputUtxos loads utxo details about the input transactions referenced by the passed transaction. First, it loads the details form the viewpoint of the main chain, then it adjusts them based upon the contents of the transaction pool.

This function is safe for concurrent access.

func (*TxPool) FetchTransaction

func (mp *TxPool) FetchTransaction(txHash *chainhash.Hash) (*bchutil.Tx, error)

FetchTransaction returns the requested transaction from the transaction pool. This only fetches from the main transaction pool and does not include orphans.

This function is safe for concurrent access.

func (*TxPool) FetchTxDesc

func (mp *TxPool) FetchTxDesc(txHash *chainhash.Hash) (*TxDesc, error)

FetchTxDesc returns the requested transaction description from the transaction pool. This only fetches from the main transaction pool and does not include orphans.

This function is safe for concurrent access.

func (*TxPool) FetchUtxoView added in v0.14.7

func (mp *TxPool) FetchUtxoView(tx *bchutil.Tx) (*blockchain.UtxoViewpoint, error)

FetchUtxoView loads utxo details about the transactions inputs and outputs. First, it loads the details form the viewpoint of the main chain, then it adjusts them based upon the contents of the transaction pool.

This function is safe for concurrent access.

func (*TxPool) HaveDSProof added in v0.22.3

func (mp *TxPool) HaveDSProof(hash *chainhash.Hash) bool

HaveDSProof returns whether the proof is known, as an orphan or not, or was recently rejected. It always returns true when proofs are disabled, so they are never requested.

This function is safe for concurrent access.

func (*TxPool) HaveTransaction

func (mp *TxPool) HaveTransaction(hash *chainhash.Hash) bool

HaveTransaction returns whether or not the passed transaction already exists in the main pool or in the orphan pool.

This function is safe for concurrent access.

func (*TxPool) IsOrphanInPool

func (mp *TxPool) IsOrphanInPool(hash *chainhash.Hash) bool

IsOrphanInPool returns whether or not the passed transaction already exists in the orphan pool.

This function is safe for concurrent access.

func (*TxPool) IsTransactionInPool

func (mp *TxPool) IsTransactionInPool(hash *chainhash.Hash) bool

IsTransactionInPool returns whether or not the passed transaction already exists in the main pool.

This function is safe for concurrent access.

func (*TxPool) LastUpdated

func (mp *TxPool) LastUpdated() time.Time

LastUpdated returns the last time a transaction was added to or removed from the main pool. It does not include the orphan pool.

This function is safe for concurrent access.

func (*TxPool) MaybeAcceptTransaction

func (mp *TxPool) MaybeAcceptTransaction(tx *bchutil.Tx, isNew bool) ([]*chainhash.Hash, *TxDesc, error)

MaybeAcceptTransaction is the main workhorse for handling insertion of new free-standing transactions into a memory pool. It includes functionality such as rejecting duplicate transactions, ensuring transactions follow all rules, detecting orphan transactions, and insertion into the memory pool.

If the transaction is an orphan (missing parent transactions), the transaction is NOT added to the orphan pool, but each unknown referenced parent is returned. Use ProcessTransaction instead if new orphans should be added to the orphan pool.

This function is safe for concurrent access.

func (*TxPool) MiningDescs

func (mp *TxPool) MiningDescs() []*mining.TxDesc

MiningDescs returns a slice of mining descriptors for all the transactions in the pool.

This is part of the mining.TxSource interface implementation and is safe for concurrent access as required by the interface contract.

func (*TxPool) ProcessDSProof added in v0.22.3

func (mp *TxPool) ProcessDSProof(proof *wire.MsgDSProof, peer Tag, hasPeer bool) (DSProofResult, error)

ProcessDSProof checks a double spend proof received from peer and stores it when it is valid or cannot be checked yet. An error means the proof is invalid; its id is then remembered as rejected, and the proof is not checked again while it is.

This function is safe for concurrent access.

func (*TxPool) ProcessOrphans

func (mp *TxPool) ProcessOrphans(acceptedTx *bchutil.Tx) []*TxDesc

ProcessOrphans determines if there are any orphans which depend on the passed transaction hash (it is possible that they are no longer orphans) and potentially accepts them to the memory pool. It repeats the process for the newly accepted transactions (to detect further orphans which may no longer be orphans) until there are no more.

It returns a slice of transactions added to the mempool. A nil slice means no transactions were moved from the orphan pool to the mempool.

This function is safe for concurrent access.

func (*TxPool) ProcessTransaction

func (mp *TxPool) ProcessTransaction(tx *bchutil.Tx, allowOrphan bool, tag Tag) ([]*TxDesc, error)

ProcessTransaction is the main workhorse for handling insertion of new free-standing transactions into the memory pool. It includes functionality such as rejecting duplicate transactions, ensuring transactions follow all rules, orphan transaction handling, and insertion into the memory pool.

It returns a slice of transactions added to the mempool. When the error is nil, the list will include the passed transaction itself along with any additional orphan transaactions that were added as a result of the passed one being accepted.

The orphan pool is only treated as a source of duplicates when the caller allows orphans, which is to say for peer relay. See the note on the maybeAcceptTransaction call below.

This function is safe for concurrent access.

func (*TxPool) ProcessTransactionWithMaxFee added in v0.22.3

func (mp *TxPool) ProcessTransactionWithMaxFee(tx *bchutil.Tx, allowOrphan bool, tag Tag, maxFee bchutil.Amount) ([]*TxDesc, error)

ProcessTransactionWithMaxFee is like ProcessTransaction, but also rejects the transaction when it pays more fees than a positive maxFee.

This function is safe for concurrent access.

func (*TxPool) RawMempoolVerbose

func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseResult

RawMempoolVerbose returns all of the entries in the mempool as a fully populated btcjson result. The lock is held only to take the pool's descriptors, which do not change, and the result is built from them after it is released, so writers do not wait for the whole result, which takes about a microsecond per transaction.

This function is safe for concurrent access.

func (*TxPool) RemoveDSProofOrphansByTag added in v0.22.3

func (mp *TxPool) RemoveDSProofOrphansByTag(tag Tag) uint64

RemoveDSProofOrphansByTag removes the orphan double spend proofs sent by the peer with the passed tag, which has disconnected, and returns how many.

This function is safe for concurrent access.

func (*TxPool) RemoveDoubleSpends

func (mp *TxPool) RemoveDoubleSpends(tx *bchutil.Tx)

RemoveDoubleSpends removes all transactions which spend outputs spent by the passed transaction from the memory pool. Removing those transactions then leads to removing all transactions which rely on them, recursively. This is necessary when a block is connected to the main chain because the block may contain transactions which were previously unknown to the memory pool.

This function is safe for concurrent access.

func (*TxPool) RemoveOrphan

func (mp *TxPool) RemoveOrphan(tx *bchutil.Tx)

RemoveOrphan removes the passed orphan transaction from the orphan pool and previous orphan index.

This function is safe for concurrent access.

func (*TxPool) RemoveOrphansByTag

func (mp *TxPool) RemoveOrphansByTag(tag Tag) uint64

RemoveOrphansByTag removes all orphan transactions tagged with the provided identifier.

This function is safe for concurrent access.

func (*TxPool) RemoveTransaction

func (mp *TxPool) RemoveTransaction(tx *bchutil.Tx, removeRedeemers bool)

RemoveTransaction removes the passed transaction from the mempool. When the removeRedeemers flag is set, any transactions that redeem outputs from the removed transaction will also be removed recursively from the mempool, as they would otherwise become orphans.

This function is safe for concurrent access.

func (*TxPool) TxDescs

func (mp *TxPool) TxDescs() []*TxDesc

TxDescs returns a slice of descriptors for all the transactions in the pool. The descriptors are to be treated as read only.

This function is safe for concurrent access.

func (*TxPool) TxHashes

func (mp *TxPool) TxHashes() []*chainhash.Hash

TxHashes returns a slice of hashes for all of the transactions in the memory pool.

This function is safe for concurrent access.

type TxRuleError

type TxRuleError struct {
	RejectCode  wire.RejectCode // The code to send with reject messages
	Reason      string          // BCHN's short reason, such as "dust"
	Description string          // Human readable description of the issue
}

TxRuleError identifies a rule violation. It is used to indicate that processing of a 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 ErrorCode field to ascertain the specific reason for the rule violation.

func (TxRuleError) Error

func (e TxRuleError) Error() string

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

Jump to

Keyboard shortcuts

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