@@ -187,10 +187,7 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(size_t entry_size,
187
187
size_t entry_count,
188
188
setEntries& setAncestors,
189
189
CTxMemPoolEntry::Parents& staged_ancestors,
190
- uint64_t limitAncestorCount,
191
- uint64_t limitAncestorSize,
192
- uint64_t limitDescendantCount,
193
- uint64_t limitDescendantSize,
190
+ const Limits& limits,
194
191
std::string &errString) const
195
192
{
196
193
size_t totalSizeWithAncestors = entry_size;
@@ -203,14 +200,14 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(size_t entry_size,
203
200
staged_ancestors.erase (stage);
204
201
totalSizeWithAncestors += stageit->GetTxSize ();
205
202
206
- if (stageit->GetSizeWithDescendants () + entry_size > limitDescendantSize ) {
207
- errString = strprintf (" exceeds descendant size limit for tx %s [limit: %u]" , stageit->GetTx ().GetHash ().ToString (), limitDescendantSize );
203
+ if (stageit->GetSizeWithDescendants () + entry_size > static_cast < uint64_t >(limits. descendant_size_vbytes ) ) {
204
+ errString = strprintf (" exceeds descendant size limit for tx %s [limit: %u]" , stageit->GetTx ().GetHash ().ToString (), limits. descendant_size_vbytes );
208
205
return false ;
209
- } else if (stageit->GetCountWithDescendants () + entry_count > limitDescendantCount ) {
210
- errString = strprintf (" too many descendants for tx %s [limit: %u]" , stageit->GetTx ().GetHash ().ToString (), limitDescendantCount );
206
+ } else if (stageit->GetCountWithDescendants () + entry_count > static_cast < uint64_t >(limits. descendant_count ) ) {
207
+ errString = strprintf (" too many descendants for tx %s [limit: %u]" , stageit->GetTx ().GetHash ().ToString (), limits. descendant_count );
211
208
return false ;
212
- } else if (totalSizeWithAncestors > limitAncestorSize ) {
213
- errString = strprintf (" exceeds ancestor size limit [limit: %u]" , limitAncestorSize );
209
+ } else if (totalSizeWithAncestors > static_cast < uint64_t >(limits. ancestor_size_vbytes ) ) {
210
+ errString = strprintf (" exceeds ancestor size limit [limit: %u]" , limits. ancestor_size_vbytes );
214
211
return false ;
215
212
}
216
213
@@ -222,8 +219,8 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(size_t entry_size,
222
219
if (setAncestors.count (parent_it) == 0 ) {
223
220
staged_ancestors.insert (parent);
224
221
}
225
- if (staged_ancestors.size () + setAncestors.size () + entry_count > limitAncestorCount ) {
226
- errString = strprintf (" too many unconfirmed ancestors [limit: %u]" , limitAncestorCount );
222
+ if (staged_ancestors.size () + setAncestors.size () + entry_count > static_cast < uint64_t >(limits. ancestor_count ) ) {
223
+ errString = strprintf (" too many unconfirmed ancestors [limit: %u]" , limits. ancestor_count );
227
224
return false ;
228
225
}
229
226
}
@@ -233,10 +230,7 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(size_t entry_size,
233
230
}
234
231
235
232
bool CTxMemPool::CheckPackageLimits (const Package& package,
236
- uint64_t limitAncestorCount,
237
- uint64_t limitAncestorSize,
238
- uint64_t limitDescendantCount,
239
- uint64_t limitDescendantSize,
233
+ const Limits& limits,
240
234
std::string &errString) const
241
235
{
242
236
CTxMemPoolEntry::Parents staged_ancestors;
@@ -247,8 +241,8 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
247
241
std::optional<txiter> piter = GetIter (input.prevout .hash );
248
242
if (piter) {
249
243
staged_ancestors.insert (**piter);
250
- if (staged_ancestors.size () + package.size () > limitAncestorCount ) {
251
- errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount );
244
+ if (staged_ancestors.size () + package.size () > static_cast < uint64_t >(limits. ancestor_count ) ) {
245
+ errString = strprintf (" too many unconfirmed parents [limit: %u]" , limits. ancestor_count );
252
246
return false ;
253
247
}
254
248
}
@@ -260,19 +254,15 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
260
254
setEntries setAncestors;
261
255
const auto ret = CalculateAncestorsAndCheckLimits (total_size, package.size (),
262
256
setAncestors, staged_ancestors,
263
- limitAncestorCount, limitAncestorSize,
264
- limitDescendantCount, limitDescendantSize, errString);
257
+ limits, errString);
265
258
// It's possible to overestimate the ancestor/descendant totals.
266
259
if (!ret) errString.insert (0 , " possibly " );
267
260
return ret;
268
261
}
269
262
270
263
bool CTxMemPool::CalculateMemPoolAncestors (const CTxMemPoolEntry &entry,
271
264
setEntries &setAncestors,
272
- uint64_t limitAncestorCount,
273
- uint64_t limitAncestorSize,
274
- uint64_t limitDescendantCount,
275
- uint64_t limitDescendantSize,
265
+ const Limits& limits,
276
266
std::string &errString,
277
267
bool fSearchForParents /* = true */ ) const
278
268
{
@@ -287,8 +277,8 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry,
287
277
std::optional<txiter> piter = GetIter (tx.vin [i].prevout .hash );
288
278
if (piter) {
289
279
staged_ancestors.insert (**piter);
290
- if (staged_ancestors.size () + 1 > limitAncestorCount ) {
291
- errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount );
280
+ if (staged_ancestors.size () + 1 > static_cast < uint64_t >(limits. ancestor_count ) ) {
281
+ errString = strprintf (" too many unconfirmed parents [limit: %u]" , limits. ancestor_count );
292
282
return false ;
293
283
}
294
284
}
@@ -302,8 +292,7 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry,
302
292
303
293
return CalculateAncestorsAndCheckLimits (entry.GetTxSize (), /* entry_count=*/ 1 ,
304
294
setAncestors, staged_ancestors,
305
- limitAncestorCount, limitAncestorSize,
306
- limitDescendantCount, limitDescendantSize, errString);
295
+ limits, errString);
307
296
}
308
297
309
298
void CTxMemPool::UpdateAncestorsOf (bool add, txiter it, setEntries &setAncestors)
@@ -347,7 +336,6 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
347
336
{
348
337
// For each entry, walk back all ancestors and decrement size associated with this
349
338
// transaction
350
- const uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
351
339
if (updateDescendants) {
352
340
// updateDescendants should be true whenever we're not recursively
353
341
// removing a tx and all its descendants, eg when a transaction is
@@ -390,7 +378,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
390
378
// mempool parents we'd calculate by searching, and it's important that
391
379
// we use the cached notion of ancestor transactions as the set of
392
380
// things to update for removal.
393
- CalculateMemPoolAncestors (entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit , dummy, false );
381
+ CalculateMemPoolAncestors (entry, setAncestors, Limits::NoLimits () , dummy, false );
394
382
// Note that UpdateAncestorsOf severs the child links that point to
395
383
// removeIt in the entries for the parents of removeIt.
396
384
UpdateAncestorsOf (false , removeIt, setAncestors);
@@ -744,9 +732,8 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
744
732
assert (std::equal (setParentCheck.begin (), setParentCheck.end (), it->GetMemPoolParentsConst ().begin (), comp));
745
733
// Verify ancestor state is correct.
746
734
setEntries setAncestors;
747
- uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
748
735
std::string dummy;
749
- CalculateMemPoolAncestors (*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit , dummy);
736
+ CalculateMemPoolAncestors (*it, setAncestors, Limits::NoLimits () , dummy);
750
737
uint64_t nCountCheck = setAncestors.size () + 1 ;
751
738
uint64_t nSizeCheck = it->GetTxSize ();
752
739
CAmount nFeesCheck = it->GetModifiedFee ();
@@ -908,9 +895,8 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
908
895
mapTx.modify (it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee (nFeeDelta); });
909
896
// Now update all ancestors' modified fees with descendants
910
897
setEntries setAncestors;
911
- uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
912
898
std::string dummy;
913
- CalculateMemPoolAncestors (*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit , dummy, false );
899
+ CalculateMemPoolAncestors (*it, setAncestors, Limits::NoLimits () , dummy, false );
914
900
for (txiter ancestorIt : setAncestors) {
915
901
mapTx.modify (ancestorIt, [=](CTxMemPoolEntry& e){ e.UpdateDescendantState (0 , nFeeDelta, 0 );});
916
902
}
@@ -1049,9 +1035,8 @@ int CTxMemPool::Expire(std::chrono::seconds time)
1049
1035
void CTxMemPool::addUnchecked (const CTxMemPoolEntry &entry, bool validFeeEstimate)
1050
1036
{
1051
1037
setEntries setAncestors;
1052
- uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
1053
1038
std::string dummy;
1054
- CalculateMemPoolAncestors (entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit , dummy);
1039
+ CalculateMemPoolAncestors (entry, setAncestors, Limits::NoLimits () , dummy);
1055
1040
return addUnchecked (entry, setAncestors, validFeeEstimate);
1056
1041
}
1057
1042
0 commit comments