From eea462de9c652dca556ad241d2126b10790f67f8 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 14 Oct 2019 13:32:41 -0400 Subject: [PATCH 1/2] [wallet] Remove package limit config access from wallet The wallet should not be able to directly access global configuration from the node. Remove access of "-limitancestorcount" and "-limitdescendantcount". --- src/interfaces/chain.cpp | 5 +++++ src/interfaces/chain.h | 5 +++++ src/wallet/wallet.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index b8b9ecded9..b7cd65ff3a 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -298,6 +298,11 @@ public: { ::mempool.GetTransactionAncestry(txid, ancestors, descendants); } + void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override + { + limit_ancestor_count = gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); + limit_descendant_count = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); + } bool checkChainLimits(const CTransactionRef& tx) override { LockPoints lp; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index da670a3370..73a78e21fb 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -163,6 +163,11 @@ public: //! Calculate mempool ancestor and descendant counts for the given transaction. virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0; + //! Get the node's package limits. + //! Currently only returns the ancestor and descendant count limits, but could be enhanced to + //! return more policy settings. + virtual void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) = 0; + //! Check if transaction will pass the mempool's chain limits. virtual bool checkChainLimits(const CTransactionRef& tx) = 0; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 09f08220db..1551c645d0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -2739,8 +2738,11 @@ bool CWallet::SelectCoins(const std::vector& vAvailableCoins, const CAm } std::vector groups = GroupOutputs(vCoins, !coin_control.m_avoid_partial_spends); - size_t max_ancestors = (size_t)std::max(1, gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT)); - size_t max_descendants = (size_t)std::max(1, gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT)); + unsigned int limit_ancestor_count; + unsigned int limit_descendant_count; + chain().getPackageLimits(limit_ancestor_count, limit_descendant_count); + size_t max_ancestors = (size_t)std::max(1, limit_ancestor_count); + size_t max_descendants = (size_t)std::max(1, limit_descendant_count); bool fRejectLongChains = gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS); bool res = nTargetValue <= nValueFromPresetInputs || From b96ed0396294fc4fa89d83ceab6bc169dd09f002 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 14 Oct 2019 13:39:25 -0400 Subject: [PATCH 2/2] [wallet] Remove pruning check for -rescan option Prior to this PR, the wallet would not allow the `-rescan` option at startup if pruning was enabled. This is unnecessarily restrictive. It should be possible to rescan if pruning is enabled, as long as no blocks have actually been pruned yet. Remove the pruning check from WalletInit::ParameterInteraction(). If any blocks have been pruned, that will be caught in CreateWalletFromFile(). --- src/wallet/init.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 43b6ead028..b7f3f2e5fe 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -122,8 +122,6 @@ bool WalletInit::ParameterInteraction() const if (gArgs.GetBoolArg("-sysperms", false)) return InitError("-sysperms is not allowed in combination with enabled wallet functionality"); - if (gArgs.GetArg("-prune", 0) && gArgs.GetBoolArg("-rescan", false)) - return InitError(_("Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again.").translated); return true; }