aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-12-01 14:58:14 -0500
committerAndrew Chow <github@achow101.com>2023-12-01 15:07:23 -0500
commita97a89244e9100e3e6ba1a14d4f5e86d6eb2e86e (patch)
treef27ea665a91f5770d08ecc4a62b7460fe1cc0975 /src/kernel
parent18bed148af65746dd3a0066fefc5b48f9729c1b6 (diff)
parent91504cbe0de2b74ef1aa2709761aaf0597ec66a2 (diff)
downloadbitcoin-a97a89244e9100e3e6ba1a14d4f5e86d6eb2e86e.tar.xz
Merge bitcoin/bitcoin#28368: Fee Estimator updates from Validation Interface/CScheduler thread
91504cbe0de2b74ef1aa2709761aaf0597ec66a2 rpc: `SyncWithValidationInterfaceQueue` on fee estimation RPC's (ismaelsadeeq) 714523918ba2b853fc69bee6b04a33ba0c828bf5 tx fees, policy: CBlockPolicyEstimator update from `CValidationInterface` notifications (ismaelsadeeq) dff5ad3b9944cbb56126ba37a8da180d1327ba39 CValidationInterface: modify the parameter of `TransactionAddedToMempool` (ismaelsadeeq) 91532bd38223d7d04166e05de11d0d0b55e60f13 tx fees, policy: update `CBlockPolicyEstimator::processBlock` parameter (ismaelsadeeq) bfcd401368fc0dc43827a8969a37b7e038d5ca79 CValidationInterface, mempool: add new callback to `CValidationInterface` (ismaelsadeeq) 0889e07987294d4ef2814abfca16d8e2a0c5f541 tx fees, policy: cast with static_cast instead of C-Style cast (ismaelsadeeq) a0e3eb7549d2ba4dd3af12b9ce65e29158f59078 tx fees, policy: bugfix: move `removeTx` into reason != `BLOCK` condition (ismaelsadeeq) Pull request description: This is an attempt to #11775 This Pr will enable fee estimator to listen to ValidationInterface notifications to process new transactions added and removed from the mempool. This PR includes the following changes: - Added a new callback to the Validation Interface `MempoolTransactionsRemovedForConnectedBlock`, which notifies listeners about the transactions that have been removed due to a new block being connected, along with the height at which the transactions were removed. - Modified the `TransactionAddedToMempool` callback parameter to include additional information about the transaction needed for fee estimation. - Updated `CBlockPolicyEstimator` to process transactions using` CTransactionRef` instead of `CTxMempoolEntry.` - Implemented the `CValidationInterface` interface in `CBlockPolicyEstimater` and overridden the `TransactionAddedToMempool`, `TransactionRemovedFromMempool`, and `MempoolTransactionsRemovedForConnectedBlock` methods to receive updates from their notifications. Prior to this PR, the fee estimator updates from the mempool, i.e whenever a new block is connected all transactions in the block that are in our mempool are going to be removed using the `removeForBlock` function in `txmempool.cpp`. This removal triggered updates to the fee estimator. As a result, the fee estimator would block mempool's `cs` until it finished updating every time a new block was connected. Instead of being blocked only on mempool tx removal, we were blocking on both tx removal and fee estimator updating. If we want to further improve fee estimation, or add heavy-calulation steps to it, it is currently not viable as we would be slowing down block relay in the process This PR is smaller in terms of the changes made compared to #11775, as it focuses solely on enabling fee estimator updates from the validationInterface/cscheduler thread notifications. I have not split the validation interface because, as I understand it, the rationale behind the split in #11775 was to have `MempoolInterface` signals come from the mempool and `CValidationInterface` events come from validation. I believe this separation can be achieved in a separate refactoring PR when the need arises. Also left out some commits from #11775 - Some refactoring which are no longer needed. - Handle reorgs much better in fee estimator. - Track witness hash malleation in fee estimator I believe they are a separate change that can come in a follow-up after this. ACKs for top commit: achow101: ACK 91504cbe0de2b74ef1aa2709761aaf0597ec66a2 TheCharlatan: Re-ACK 91504cbe0de2b74ef1aa2709761aaf0597ec66a2 willcl-ark: ACK 91504cbe0de2b74ef1aa2709761aaf0597ec66a2 Tree-SHA512: 846dfb9da57a8a42458827b8975722d153907fe6302ad65748d74f311e1925557ad951c3d95fe71fb90ddcc8a3710c45abb343ab86b88780871cb9c38c72c7b1
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/mempool_entry.h59
-rw-r--r--src/kernel/mempool_options.h4
2 files changed, 59 insertions, 4 deletions
diff --git a/src/kernel/mempool_entry.h b/src/kernel/mempool_entry.h
index b5c0499012..bd39c9cc5f 100644
--- a/src/kernel/mempool_entry.h
+++ b/src/kernel/mempool_entry.h
@@ -190,4 +190,63 @@ public:
using CTxMemPoolEntryRef = CTxMemPoolEntry::CTxMemPoolEntryRef;
+struct TransactionInfo {
+ const CTransactionRef m_tx;
+ /* The fee the transaction paid */
+ const CAmount m_fee;
+ /**
+ * The virtual transaction size.
+ *
+ * This is a policy field which considers the sigop cost of the
+ * transaction as well as its weight, and reinterprets it as bytes.
+ *
+ * It is the primary metric by which the mining algorithm selects
+ * transactions.
+ */
+ const int64_t m_virtual_transaction_size;
+ /* The block height the transaction entered the mempool */
+ const unsigned int txHeight;
+
+ TransactionInfo(const CTransactionRef& tx, const CAmount& fee, const int64_t vsize, const unsigned int height)
+ : m_tx{tx},
+ m_fee{fee},
+ m_virtual_transaction_size{vsize},
+ txHeight{height} {}
+};
+
+struct RemovedMempoolTransactionInfo {
+ TransactionInfo info;
+ explicit RemovedMempoolTransactionInfo(const CTxMemPoolEntry& entry)
+ : info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}
+};
+
+struct NewMempoolTransactionInfo {
+ TransactionInfo info;
+ /*
+ * This boolean indicates whether the transaction was added
+ * without enforcing mempool fee limits.
+ */
+ const bool m_from_disconnected_block;
+ /* This boolean indicates whether the transaction is part of a package. */
+ const bool m_submitted_in_package;
+ /*
+ * This boolean indicates whether the blockchain is up to date when the
+ * transaction is added to the mempool.
+ */
+ const bool m_chainstate_is_current;
+ /* Indicates whether the transaction has unconfirmed parents. */
+ const bool m_has_no_mempool_parents;
+
+ explicit NewMempoolTransactionInfo(const CTransactionRef& tx, const CAmount& fee,
+ const int64_t vsize, const unsigned int height,
+ const bool from_disconnected_block, const bool submitted_in_package,
+ const bool chainstate_is_current,
+ const bool has_no_mempool_parents)
+ : info{tx, fee, vsize, height},
+ m_from_disconnected_block{from_disconnected_block},
+ m_submitted_in_package{submitted_in_package},
+ m_chainstate_is_current{chainstate_is_current},
+ m_has_no_mempool_parents{has_no_mempool_parents} {}
+};
+
#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
diff --git a/src/kernel/mempool_options.h b/src/kernel/mempool_options.h
index d09fd2ba35..753aebd455 100644
--- a/src/kernel/mempool_options.h
+++ b/src/kernel/mempool_options.h
@@ -13,8 +13,6 @@
#include <cstdint>
#include <optional>
-class CBlockPolicyEstimator;
-
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
/** Default for -maxmempool when blocksonly is set */
@@ -37,8 +35,6 @@ namespace kernel {
* Most of the time, this struct should be referenced as CTxMemPool::Options.
*/
struct MemPoolOptions {
- /* Used to estimate appropriate transaction fees. */
- CBlockPolicyEstimator* estimator{nullptr};
/* The ratio used to determine how often sanity checks will run. */
int check_ratio{0};
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};