Skip to content

Commit

Permalink
Make MiniMinerMempoolEntry fields private
Browse files Browse the repository at this point in the history
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
  • Loading branch information
murchandamus committed Jun 12, 2023
1 parent d2fe456 commit 9daf105
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ void MiniMiner::DeleteAncestorPackage(const std::set<MockEntryMap::iterator, Ite
for (auto& descendant : it->second) {
// If these fail, we must be double-deducting.
Assume(descendant->second.GetModFeesWithAncestors() >= anc->second.GetModifiedFee());
Assume(descendant->second.vsize_with_ancestors >= anc->second.GetTxSize());
descendant->second.fee_with_ancestors -= anc->second.GetModifiedFee();
descendant->second.vsize_with_ancestors -= anc->second.GetTxSize();
Assume(descendant->second.GetSizeWithAncestors() >= anc->second.GetTxSize());
descendant->second.UpdateAncestorState(-anc->second.GetTxSize(), -anc->second.GetModifiedFee());
}
}
// Delete these entries.
Expand Down
9 changes: 7 additions & 2 deletions src/node/mini_miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class MiniMinerMempoolEntry
const CAmount fee_individual;
const CTransactionRef tx;
const int64_t vsize_individual;
CAmount fee_with_ancestors;
int64_t vsize_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:
CAmount fee_with_ancestors;
int64_t vsize_with_ancestors;
explicit MiniMinerMempoolEntry(CTxMemPool::txiter entry) :
fee_individual{entry->GetModifiedFee()},
tx{entry->GetSharedTx()},
Expand All @@ -38,6 +39,10 @@ class MiniMinerMempoolEntry
int64_t GetTxSize() const { return vsize_individual; }
int64_t GetSizeWithAncestors() const { return vsize_with_ancestors; }
const CTransaction& GetTx() const LIFETIMEBOUND { return *tx; }
void UpdateAncestorState(int64_t vsize_change, CAmount fee_change) {
vsize_with_ancestors += vsize_change;
fee_with_ancestors += fee_change;
}
};

// Comparator needed for std::set<MockEntryMap::iterator>
Expand Down

0 comments on commit 9daf105

Please sign in to comment.