Skip to content

Commit 00922b8

Browse files
committed
Merge #15906: [wallet] Move min_depth and max_depth to coin control
80ba424 extract min & max depth onto coin control (Amiti Uttarwar) Pull request description: - Refactor `AvailableCoins` to pull min & max depths from coin control. - Add `m_max_depth` to coin control to support this. - Addresses issue bitcoin/bitcoin#15823, see thread for further details. ACKs for top commit: laanwj: ACK 80ba424 Tree-SHA512: 8f7c0aa90b3bc3667baf6741b1da2829f3919e1df92ae097d86c6b239f0c024eb410d7100e6251ea8fc49d022fb5a1214bf79b0f8b0014945b7784b2311647d1
2 parents 8241b51 + 80ba424 commit 00922b8

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/wallet/coincontrol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ void CCoinControl::SetNull()
2020
m_confirm_target.reset();
2121
m_signal_bip125_rbf.reset();
2222
m_fee_mode = FeeEstimateMode::UNSET;
23+
m_min_depth = DEFAULT_MIN_DEPTH;
24+
m_max_depth = DEFAULT_MAX_DEPTH;
2325
}
2426

src/wallet/coincontrol.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include <boost/optional.hpp>
1414

15+
const int DEFAULT_MIN_DEPTH = 0;
16+
const int DEFAULT_MAX_DEPTH = 9999999;
17+
1518
/** Coin Control Features. */
1619
class CCoinControl
1720
{
@@ -39,7 +42,9 @@ class CCoinControl
3942
//! Fee estimation mode to control arguments to estimateSmartFee
4043
FeeEstimateMode m_fee_mode;
4144
//! Minimum chain depth value for coin availability
42-
int m_min_depth{0};
45+
int m_min_depth = DEFAULT_MIN_DEPTH;
46+
//! Maximum chain depth value for coin availability
47+
int m_max_depth = DEFAULT_MAX_DEPTH;
4348

4449
CCoinControl()
4550
{

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2879,9 +2879,11 @@ static UniValue listunspent(const JSONRPCRequest& request)
28792879
{
28802880
CCoinControl cctl;
28812881
cctl.m_avoid_address_reuse = false;
2882+
cctl.m_min_depth = nMinDepth;
2883+
cctl.m_max_depth = nMaxDepth;
28822884
auto locked_chain = pwallet->chain().lock();
28832885
LOCK(pwallet->cs_wallet);
2884-
pwallet->AvailableCoins(*locked_chain, vecOutputs, !include_unsafe, &cctl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
2886+
pwallet->AvailableCoins(*locked_chain, vecOutputs, !include_unsafe, &cctl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
28852887
}
28862888

28872889
LOCK(pwallet->cs_wallet);

src/wallet/wallet.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
24482448
return balance;
24492449
}
24502450

2451-
void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput> &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const
2451+
void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput>& vCoins, bool fOnlySafe, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount) const
24522452
{
24532453
AssertLockHeld(cs_wallet);
24542454

@@ -2457,6 +2457,8 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
24572457
// Either the WALLET_FLAG_AVOID_REUSE flag is not set (in which case we always allow), or we default to avoiding, and only in the case where
24582458
// a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses
24592459
bool allow_used_addresses = !IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || (coinControl && !coinControl->m_avoid_address_reuse);
2460+
const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH};
2461+
const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH};
24602462

24612463
for (const auto& entry : mapWallet)
24622464
{
@@ -2516,8 +2518,9 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
25162518
continue;
25172519
}
25182520

2519-
if (nDepth < nMinDepth || nDepth > nMaxDepth)
2521+
if (nDepth < min_depth || nDepth > max_depth) {
25202522
continue;
2523+
}
25212524

25222525
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
25232526
if (wtx.tx->vout[i].nValue < nMinimumAmount || wtx.tx->vout[i].nValue > nMaximumAmount)
@@ -2959,7 +2962,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
29592962
LOCK(cs_wallet);
29602963
{
29612964
std::vector<COutput> vAvailableCoins;
2962-
AvailableCoins(*locked_chain, vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0, coin_control.m_min_depth);
2965+
AvailableCoins(*locked_chain, vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);
29632966
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
29642967

29652968
// Create change script that will be used if we need change

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ class CWallet final : public FillableSigningProvider, private interfaces::Chain:
951951
/**
952952
* populate vCoins with vector of available COutputs.
953953
*/
954-
void AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
954+
void AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput>& vCoins, bool fOnlySafe = true, const CCoinControl* coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
955955

956956
/**
957957
* Return list of available coins and locked coins grouped by non-change output address.

0 commit comments

Comments
 (0)