Skip to content

Commit 9f0f83d

Browse files
committed
Merge bitcoin#29065: bench: wallet, fix change position out of range error
37c75c5 test: wallet, fix change position out of range error (furszy) Pull request description: Fixes bitcoin#29061. Only the benchmark is affected. Since bitcoin#25273, the behavior of 'inserting change at a random position' is instructed by passing ´std::nullopt´ instead of -1. Also, added missing documentation about the meaning of 'change_pos=std::nullopt' inside 'CWallet::CreateTransaction()' ACKs for top commit: achow101: ACK 37c75c5 kevkevinpal: ACK [37c75c5](bitcoin@37c75c5) BrandonOdiwuor: ACK 37c75c5 Tree-SHA512: d9a8d8533540455716a5090fcf407573cad9f0d0018a05f903f89e51620302f9b256318db6f7338b85c047f7fab372d724e916b1721d7ed302dbf3d845b08734
2 parents 019ec8a + 37c75c5 commit 9f0f83d

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

src/bench/wallet_create_tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
129129

130130
bench.epochIterations(5).run([&] {
131131
LOCK(wallet.cs_wallet);
132-
const auto& tx_res = CreateTransaction(wallet, recipients, -1, coin_control);
132+
const auto& tx_res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
133133
assert(tx_res);
134134
});
135135
}

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
316316
// We cannot source new unconfirmed inputs(bip125 rule 2)
317317
new_coin_control.m_min_depth = 1;
318318

319-
auto res = CreateTransaction(wallet, recipients, std::nullopt, new_coin_control, false);
319+
auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false);
320320
if (!res) {
321321
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
322322
return Result::WALLET_ERROR;

src/wallet/rpc/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vecto
155155
std::shuffle(recipients.begin(), recipients.end(), FastRandomContext());
156156

157157
// Send
158-
auto res = CreateTransaction(wallet, recipients, std::nullopt, coin_control, true);
158+
auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control, true);
159159
if (!res) {
160160
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, util::ErrorString(res).original);
161161
}

src/wallet/spend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct CreatedTransactionResult
216216
/**
217217
* Create a new transaction paying the recipients with a set of coins
218218
* selected by SelectCoins(); Also create the change output, when needed
219-
* @note passing change_pos as -1 will result in setting a random position
219+
* @note passing change_pos as std::nullopt will result in setting a random position
220220
*/
221221
util::Result<CreatedTransactionResult> CreateTransaction(CWallet& wallet, const std::vector<CRecipient>& vecSend, std::optional<unsigned int> change_pos, const CCoinControl& coin_control, bool sign = true);
222222

src/wallet/test/spend_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
3333
coin_control.fOverrideFeeRate = true;
3434
// We need to use a change type with high cost of change so that the leftover amount will be dropped to fee instead of added as a change output
3535
coin_control.m_change_type = OutputType::LEGACY;
36-
auto res = CreateTransaction(*wallet, {recipient}, std::nullopt, coin_control);
36+
auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, coin_control);
3737
BOOST_CHECK(res);
3838
const auto& txr = *res;
3939
BOOST_CHECK_EQUAL(txr.tx->vout.size(), 1);
@@ -97,12 +97,12 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
9797
// so that the recipient's amount is no longer equal to the user's selected target of 299 BTC.
9898

9999
// First case, use 'subtract_fee_from_outputs=true'
100-
util::Result<CreatedTransactionResult> res_tx = CreateTransaction(*wallet, recipients, /*change_pos*/-1, coin_control);
100+
util::Result<CreatedTransactionResult> res_tx = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
101101
BOOST_CHECK(!res_tx.has_value());
102102

103103
// Second case, don't use 'subtract_fee_from_outputs'.
104104
recipients[0].fSubtractFeeFromAmount = false;
105-
res_tx = CreateTransaction(*wallet, recipients, /*change_pos*/-1, coin_control);
105+
res_tx = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
106106
BOOST_CHECK(!res_tx.has_value());
107107
}
108108

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
558558
CTransactionRef tx;
559559
CCoinControl dummy;
560560
{
561-
auto res = CreateTransaction(*wallet, {recipient}, std::nullopt, dummy);
561+
auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, dummy);
562562
BOOST_CHECK(res);
563563
tx = res->tx;
564564
}

0 commit comments

Comments
 (0)