From b9ef21dd727dde33f5bd3c33226b05d07eb12aac Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Mon, 21 May 2018 11:15:12 +0900 Subject: [PATCH] mempool: Add explicit max_descendants TransactionWithinChainLimits would take a 'limit' and check it against ascendants and descendants. This is changed to take an explicit max ancestors and max descendants value, and to test the corresponding value against its corresponding max. --- src/txmempool.cpp | 6 +++--- src/txmempool.h | 2 +- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index bb585fc0758..d3f5c1bd2a1 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1055,11 +1055,11 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector* pvNoSpends } } -bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const { +bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const { LOCK(cs); auto it = mapTx.find(txid); - return it == mapTx.end() || (it->GetCountWithAncestors() < chainLimit && - it->GetCountWithDescendants() < chainLimit); + return it == mapTx.end() || (it->GetCountWithAncestors() < ancestor_limit && + it->GetCountWithDescendants() < descendant_limit); } SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits::max())), k1(GetRand(std::numeric_limits::max())) {} diff --git a/src/txmempool.h b/src/txmempool.h index ca7b1cd4be3..f6792b09686 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -620,7 +620,7 @@ public: int Expire(int64_t time); /** Returns false if the transaction is in the mempool and not within the chain limit specified. */ - bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const; + bool TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const; unsigned long size() { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c3597aace83..306f6281968 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2469,7 +2469,7 @@ bool CWallet::OutputEligibleForSpending(const COutput& output, const CoinEligibi if (output.nDepth < (output.tx->IsFromMe(ISMINE_ALL) ? eligibility_filter.conf_mine : eligibility_filter.conf_theirs)) return false; - if (!mempool.TransactionWithinChainLimit(output.tx->GetHash(), eligibility_filter.max_ancestors)) + if (!mempool.TransactionWithinChainLimit(output.tx->GetHash(), eligibility_filter.max_ancestors, eligibility_filter.max_descendants)) return false; return true; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f1761b0fcff..1ec2a9e7716 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -662,8 +662,10 @@ struct CoinEligibilityFilter const int conf_mine; const int conf_theirs; const uint64_t max_ancestors; + const uint64_t max_descendants; - CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors) : conf_mine(conf_mine), conf_theirs(conf_theirs), max_ancestors(max_ancestors) {} + CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors) : conf_mine(conf_mine), conf_theirs(conf_theirs), max_ancestors(max_ancestors), max_descendants(max_ancestors) {} + CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors, uint64_t max_descendants) : conf_mine(conf_mine), conf_theirs(conf_theirs), max_ancestors(max_ancestors), max_descendants(max_descendants) {} }; class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime