Skip to content

Commit

Permalink
[refactor] change MiniMinerMempoolEntry ctor to take values, update i…
Browse files Browse the repository at this point in the history
…ncludes

No behavior change. All we are doing is copying out these values before
passing them into the ctor instead of within the ctor.

This makes it possible to use the MiniMiner algorithms to analyze
transactions that haven't been submitted to the mempool yet.

It also iwyu's the mini_miner includes.
  • Loading branch information
glozow committed Nov 3, 2023
1 parent 4aa98b7 commit e3b2e63
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

#include <node/mini_miner.h>

#include <boost/multi_index/detail/hash_index_iterator.hpp>
#include <boost/operators.hpp>
#include <consensus/amount.h>
#include <policy/feerate.h>
#include <primitives/transaction.h>
#include <sync.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/check.h>

#include <algorithm>
Expand Down Expand Up @@ -72,7 +77,12 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
// Add every entry to m_entries_by_txid and m_entries, except the ones that will be replaced.
for (const auto& txiter : cluster) {
if (!m_to_be_replaced.count(txiter->GetTx().GetHash())) {
auto [mapiter, success] = m_entries_by_txid.emplace(txiter->GetTx().GetHash(), MiniMinerMempoolEntry(txiter));
auto [mapiter, success] = m_entries_by_txid.emplace(txiter->GetTx().GetHash(),
MiniMinerMempoolEntry{/*fee_self=*/txiter->GetModifiedFee(),
/*fee_ancestor=*/txiter->GetModFeesWithAncestors(),
/*vsize_self=*/txiter->GetTxSize(),
/*vsize_ancestor=*/txiter->GetSizeWithAncestors(),
/*tx_in=*/txiter->GetSharedTx()});
m_entries.push_back(mapiter);
} else {
auto outpoints_it = m_requested_outpoints_by_txid.find(txiter->GetTx().GetHash());
Expand Down
30 changes: 21 additions & 9 deletions src/node/mini_miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,45 @@
#ifndef BITCOIN_NODE_MINI_MINER_H
#define BITCOIN_NODE_MINI_MINER_H

#include <txmempool.h>
#include <consensus/amount.h>
#include <primitives/transaction.h>
#include <uint256.h>

#include <map>
#include <memory>
#include <optional>
#include <set>
#include <stdint.h>
#include <vector>

class CFeeRate;
class CTxMemPool;

namespace node {

// Container for tracking updates to ancestor feerate as we include ancestors in the "block"
class MiniMinerMempoolEntry
{
const CAmount fee_individual;
const CTransactionRef tx;
const int64_t vsize_individual;
CAmount fee_with_ancestors;
int64_t vsize_with_ancestors;
const CAmount fee_individual;
CAmount fee_with_ancestors;

// This class must be constructed while holding mempool.cs. After construction, the object's
// methods can be called without holding that lock.

public:
explicit MiniMinerMempoolEntry(CTxMemPool::txiter entry) :
fee_individual{entry->GetModifiedFee()},
tx{entry->GetSharedTx()},
vsize_individual(entry->GetTxSize()),
fee_with_ancestors{entry->GetModFeesWithAncestors()},
vsize_with_ancestors(entry->GetSizeWithAncestors())
explicit MiniMinerMempoolEntry(CAmount fee_self,
CAmount fee_ancestor,
int64_t vsize_self,
int64_t vsize_ancestor,
const CTransactionRef& tx_in):
tx{tx_in},
vsize_individual{vsize_self},
vsize_with_ancestors{vsize_ancestor},
fee_individual{fee_self},
fee_with_ancestors{fee_ancestor}
{ }

CAmount GetModifiedFee() const { return fee_individual; }
Expand Down

0 comments on commit e3b2e63

Please sign in to comment.