@@ -150,33 +150,15 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
150
150
UpdateForDescendants (it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
151
151
}
152
152
}
153
-
154
- bool CTxMemPool::CalculateMemPoolAncestors (const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents /* = true */ ) const
153
+ bool CTxMemPool::CalculateAncestorsAndCheckLimits (const CTxMemPoolEntry& entry,
154
+ setEntries& setAncestors,
155
+ CTxMemPoolEntry::Parents &staged_ancestors,
156
+ uint64_t limitAncestorCount,
157
+ uint64_t limitAncestorSize,
158
+ uint64_t limitDescendantCount,
159
+ uint64_t limitDescendantSize,
160
+ std::string &errString) const
155
161
{
156
- CTxMemPoolEntry::Parents staged_ancestors;
157
- const CTransaction &tx = entry.GetTx ();
158
-
159
- if (fSearchForParents ) {
160
- // Get parents of this transaction that are in the mempool
161
- // GetMemPoolParents() is only valid for entries in the mempool, so we
162
- // iterate mapTx to find parents.
163
- for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
164
- std::optional<txiter> piter = GetIter (tx.vin [i].prevout .hash );
165
- if (piter) {
166
- staged_ancestors.insert (**piter);
167
- if (staged_ancestors.size () + 1 > limitAncestorCount) {
168
- errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount);
169
- return false ;
170
- }
171
- }
172
- }
173
- } else {
174
- // If we're not searching for parents, we require this to be an
175
- // entry in the mempool already.
176
- txiter it = mapTx.iterator_to (entry);
177
- staged_ancestors = it->GetMemPoolParentsConst ();
178
- }
179
-
180
162
size_t totalSizeWithAncestors = entry.GetTxSize ();
181
163
182
164
while (!staged_ancestors.empty ()) {
@@ -216,6 +198,44 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntr
216
198
return true ;
217
199
}
218
200
201
+ bool CTxMemPool::CalculateMemPoolAncestors (const CTxMemPoolEntry &entry,
202
+ setEntries &setAncestors,
203
+ uint64_t limitAncestorCount,
204
+ uint64_t limitAncestorSize,
205
+ uint64_t limitDescendantCount,
206
+ uint64_t limitDescendantSize,
207
+ std::string &errString,
208
+ bool fSearchForParents /* = true */ ) const
209
+ {
210
+ CTxMemPoolEntry::Parents staged_ancestors;
211
+ const CTransaction &tx = entry.GetTx ();
212
+
213
+ if (fSearchForParents ) {
214
+ // Get parents of this transaction that are in the mempool
215
+ // GetMemPoolParents() is only valid for entries in the mempool, so we
216
+ // iterate mapTx to find parents.
217
+ for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
218
+ std::optional<txiter> piter = GetIter (tx.vin [i].prevout .hash );
219
+ if (piter) {
220
+ staged_ancestors.insert (**piter);
221
+ if (staged_ancestors.size () + 1 > limitAncestorCount) {
222
+ errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount);
223
+ return false ;
224
+ }
225
+ }
226
+ }
227
+ } else {
228
+ // If we're not searching for parents, we require this to already be an
229
+ // entry in the mempool and use the entry's cached parents.
230
+ txiter it = mapTx.iterator_to (entry);
231
+ staged_ancestors = it->GetMemPoolParentsConst ();
232
+ }
233
+
234
+ return CalculateAncestorsAndCheckLimits (entry, setAncestors, staged_ancestors,
235
+ limitAncestorCount, limitAncestorSize,
236
+ limitDescendantCount, limitDescendantSize, errString);
237
+ }
238
+
219
239
void CTxMemPool::UpdateAncestorsOf (bool add, txiter it, setEntries &setAncestors)
220
240
{
221
241
CTxMemPoolEntry::Parents parents = it->GetMemPoolParents ();
0 commit comments