Skip to content

Commit 6e4d789

Browse files
committed
wallet: add back missing CoinSelectionParams assignments
They were removed as part of dash#3668 and omitted in related backports but as bitcoin#17331 will be a logical partial revert of the former, we need to add them back in preparation for it.
1 parent bd35042 commit 6e4d789

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/wallet/spend.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,18 @@ bool CWallet::CreateTransactionInternal(
686686
// change keypool ran out, but change is required.
687687
CHECK_NONFATAL(IsValidDestination(dest) != scriptChange.empty());
688688
}
689+
CTxOut change_prototype_txout(0, scriptChange);
690+
coin_selection_params.change_output_size = GetSerializeSize(change_prototype_txout);
691+
692+
// Get size of spending the change output
693+
int change_spend_size = CalculateMaximumSignedInputSize(change_prototype_txout, this);
694+
// If the wallet doesn't know how to sign change output, assume p2sh-p2pkh
695+
// as lower-bound to allow BnB to do it's thing
696+
if (change_spend_size == -1) {
697+
coin_selection_params.change_spend_size = DUMMY_NESTED_P2PKH_INPUT_SIZE;
698+
} else {
699+
coin_selection_params.change_spend_size = (size_t)change_spend_size;
700+
}
689701

690702
// Set discard feerate
691703
coin_selection_params.m_discard_feerate = coin_control.m_discard_feerate ? *coin_control.m_discard_feerate : GetDiscardRate(*this);
@@ -704,12 +716,18 @@ bool CWallet::CreateTransactionInternal(
704716
return false;
705717
}
706718

719+
// Get long term estimate
720+
CCoinControl cc_temp;
721+
cc_temp.m_confirm_target = chain().estimateMaxBlocks();
722+
coin_selection_params.m_long_term_feerate = GetMinimumFeeRate(*this, cc_temp, nullptr);
723+
707724
nFeeRet = 0;
708725
bool pick_new_inputs = true;
709726
CAmount nValueIn = 0;
710727

711728
// BnB selector is the only selector used when this is true.
712729
coin_selection_params.use_bnb = false; // Dash: never use BnB
730+
coin_selection_params.m_subtract_fee_outputs = nSubtractFeeFromAmount != 0; // If we are doing subtract fee from recipient, don't use effective values
713731

714732
CAmount nAmountToSelectAdditional{0};
715733
// Start with nAmountToSelectAdditional=0 and loop until there is enough to cover the request + fees, try it 500 times.
@@ -726,7 +744,11 @@ bool CWallet::CreateTransactionInternal(
726744
assert(nAmountToSelectAdditional >= 0);
727745
nValueToSelect += nAmountToSelectAdditional;
728746
}
747+
729748
// vouts to the payees
749+
if (!coin_selection_params.m_subtract_fee_outputs) {
750+
coin_selection_params.tx_noinputs_size = 10; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 output count
751+
}
730752
for (const auto& recipient : vecSend)
731753
{
732754
CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
@@ -743,6 +765,11 @@ bool CWallet::CreateTransactionInternal(
743765
}
744766
}
745767

768+
// Include the fee cost for outputs. Note this is only used for BnB right now
769+
if (!coin_selection_params.m_subtract_fee_outputs) {
770+
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
771+
}
772+
746773
if (IsDust(txout, chain().relayDustFee()))
747774
{
748775
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)

src/wallet/test/wallet_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,6 @@ static size_t CalculateNestedKeyhashInputSize(bool use_max_sig)
13531353
return ::GetSerializeSize(tx_in, PROTOCOL_VERSION);
13541354
}
13551355

1356-
static constexpr size_t DUMMY_NESTED_P2PKH_INPUT_SIZE = 113;
13571356
BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup)
13581357
{
13591358
BOOST_CHECK_EQUAL(CalculateNestedKeyhashInputSize(false), DUMMY_NESTED_P2PKH_INPUT_SIZE);

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ static const CAmount DEFAULT_TRANSACTION_MAXFEE = COIN / 10;
104104
static const CAmount HIGH_TX_FEE_PER_KB = COIN / 100;
105105
//! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
106106
static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;
107+
//! Pre-calculated constants for input size estimation in *virtual size*
108+
static constexpr size_t DUMMY_NESTED_P2PKH_INPUT_SIZE = 113;
107109

108110
//! if set, all keys will be derived by using BIP39/BIP44
109111
static const bool DEFAULT_USE_HD_WALLET = true;

0 commit comments

Comments
 (0)