Documentation ¶
Index ¶
- Constants
- func CalcPriority(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextBlockHeight int64) float64
- func DisableLog()
- func ErrToRejectErr(err error) (wire.RejectCode, string)
- func UseLogger(logger btclog.Logger)
- type Config
- type Policy
- type RuleError
- type TxDesc
- type TxPool
- func (mp *TxPool) CheckIfTxsExist(hashes []chainhash.Hash) bool
- func (mp *TxPool) Count() int
- func (mp *TxPool) FetchTransaction(txHash *chainhash.Hash, includeRecentBlock bool) (*dcrutil.Tx, error)
- func (mp *TxPool) HaveTransaction(hash *chainhash.Hash) bool
- func (mp *TxPool) HaveTransactions(hashes []*chainhash.Hash) []bool
- func (mp *TxPool) IsOrphanInPool(hash *chainhash.Hash) bool
- func (mp *TxPool) IsTransactionInPool(hash *chainhash.Hash) bool
- func (mp *TxPool) IsTxTreeValid(best *chainhash.Hash) bool
- func (mp *TxPool) LastUpdated() time.Time
- func (mp *TxPool) MaybeAcceptTransaction(tx *dcrutil.Tx, isNew, rateLimit bool) ([]*chainhash.Hash, error)
- func (mp *TxPool) MiningDescs() []*mining.TxDesc
- func (mp *TxPool) ProcessOrphans(hash *chainhash.Hash) []*dcrutil.Tx
- func (mp *TxPool) ProcessTransaction(tx *dcrutil.Tx, allowOrphan, rateLimit, allowHighFees bool) ([]*dcrutil.Tx, error)
- func (mp *TxPool) PruneExpiredTx(height int64)
- func (mp *TxPool) PruneStakeTx(requiredStakeDifficulty, height int64)
- func (mp *TxPool) RawMempoolVerbose(filterType *stake.TxType) map[string]*dcrjson.GetRawMempoolVerboseResult
- func (mp *TxPool) RemoveDoubleSpends(tx *dcrutil.Tx)
- func (mp *TxPool) RemoveOrphan(txHash *chainhash.Hash)
- func (mp *TxPool) RemoveTransaction(tx *dcrutil.Tx, removeRedeemers bool)
- func (mp *TxPool) TxDescs() []*TxDesc
- func (mp *TxPool) TxHashes() []*chainhash.Hash
- func (mp *TxPool) VoteHashesForBlock(blockHash chainhash.Hash) []chainhash.Hash
- func (mp *TxPool) VotesForBlocks(hashes []chainhash.Hash) [][]*VoteTx
- type TxRuleError
- type VoteTx
Constants ¶
const ( // DefaultBlockPrioritySize is the default size in bytes for high- // priority / low-fee transactions. It is used to help determine which // are allowed into the mempool and consequently affects their relay and // inclusion when generating block templates. DefaultBlockPrioritySize = 20000 // MinHighPriority is the minimum priority value that allows a // transaction to be considered high priority. MinHighPriority = dcrutil.AtomsPerCoin * 144.0 / 250 )
const ( // DefaultMinRelayTxFee is the minimum fee in atoms that is required for // a transaction to be treated as free for relay and mining purposes. // It is also used to help determine if a transaction is considered dust // and as a base for calculating minimum required fees for larger // transactions. This value is in Atoms/1000 bytes. DefaultMinRelayTxFee = dcrutil.Amount(1e6) )
Variables ¶
This section is empty.
Functions ¶
func CalcPriority ¶
func CalcPriority(tx *wire.MsgTx, utxoView *blockchain.UtxoViewpoint, nextBlockHeight int64) 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 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.
Types ¶
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 // NewestHash defines the function to retrieve the newest sha. NewestHash func() (*chainhash.Hash, int64, error) // NextStakeDifficulty defines the function to retrieve the stake // difficulty for the block after the current best block. // // This function must be safe for concurrent access. NextStakeDifficulty func() (int64, error) // FetchUtxoView defines the function to use to fetch unspent // transaction output information. FetchUtxoView func(*dcrutil.Tx, bool) (*blockchain.UtxoViewpoint, error) // Chain defines the concurrent safe block chain instance which houses // the current best chain. Chain *blockchain.BlockChain // SigCache defines a signature cache to use. SigCache *txscript.SigCache // TimeSource defines the timesource to use. TimeSource blockchain.MedianTimeSource // 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 // ExistsAddrIndex defines the optional exists 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. ExistsAddrIndex *indexers.ExistsAddrIndex }
Config is a descriptor containing the memory pool configuration.
type Policy ¶
type Policy struct { // DisableRelayPriority defines whether to relay free or low-fee // transactions that do not have enough priority to be relayed. DisableRelayPriority bool // FreeTxRelayLimit defines the given amount in thousands of bytes // per minute that transactions with no fee are rate limited to. FreeTxRelayLimit float64 // 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 // MaxSigOpsPerTx is the maximum number of signature operations // in a single transaction we will relay or mine. It is a fraction // of the max signature operations for a block. MaxSigOpsPerTx int // MinRelayTxFee defines the minimum transaction fee in BTC/kB to be // considered a non-zero fee. MinRelayTxFee dcrutil.Amount // AllowOldVotes defines whether or not votes on old blocks will be // admitted and relayed. AllowOldVotes bool }
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.
type TxDesc ¶
type TxDesc struct { mining.TxDesc // StartingPriority is the priority of the transaction when it was added // to the pool. StartingPriority float64 }
TxDesc is a descriptor containing a transaction in the mempool along with additional metadata.
type TxPool ¶
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 ¶
New returns a new memory pool for validating and storing standalone transactions until they are mined into a block.
func (*TxPool) CheckIfTxsExist ¶
CheckIfTxsExist checks a list of transaction hashes against the mempool and returns true if they all exist in the mempool, otherwise false.
This function is safe for concurrent access.
func (*TxPool) Count ¶
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) FetchTransaction ¶
func (mp *TxPool) FetchTransaction(txHash *chainhash.Hash, includeRecentBlock bool) (*dcrutil.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) HaveTransaction ¶
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) HaveTransactions ¶
HaveTransactions returns whether or not the passed transactions already exist in the main pool or in the orphan pool.
This function is safe for concurrent access.
func (*TxPool) IsOrphanInPool ¶
IsOrphanInPool returns whether or not the passed transaction already exists in the orphan pool.
This function is safe for concurrent access.
func (*TxPool) IsTransactionInPool ¶
IsTransactionInPool returns whether or not the passed transaction already exists in the main pool.
This function is safe for concurrent access.
func (*TxPool) IsTxTreeValid ¶
IsTxTreeValid calls isTxTreeValid, but makes it safe for concurrent access.
func (*TxPool) LastUpdated ¶
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 *dcrutil.Tx, isNew, rateLimit bool) ([]*chainhash.Hash, 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, orphan transaction handling, and insertion into the memory pool. The isOrphan parameter can be nil if the caller does not need to know whether or not the transaction is an orphan.
This function is safe for concurrent access.
func (*TxPool) MiningDescs ¶
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) ProcessOrphans ¶
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 *dcrutil.Tx, allowOrphan, rateLimit, allowHighFees bool) ([]*dcrutil.Tx, 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.
This function is safe for concurrent access.
func (*TxPool) PruneExpiredTx ¶
PruneExpiredTx prunes expired transactions from the mempool that may no longer be able to be included into a block.
func (*TxPool) PruneStakeTx ¶
PruneStakeTx is the function which is called every time a new block is processed. The idea is any outstanding SStx that hasn't been mined in a certain period of time (CoinbaseMaturity) and the submitted SStx's stake difficulty is below the current required stake difficulty should be pruned from mempool since they will never be mined. The same idea stands for SSGen and SSRtx
func (*TxPool) RawMempoolVerbose ¶
func (mp *TxPool) RawMempoolVerbose(filterType *stake.TxType) map[string]*dcrjson.GetRawMempoolVerboseResult
RawMempoolVerbose returns all of the entries in the mempool filtered by the provided stake type as a fully populated JSON result. The filter type can be nil in which case all transactions will be returned.
This function is safe for concurrent access.
func (*TxPool) RemoveDoubleSpends ¶
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 ¶
RemoveOrphan removes the passed orphan transaction from the orphan pool and previous orphan index.
This function is safe for concurrent access.
func (*TxPool) RemoveTransaction ¶
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 ¶
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 ¶
TxHashes returns a slice of hashes for all of the transactions in the memory pool.
This function is safe for concurrent access.
func (*TxPool) VoteHashesForBlock ¶
VoteHashesForBlock returns the hashes for all votes on the provided block hash that are currently available in the mempool.
This function is safe for concurrent access.
type TxRuleError ¶
type TxRuleError struct { RejectCode wire.RejectCode // The code to send with reject messages 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.