Skip to content

Commit 91532bd

Browse files
committed
tx fees, policy: update CBlockPolicyEstimator::processBlock parameter
Update `processBlock` parameter to reference to a vector of `RemovedMempoolTransactionInfo`.
1 parent bfcd401 commit 91532bd

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

src/policy/fees.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,18 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
618618
assert(bucketIndex == bucketIndex3);
619619
}
620620

621-
bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
621+
bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const RemovedMempoolTransactionInfo& tx)
622622
{
623623
AssertLockHeld(m_cs_fee_estimator);
624-
if (!_removeTx(entry->GetTx().GetHash(), true)) {
624+
if (!_removeTx(tx.info.m_tx->GetHash(), true)) {
625625
// This transaction wasn't being tracked for fee estimation
626626
return false;
627627
}
628628

629629
// How many blocks did it take for miners to include this transaction?
630630
// blocksToConfirm is 1-based, so a transaction included in the earliest
631631
// possible block has confirmation count of 1
632-
int blocksToConfirm = nBlockHeight - entry->GetHeight();
632+
int blocksToConfirm = nBlockHeight - tx.info.txHeight;
633633
if (blocksToConfirm <= 0) {
634634
// This can't happen because we don't process transactions from a block with a height
635635
// lower than our greatest seen height
@@ -638,16 +638,16 @@ bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
638638
}
639639

640640
// Feerates are stored and reported as BTC-per-kb:
641-
CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());
641+
CFeeRate feeRate(tx.info.m_fee, tx.info.m_virtual_transaction_size);
642642

643643
feeStats->Record(blocksToConfirm, static_cast<double>(feeRate.GetFeePerK()));
644644
shortStats->Record(blocksToConfirm, static_cast<double>(feeRate.GetFeePerK()));
645645
longStats->Record(blocksToConfirm, static_cast<double>(feeRate.GetFeePerK()));
646646
return true;
647647
}
648648

649-
void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
650-
std::vector<const CTxMemPoolEntry*>& entries)
649+
void CBlockPolicyEstimator::processBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block,
650+
unsigned int nBlockHeight)
651651
{
652652
LOCK(m_cs_fee_estimator);
653653
if (nBlockHeight <= nBestSeenHeight) {
@@ -676,8 +676,8 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
676676

677677
unsigned int countedTxs = 0;
678678
// Update averages with data points from current block
679-
for (const auto& entry : entries) {
680-
if (processBlockTx(nBlockHeight, entry))
679+
for (const auto& tx : txs_removed_for_block) {
680+
if (processBlockTx(nBlockHeight, tx))
681681
countedTxs++;
682682
}
683683

@@ -688,7 +688,7 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
688688

689689

690690
LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy estimates updated by %u of %u block txs, since last block %u of %u tracked, mempool map size %u, max target %u from %s\n",
691-
countedTxs, entries.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size(),
691+
countedTxs, txs_removed_for_block.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size(),
692692
MaxUsableEstimate(), HistoricalBlockSpan() > BlockSpan() ? "historical" : "current");
693693

694694
trackedTxs = 0;

src/policy/fees.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static constexpr bool DEFAULT_ACCEPT_STALE_FEE_ESTIMATES{false};
3737
class AutoFile;
3838
class CTxMemPoolEntry;
3939
class TxConfirmStats;
40+
struct RemovedMempoolTransactionInfo;
4041

4142
/* Identifier for each of the 3 different TxConfirmStats which will track
4243
* history over different time horizons. */
@@ -201,8 +202,8 @@ class CBlockPolicyEstimator
201202
~CBlockPolicyEstimator();
202203

203204
/** Process all the transactions that have been included in a block */
204-
void processBlock(unsigned int nBlockHeight,
205-
std::vector<const CTxMemPoolEntry*>& entries)
205+
void processBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block,
206+
unsigned int nBlockHeight)
206207
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
207208

208209
/** Process a transaction accepted to the mempool*/
@@ -290,7 +291,7 @@ class CBlockPolicyEstimator
290291
std::map<double, unsigned int> bucketMap GUARDED_BY(m_cs_fee_estimator); // Map of bucket upper-bound to index into all vectors by bucket
291292

292293
/** Process a transaction confirmed in a block*/
293-
bool processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry) EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
294+
bool processBlockTx(unsigned int nBlockHeight, const RemovedMempoolTransactionInfo& tx) EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
294295

295296
/** Helper for estimateSmartFee */
296297
double estimateCombinedFee(unsigned int confTarget, double successThreshold, bool checkShorterHorizon, EstimationResult *result) const EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);

src/test/fuzz/policy_estimator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
6161
const CTransaction tx{*mtx};
6262
mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
6363
}
64-
std::vector<const CTxMemPoolEntry*> ptrs;
65-
ptrs.reserve(mempool_entries.size());
64+
std::vector<RemovedMempoolTransactionInfo> txs;
65+
txs.reserve(mempool_entries.size());
6666
for (const CTxMemPoolEntry& mempool_entry : mempool_entries) {
67-
ptrs.push_back(&mempool_entry);
67+
txs.emplace_back(mempool_entry);
6868
}
69-
block_policy_estimator.processBlock(fuzzed_data_provider.ConsumeIntegral<unsigned int>(), ptrs);
69+
block_policy_estimator.processBlock(txs, fuzzed_data_provider.ConsumeIntegral<unsigned int>());
7070
},
7171
[&] {
7272
(void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider), /*inBlock=*/fuzzed_data_provider.ConsumeBool());

src/txmempool.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -643,17 +643,6 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
643643
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
644644
{
645645
AssertLockHeld(cs);
646-
std::vector<const CTxMemPoolEntry*> entries;
647-
for (const auto& tx : vtx)
648-
{
649-
uint256 hash = tx->GetHash();
650-
651-
indexed_transaction_set::iterator i = mapTx.find(hash);
652-
if (i != mapTx.end())
653-
entries.push_back(&*i);
654-
}
655-
// Before the txs in the new block have been removed from the mempool, update policy estimates
656-
if (minerPolicyEstimator) {minerPolicyEstimator->processBlock(nBlockHeight, entries);}
657646
std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
658647
txs_removed_for_block.reserve(vtx.size());
659648
for (const auto& tx : vtx)
@@ -668,6 +657,10 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
668657
removeConflicts(*tx);
669658
ClearPrioritisation(tx->GetHash());
670659
}
660+
// Update policy estimates
661+
if (minerPolicyEstimator) {
662+
minerPolicyEstimator->processBlock(txs_removed_for_block, nBlockHeight);
663+
}
671664
GetMainSignals().MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);
672665
lastRollingFeeUpdate = GetTime();
673666
blockSinceLastRollingFeeBump = true;

0 commit comments

Comments
 (0)