Skip to content

Commit

Permalink
Merge bitcoin#28808: refactor: Miniminer package linearization followups
Browse files Browse the repository at this point in the history
b4b01d3 [refactor] updating miniminer comments to be more accurate (kevkevin)
83933ef [refactor] Miniminer var cached_descendants to descendants (kevkevin)
43423fd [refactor] Change MiniMinerMempoolEntry order (kevkevin)

Pull request description:

  ### Motivation
  In bitcoin#28762 there were some post merge comments which are being addressed in this PR with the following commits

  ### [8d4c46f](8d4c46f) Reorganizing `MiniMinerMempoolEntry` to match the order we have elsewhere
  * bitcoin#28762 (comment)

  ### [7505ec2](7505ec2) Renaming `cached_descendants` to `descendants` for simpler variable naming
  * bitcoin#28762 (comment)

  ### [b21f2f2](b21f2f2) Code comment modifications to be more accurate to what is actually happening
  * bitcoin#28762 (comment) and
  * bitcoin#28762 (comment) and
  * bitcoin#28762 (comment)

ACKs for top commit:
  murchandamus:
    reACK b4b01d3
  theStack:
    LGTM ACK b4b01d3

Tree-SHA512: 54f044a578fb203d8a3c1aa0bcd1fc4bcdff0bc9b024351925a4caf0ccece7c7736b0694ad1168c3cbb447bdb58a91f4cac365f46114da29a889fbc8ea595b82
  • Loading branch information
glozow committed Nov 9, 2023
2 parents 3d7544b + b4b01d3 commit d60ebea
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
12 changes: 6 additions & 6 deletions src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
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{/*fee_self=*/txiter->GetModifiedFee(),
/*fee_ancestor=*/txiter->GetModFeesWithAncestors(),
MiniMinerMempoolEntry{/*tx_in=*/txiter->GetSharedTx(),
/*vsize_self=*/txiter->GetTxSize(),
/*vsize_ancestor=*/txiter->GetSizeWithAncestors(),
/*tx_in=*/txiter->GetSharedTx()});
/*fee_self=*/txiter->GetModifiedFee(),
/*fee_ancestor=*/txiter->GetModFeesWithAncestors()});
m_entries.push_back(mapiter);
} else {
auto outpoints_it = m_requested_outpoints_by_txid.find(txiter->GetTx().GetHash());
Expand Down Expand Up @@ -154,18 +154,18 @@ MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
m_ready_to_calculate = false;
return;
}
std::vector<MockEntryMap::iterator> cached_descendants;
std::vector<MockEntryMap::iterator> descendants;
for (const auto& desc_txid : desc_txids) {
auto desc_it{m_entries_by_txid.find(desc_txid)};
// Descendants should only include transactions with corresponding entries.
if (!Assume(desc_it != m_entries_by_txid.end())) {
m_ready_to_calculate = false;
return;
} else {
cached_descendants.emplace_back(desc_it);
descendants.emplace_back(desc_it);
}
}
m_descendant_set_by_txid.emplace(txid, cached_descendants);
m_descendant_set_by_txid.emplace(txid, descendants);
}
Assume(m_to_be_replaced.empty());
Assume(m_requested_outpoints_by_txid.empty());
Expand Down
14 changes: 7 additions & 7 deletions src/node/mini_miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class MiniMinerMempoolEntry
// methods can be called without holding that lock.

public:
explicit MiniMinerMempoolEntry(CAmount fee_self,
CAmount fee_ancestor,
explicit MiniMinerMempoolEntry(const CTransactionRef& tx_in,
int64_t vsize_self,
int64_t vsize_ancestor,
const CTransactionRef& tx_in):
CAmount fee_self,
CAmount fee_ancestor):
tx{tx_in},
vsize_individual{vsize_self},
vsize_with_ancestors{vsize_ancestor},
Expand Down Expand Up @@ -137,10 +137,10 @@ class MiniMiner
*/
MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& outpoints);

/** Constructor in which the MiniMinerMempoolEntry entries have been constructed manually,
* presumably because these transactions are not in the mempool (yet). It is assumed that all
* entries are unique and their values are correct, otherwise results computed by MiniMiner may
* be incorrect. Callers should check IsReadyToCalculate() after construction.
/** Constructor in which the MiniMinerMempoolEntry entries have been constructed manually.
* It is assumed that all entries are unique and their values are correct, otherwise results
* computed by MiniMiner may be incorrect. Callers should check IsReadyToCalculate() after
* construction.
* @param[in] descendant_caches A map from each transaction to the set of txids of this
* transaction's descendant set, including itself. Each tx in
* manual_entries must have a corresponding entry in this map, and
Expand Down
51 changes: 25 additions & 26 deletions src/test/miniminer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ BOOST_FIXTURE_TEST_CASE(miniminer_1p1c, TestChain100Setup)
const int32_t tx6_vsize{tx_dims.at(tx6->GetHash()).vsize};
const int32_t tx7_vsize{tx_dims.at(tx7->GetHash()).vsize};

miniminer_info.emplace_back(/*fee_self=*/med_fee,/*fee_ancestor=*/med_fee,/*vsize_self=*/tx0_vsize,/*vsize_ancestor=*/tx0_vsize, tx0);
miniminer_info.emplace_back( med_fee, 2*med_fee, tx1_vsize, tx0_vsize + tx1_vsize, tx1);
miniminer_info.emplace_back( low_fee, low_fee, tx2_vsize, tx2_vsize, tx2);
miniminer_info.emplace_back( high_fee, low_fee + high_fee, tx3_vsize, tx2_vsize + tx3_vsize, tx3);
miniminer_info.emplace_back( low_fee, low_fee, tx4_vsize, tx4_vsize, tx4);
miniminer_info.emplace_back( tx5_mod_fee, low_fee + tx5_mod_fee, tx5_vsize, tx4_vsize + tx5_vsize, tx5);
miniminer_info.emplace_back( high_fee, high_fee, tx6_vsize, tx6_vsize, tx6);
miniminer_info.emplace_back( low_fee, high_fee + low_fee, tx7_vsize, tx6_vsize + tx7_vsize, tx7);
miniminer_info.emplace_back(tx0,/*vsize_self=*/tx0_vsize,/*vsize_ancestor=*/tx0_vsize,/*fee_self=*/med_fee,/*fee_ancestor=*/med_fee);
miniminer_info.emplace_back(tx1, tx1_vsize, tx0_vsize + tx1_vsize, med_fee, 2*med_fee);
miniminer_info.emplace_back(tx2, tx2_vsize, tx2_vsize, low_fee, low_fee);
miniminer_info.emplace_back(tx3, tx3_vsize, tx2_vsize + tx3_vsize, high_fee, low_fee + high_fee);
miniminer_info.emplace_back(tx4, tx4_vsize, tx4_vsize, low_fee, low_fee);
miniminer_info.emplace_back(tx5, tx5_vsize, tx4_vsize + tx5_vsize, tx5_mod_fee, low_fee + tx5_mod_fee);
miniminer_info.emplace_back(tx6, tx6_vsize, tx6_vsize, high_fee, high_fee);
miniminer_info.emplace_back(tx7, tx7_vsize, tx6_vsize + tx7_vsize, low_fee, high_fee + low_fee);
}
std::map<Txid, std::set<Txid>> descendant_caches;
descendant_caches.emplace(tx0->GetHash(), std::set<Txid>{tx0->GetHash(), tx1->GetHash()});
Expand Down Expand Up @@ -543,15 +543,14 @@ BOOST_FIXTURE_TEST_CASE(miniminer_overlap, TestChain100Setup)
}
// Check linearization order
std::vector<node::MiniMinerMempoolEntry> miniminer_info;
miniminer_info.emplace_back(/*fee_self=*/low_fee, /*fee_ancestor=*/low_fee,/*vsize_self=*/tx_vsizes[0], /*vsize_ancestor=*/tx_vsizes[0], tx0);
miniminer_info.emplace_back( med_fee, med_fee, tx_vsizes[1], tx_vsizes[1], tx1);
miniminer_info.emplace_back( high_fee, high_fee, tx_vsizes[2], tx_vsizes[2], tx2);
miniminer_info.emplace_back( high_fee, low_fee+med_fee+2*high_fee, tx_vsizes[3], tx_vsizes[0]+tx_vsizes[1]+tx_vsizes[2]+tx_vsizes[3], tx3);

miniminer_info.emplace_back( high_fee, high_fee, tx_vsizes[4], tx_vsizes[4], tx4);
miniminer_info.emplace_back( low_fee, low_fee + high_fee, tx_vsizes[5], tx_vsizes[4]+tx_vsizes[5], tx5);
miniminer_info.emplace_back( med_fee, high_fee+low_fee+med_fee, tx_vsizes[6], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[6], tx6);
miniminer_info.emplace_back( high_fee, high_fee+low_fee+high_fee, tx_vsizes[7], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[7], tx7);
miniminer_info.emplace_back(tx0,/*vsize_self=*/tx_vsizes[0], /*vsize_ancestor=*/tx_vsizes[0], /*fee_self=*/low_fee, /*fee_ancestor=*/low_fee);
miniminer_info.emplace_back(tx1, tx_vsizes[1], tx_vsizes[1], med_fee, med_fee);
miniminer_info.emplace_back(tx2, tx_vsizes[2], tx_vsizes[2], high_fee, high_fee);
miniminer_info.emplace_back(tx3, tx_vsizes[3], tx_vsizes[0]+tx_vsizes[1]+tx_vsizes[2]+tx_vsizes[3], high_fee, low_fee+med_fee+2*high_fee);
miniminer_info.emplace_back(tx4, tx_vsizes[4], tx_vsizes[4], high_fee, high_fee);
miniminer_info.emplace_back(tx5, tx_vsizes[5], tx_vsizes[4]+tx_vsizes[5], low_fee, low_fee + high_fee);
miniminer_info.emplace_back(tx6, tx_vsizes[6], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[6], med_fee, high_fee+low_fee+med_fee);
miniminer_info.emplace_back(tx7, tx_vsizes[7], tx_vsizes[4]+tx_vsizes[5]+tx_vsizes[7], high_fee, high_fee+low_fee+high_fee);

std::map<Txid, std::set<Txid>> descendant_caches;
descendant_caches.emplace(tx0->GetHash(), std::set<Txid>{tx0->GetHash(), tx3->GetHash()});
Expand Down Expand Up @@ -647,7 +646,7 @@ BOOST_FIXTURE_TEST_CASE(manual_ctor, TestChain100Setup)
CTxMemPool& pool = *Assert(m_node.mempool);
LOCK2(cs_main, pool.cs);
{
// 3 pairs of fee-bumping grandparent + parent, plus 1 low-feerate child.
// 3 pairs of grandparent + fee-bumping parent, plus 1 low-feerate child.
// 0 fee + high fee
auto grandparent_zero_fee = make_tx({{m_coinbase_txns.at(0)->GetHash(), 0}}, 1);
auto parent_high_feerate = make_tx({{grandparent_zero_fee->GetHash(), 0}}, 1);
Expand All @@ -665,13 +664,13 @@ BOOST_FIXTURE_TEST_CASE(manual_ctor, TestChain100Setup)
const int64_t child_vsize{1000};

std::vector<node::MiniMinerMempoolEntry> miniminer_info;
miniminer_info.emplace_back(/*fee_self=*/0, /*fee_ancestor=*/0,/*vsize_self=*/tx_vsize,/*vsize_ancestor=*/tx_vsize, grandparent_zero_fee);
miniminer_info.emplace_back( high_fee, high_fee, tx_vsize, 2*tx_vsize, parent_high_feerate);
miniminer_info.emplace_back( 2*low_fee, 2*low_fee, tx_vsize, tx_vsize, grandparent_double_low_feerate);
miniminer_info.emplace_back( med_fee, 2*low_fee+med_fee, tx_vsize, 2*tx_vsize, parent_med_feerate);
miniminer_info.emplace_back( low_fee, low_fee, tx_vsize, tx_vsize, grandparent_low_feerate);
miniminer_info.emplace_back( 2*low_fee, 3*low_fee, tx_vsize, 2*tx_vsize, parent_double_low_feerate);
miniminer_info.emplace_back( low_fee, high_fee+med_fee+6*low_fee, child_vsize, 6*tx_vsize+child_vsize, child);
miniminer_info.emplace_back(grandparent_zero_fee, /*vsize_self=*/tx_vsize,/*vsize_ancestor=*/tx_vsize, /*fee_self=*/0,/*fee_ancestor=*/0);
miniminer_info.emplace_back(parent_high_feerate, tx_vsize, 2*tx_vsize, high_fee, high_fee);
miniminer_info.emplace_back(grandparent_double_low_feerate, tx_vsize, tx_vsize, 2*low_fee, 2*low_fee);
miniminer_info.emplace_back(parent_med_feerate, tx_vsize, 2*tx_vsize, med_fee, 2*low_fee+med_fee);
miniminer_info.emplace_back(grandparent_low_feerate, tx_vsize, tx_vsize, low_fee, low_fee);
miniminer_info.emplace_back(parent_double_low_feerate, tx_vsize, 2*tx_vsize, 2*low_fee, 3*low_fee);
miniminer_info.emplace_back(child, child_vsize, 6*tx_vsize+child_vsize, low_fee, high_fee+med_fee+6*low_fee);
std::map<Txid, std::set<Txid>> descendant_caches;
descendant_caches.emplace(grandparent_zero_fee->GetHash(), std::set<Txid>{grandparent_zero_fee->GetHash(), parent_high_feerate->GetHash(), child->GetHash()});
descendant_caches.emplace(grandparent_low_feerate->GetHash(), std::set<Txid>{grandparent_low_feerate->GetHash(), parent_double_low_feerate->GetHash(), child->GetHash()});
Expand All @@ -693,7 +692,7 @@ BOOST_FIXTURE_TEST_CASE(manual_ctor, TestChain100Setup)
BOOST_CHECK_EQUAL(sequences.at(grandparent_double_low_feerate->GetHash()), 1);
BOOST_CHECK_EQUAL(sequences.at(parent_med_feerate->GetHash()), 1);

// CPFP low + med
// CPFP low + double low
BOOST_CHECK_EQUAL(sequences.at(grandparent_low_feerate->GetHash()), 2);
BOOST_CHECK_EQUAL(sequences.at(parent_double_low_feerate->GetHash()), 2);

Expand Down

0 comments on commit d60ebea

Please sign in to comment.