Skip to content

Commit e3b2e63

Browse files
committed
[refactor] change MiniMinerMempoolEntry ctor to take values, update includes
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.
1 parent 4aa98b7 commit e3b2e63

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/node/mini_miner.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
#include <node/mini_miner.h>
66

7+
#include <boost/multi_index/detail/hash_index_iterator.hpp>
8+
#include <boost/operators.hpp>
79
#include <consensus/amount.h>
810
#include <policy/feerate.h>
911
#include <primitives/transaction.h>
12+
#include <sync.h>
13+
#include <txmempool.h>
14+
#include <uint256.h>
1015
#include <util/check.h>
1116

1217
#include <algorithm>
@@ -72,7 +77,12 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
7277
// Add every entry to m_entries_by_txid and m_entries, except the ones that will be replaced.
7378
for (const auto& txiter : cluster) {
7479
if (!m_to_be_replaced.count(txiter->GetTx().GetHash())) {
75-
auto [mapiter, success] = m_entries_by_txid.emplace(txiter->GetTx().GetHash(), MiniMinerMempoolEntry(txiter));
80+
auto [mapiter, success] = m_entries_by_txid.emplace(txiter->GetTx().GetHash(),
81+
MiniMinerMempoolEntry{/*fee_self=*/txiter->GetModifiedFee(),
82+
/*fee_ancestor=*/txiter->GetModFeesWithAncestors(),
83+
/*vsize_self=*/txiter->GetTxSize(),
84+
/*vsize_ancestor=*/txiter->GetSizeWithAncestors(),
85+
/*tx_in=*/txiter->GetSharedTx()});
7686
m_entries.push_back(mapiter);
7787
} else {
7888
auto outpoints_it = m_requested_outpoints_by_txid.find(txiter->GetTx().GetHash());

src/node/mini_miner.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,45 @@
55
#ifndef BITCOIN_NODE_MINI_MINER_H
66
#define BITCOIN_NODE_MINI_MINER_H
77

8-
#include <txmempool.h>
8+
#include <consensus/amount.h>
9+
#include <primitives/transaction.h>
10+
#include <uint256.h>
911

12+
#include <map>
1013
#include <memory>
1114
#include <optional>
15+
#include <set>
1216
#include <stdint.h>
17+
#include <vector>
18+
19+
class CFeeRate;
20+
class CTxMemPool;
1321

1422
namespace node {
1523

1624
// Container for tracking updates to ancestor feerate as we include ancestors in the "block"
1725
class MiniMinerMempoolEntry
1826
{
19-
const CAmount fee_individual;
2027
const CTransactionRef tx;
2128
const int64_t vsize_individual;
22-
CAmount fee_with_ancestors;
2329
int64_t vsize_with_ancestors;
30+
const CAmount fee_individual;
31+
CAmount fee_with_ancestors;
2432

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

2836
public:
29-
explicit MiniMinerMempoolEntry(CTxMemPool::txiter entry) :
30-
fee_individual{entry->GetModifiedFee()},
31-
tx{entry->GetSharedTx()},
32-
vsize_individual(entry->GetTxSize()),
33-
fee_with_ancestors{entry->GetModFeesWithAncestors()},
34-
vsize_with_ancestors(entry->GetSizeWithAncestors())
37+
explicit MiniMinerMempoolEntry(CAmount fee_self,
38+
CAmount fee_ancestor,
39+
int64_t vsize_self,
40+
int64_t vsize_ancestor,
41+
const CTransactionRef& tx_in):
42+
tx{tx_in},
43+
vsize_individual{vsize_self},
44+
vsize_with_ancestors{vsize_ancestor},
45+
fee_individual{fee_self},
46+
fee_with_ancestors{fee_ancestor}
3547
{ }
3648

3749
CAmount GetModifiedFee() const { return fee_individual; }

0 commit comments

Comments
 (0)