Skip to content

Commit e2b5192

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23211: refactor: move update_* structs from txmempool.h to .cpp file
65aaf94 refactor: move `update_*` structs from txmempool.h to .cpp file (Sebastian Falbesoner) 9947ce6 refactor: use const reference for parents in `CTxMemPool::UpdateAncestorsOf` (Sebastian Falbesoner) Pull request description: These helpers are exclusively used in txmempool.cpp, hence they should also be moved there. The PR also contains a commit which fixes const-correctness for parents in `CTxMemPool::UpdateAncestorsOf` and declares them as reference to avoid a copy. ACKs for top commit: promag: Code review ACK 65aaf94. Verified move-only commit locally. Tree-SHA512: 7ce29f3ba0e68b5355001f27725b00f6d54cc993015356eb40b61b8cdd17db49b980f4c3d798c8e0c940d245dc3a72c474bb9ff3c0ee971ead450786076812c2
2 parents 3c4729a + 65aaf94 commit e2b5192

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

src/txmempool.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,58 @@
2222
#include <cmath>
2323
#include <optional>
2424

25+
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
26+
struct update_descendant_state
27+
{
28+
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
29+
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
30+
{}
31+
32+
void operator() (CTxMemPoolEntry &e)
33+
{ e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
34+
35+
private:
36+
int64_t modifySize;
37+
CAmount modifyFee;
38+
int64_t modifyCount;
39+
};
40+
41+
struct update_ancestor_state
42+
{
43+
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
44+
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
45+
{}
46+
47+
void operator() (CTxMemPoolEntry &e)
48+
{ e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
49+
50+
private:
51+
int64_t modifySize;
52+
CAmount modifyFee;
53+
int64_t modifyCount;
54+
int64_t modifySigOpsCost;
55+
};
56+
57+
struct update_fee_delta
58+
{
59+
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
60+
61+
void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
62+
63+
private:
64+
int64_t feeDelta;
65+
};
66+
67+
struct update_lock_points
68+
{
69+
explicit update_lock_points(const LockPoints& _lp) : lp(_lp) { }
70+
71+
void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
72+
73+
private:
74+
const LockPoints& lp;
75+
};
76+
2577
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
2678
int64_t time, unsigned int entry_height,
2779
bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
@@ -277,7 +329,7 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry,
277329

278330
void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors)
279331
{
280-
CTxMemPoolEntry::Parents parents = it->GetMemPoolParents();
332+
const CTxMemPoolEntry::Parents& parents = it->GetMemPoolParentsConst();
281333
// add or remove this tx as a child of each parent
282334
for (const CTxMemPoolEntry& parent : parents) {
283335
UpdateChild(mapTx.iterator_to(parent), it, add);

src/txmempool.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -159,58 +159,6 @@ class CTxMemPoolEntry
159159
mutable Epoch::Marker m_epoch_marker; //!< epoch when last touched, useful for graph algorithms
160160
};
161161

162-
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
163-
struct update_descendant_state
164-
{
165-
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
166-
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
167-
{}
168-
169-
void operator() (CTxMemPoolEntry &e)
170-
{ e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
171-
172-
private:
173-
int64_t modifySize;
174-
CAmount modifyFee;
175-
int64_t modifyCount;
176-
};
177-
178-
struct update_ancestor_state
179-
{
180-
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
181-
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
182-
{}
183-
184-
void operator() (CTxMemPoolEntry &e)
185-
{ e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
186-
187-
private:
188-
int64_t modifySize;
189-
CAmount modifyFee;
190-
int64_t modifyCount;
191-
int64_t modifySigOpsCost;
192-
};
193-
194-
struct update_fee_delta
195-
{
196-
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
197-
198-
void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
199-
200-
private:
201-
int64_t feeDelta;
202-
};
203-
204-
struct update_lock_points
205-
{
206-
explicit update_lock_points(const LockPoints& _lp) : lp(_lp) { }
207-
208-
void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
209-
210-
private:
211-
const LockPoints& lp;
212-
};
213-
214162
// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
215163
struct mempoolentry_txid
216164
{

0 commit comments

Comments
 (0)