Skip to content

Commit

Permalink
Pass pointers to existing CTxMemPoolEntries to fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
morcos authored and random-zebra committed Jul 8, 2021
1 parent be5982e commit d23ebfd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/policy/fees.cpp
Expand Up @@ -337,22 +337,22 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
}

void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry)
void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
{
if(entry.HasZerocoins() || entry.IsShielded()) {
if(entry->HasZerocoins() || entry->IsShielded()) {
// Zerocoin spends/mints had fixed feerate. Skip them for the estimates.
return;
}

if (!removeTx(entry.GetTx().GetHash())) {
if (!removeTx(entry->GetTx().GetHash())) {
// This transaction wasn't being tracked for fee estimation
return;
}

// How many blocks did it take for miners to include this transaction?
// blocksToConfirm is 1-based, so a transaction included in the earliest
// possible block has confirmation count of 1
int blocksToConfirm = nBlockHeight - entry.GetHeight();
int blocksToConfirm = nBlockHeight - entry->GetHeight();
if (blocksToConfirm <= 0) {
// This can't happen because we don't process transactions from a block with a height
// lower than our greatest seen height
Expand All @@ -361,13 +361,13 @@ void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxM
}

// Feerates are stored and reported as PIV-per-kb:
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());

feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
}

void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
std::vector<CTxMemPoolEntry>& entries)
std::vector<const CTxMemPoolEntry*>& entries)
{
if (nBlockHeight <= nBestSeenHeight) {
// Ignore side chains and re-orgs; assuming they are random
Expand Down
4 changes: 2 additions & 2 deletions src/policy/fees.h
Expand Up @@ -205,10 +205,10 @@ class CBlockPolicyEstimator

/** Process all the transactions that have been included in a block */
void processBlock(unsigned int nBlockHeight,
std::vector<CTxMemPoolEntry>& entries);
std::vector<const CTxMemPoolEntry*>& entries);

/** Process a transaction confirmed in a block*/
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry);
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry);

/** Process a transaction accepted to the mempool*/
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate);
Expand Down
4 changes: 2 additions & 2 deletions src/txmempool.cpp
Expand Up @@ -845,12 +845,12 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx)
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
{
LOCK(cs);
std::vector<CTxMemPoolEntry> entries;
std::vector<const CTxMemPoolEntry*> entries;
for (const auto& tx : vtx) {
uint256 hash = tx->GetHash();
indexed_transaction_set::iterator i = mapTx.find(hash);
if (i != mapTx.end())
entries.push_back(*i);
entries.push_back(&*i);
}
// Before the txs in the new block have been removed from the mempool, update policy estimates
minerPolicyEstimator->processBlock(nBlockHeight, entries);
Expand Down

0 comments on commit d23ebfd

Please sign in to comment.