@@ -57,57 +57,44 @@ size_t CTxMemPoolEntry::GetTxSize() const
57
57
// Update the given tx for any in-mempool descendants.
58
58
// Assumes that setMemPoolChildren is correct for the given tx and all
59
59
// descendants.
60
- void CTxMemPool::UpdateForDescendants (txiter update_it, cacheMap& cache, const std::set<uint256>& exclude)
60
+ void CTxMemPool::UpdateForDescendants (txiter update_it, const std::set<uint256>& exclude)
61
61
{
62
62
const auto epoch = GetFreshEpoch ();
63
63
const CTxMemPool::setEntries& direct_children = GetMemPoolChildren (update_it);
64
- // set up the update_cache to contain all of our transaction's children (note --
64
+ // set up the stage to contain all of our transaction's children (note --
65
65
// already de-duplicated in case multiple outputs of ours are spent in one
66
66
// transaction)
67
- vecEntries update_cache ;
68
- update_cache .reserve (direct_children.size ());
67
+ vecEntries stage ;
68
+ stage .reserve (direct_children.size ());
69
69
// mark every direct_child as visited so that we don't accidentally re-add them
70
70
// to the cache in the grandchild is child case
71
71
for (const txiter direct_child : direct_children) {
72
- update_cache .emplace_back (direct_child);
72
+ stage .emplace_back (direct_child);
73
73
visited (direct_child);
74
74
}
75
75
// already_traversed index keeps track of the elements that we've
76
76
// already expanded. If index is < already_traversed, we've walked it.
77
77
// If index is >= already_traversed, we need to walk it.
78
- // If already_traversed >= update_cache .size(), we're finished.
79
- for (size_t already_traversed = 0 ; already_traversed < update_cache .size (); /* modified in loop body */ ) {
78
+ // If already_traversed >= stage .size(), we're finished.
79
+ for (size_t already_traversed = 0 ; already_traversed < stage .size (); /* modified in loop body */ ) {
80
80
// rotate the back() to behind already_traversed
81
- const txiter child_it = update_cache .back ();
82
- std::swap (update_cache [already_traversed++], update_cache .back ());
81
+ const txiter child_it = stage .back ();
82
+ std::swap (stage [already_traversed++], stage .back ());
83
83
84
84
// N.B. grand_children may also be children
85
85
const CTxMemPool::setEntries& grand_children = GetMemPoolChildren (child_it);
86
86
for (const txiter grand_child_it : grand_children) {
87
87
if (visited (grand_child_it)) continue ;
88
- cacheMap::iterator cached_great_grand_children = cache.find (grand_child_it);
89
- if (cached_great_grand_children != cache.end ()) {
90
- for (const txiter great_grand_child : cached_great_grand_children->second ) {
91
- if (visited (great_grand_child)) continue ;
92
- update_cache.emplace_back (great_grand_child);
93
- // place on the back and then swap into the already_traversed index
94
- // so we don't walk it ourselves (whoever put the grand
95
- // child in the cache must have already traversed this)
96
- std::swap (update_cache[already_traversed++], update_cache.back ());
97
- }
98
- } else {
99
- // Schedule for later processing
100
- update_cache.emplace_back (grand_child_it);
101
- }
88
+ stage.emplace_back (grand_child_it);
102
89
}
103
90
}
104
91
105
- // update_cache now contains all in-mempool descendants of update_it,
92
+ // stage now contains all in-mempool descendants of update_it,
106
93
// compute updates now.
107
94
int64_t modify_size = 0 ;
108
95
CAmount modify_fee = 0 ;
109
96
int64_t modify_count = 0 ;
110
- for (txiter child_it : update_cache ) {
97
+ for (txiter child_it : stage ) {
111
98
const CTxMemPoolEntry& child = *child_it;
112
99
if (!exclude.count (child.GetTx ().GetHash ())) {
113
100
modify_size += child.GetTxSize ();
@@ -117,8 +104,6 @@ void CTxMemPool::UpdateForDescendants(txiter update_it, cacheMap& cache, const s
117
104
}
118
105
}
119
106
mapTx.modify (update_it, update_descendant_state (modify_size, modify_fee, modify_count));
120
- // share the cache (if there is one)
121
- if (!update_cache.empty ()) cache.emplace (update_it, std::move (update_cache));
122
107
}
123
108
// vHashesToUpdate is the set of transaction hashes from a disconnected block
124
109
// which has been re-added to the mempool.
@@ -128,20 +113,15 @@ void CTxMemPool::UpdateForDescendants(txiter update_it, cacheMap& cache, const s
128
113
void CTxMemPool::UpdateTransactionsFromBlock (const std::vector<uint256> &vHashesToUpdate)
129
114
{
130
115
AssertLockHeld (cs);
131
- // For each entry in vHashesToUpdate, store the set of in-mempool, but not
132
- // in-vHashesToUpdate transactions, so that we don't have to recalculate
133
- // descendants when we come across a previously seen entry.
134
- cacheMap mapMemPoolDescendantsToUpdate;
135
116
136
117
// Use a set for lookups into vHashesToUpdate (these entries are already
137
118
// accounted for in the state of their ancestors)
138
119
std::set<uint256> setAlreadyIncluded (vHashesToUpdate.begin (), vHashesToUpdate.end ());
139
120
140
121
// Iterate in reverse, so that whenever we are looking at a transaction
141
122
// we are sure that all in-mempool descendants have already been processed.
142
- // This maximizes the benefit of the descendant cache and guarantees that
143
- // setMemPoolChildren will be updated, an assumption made in
144
- // UpdateForDescendants.
123
+ // This guarantees that setMemPoolChildren will be up to date, an assumption
124
+ // made in UpdateForDescendants.
145
125
for (const uint256 &hash : reverse_iterate (vHashesToUpdate)) {
146
126
// calculate children from mapNextTx
147
127
txiter it = mapTx.find (hash);
@@ -166,7 +146,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
166
146
}
167
147
}
168
148
} // release epoch guard for UpdateForDescendants
169
- UpdateForDescendants (it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
149
+ UpdateForDescendants (it, setAlreadyIncluded);
170
150
}
171
151
}
172
152
0 commit comments