aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2023-12-13 12:38:11 -0500
committerAva Chow <github@achow101.com>2023-12-13 12:45:30 -0500
commit9f0f83d6509a214b827f5110c0f857b494ae854c (patch)
treea123dcbc3de342e3beff789008db7f0f18b4ec93 /src/wallet
parent019ec8a601c91e89a16e55d79ec60cfa29254094 (diff)
parent37c75c58202f89b752500f76c872d7f8caf6bdb3 (diff)
downloadbitcoin-9f0f83d6509a214b827f5110c0f857b494ae854c.tar.xz
Merge bitcoin/bitcoin#29065: bench: wallet, fix change position out of range error
37c75c58202f89b752500f76c872d7f8caf6bdb3 test: wallet, fix change position out of range error (furszy) Pull request description: Fixes #29061. Only the benchmark is affected. Since #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 37c75c58202f89b752500f76c872d7f8caf6bdb3 kevkevinpal: ACK [37c75c5](https://github.com/bitcoin/bitcoin/pull/29065/commits/37c75c58202f89b752500f76c872d7f8caf6bdb3) BrandonOdiwuor: ACK 37c75c58202f89b752500f76c872d7f8caf6bdb3 Tree-SHA512: d9a8d8533540455716a5090fcf407573cad9f0d0018a05f903f89e51620302f9b256318db6f7338b85c047f7fab372d724e916b1721d7ed302dbf3d845b08734
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/feebumper.cpp2
-rw-r--r--src/wallet/rpc/spend.cpp2
-rw-r--r--src/wallet/spend.h2
-rw-r--r--src/wallet/test/spend_tests.cpp6
-rw-r--r--src/wallet/test/wallet_tests.cpp2
5 files changed, 7 insertions, 7 deletions
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index c6ed0fe11c..6a8453965b 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -316,7 +316,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
// We cannot source new unconfirmed inputs(bip125 rule 2)
new_coin_control.m_min_depth = 1;
- auto res = CreateTransaction(wallet, recipients, std::nullopt, new_coin_control, false);
+ auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false);
if (!res) {
errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
return Result::WALLET_ERROR;
diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp
index b121c8e1a7..5a13b5ac8e 100644
--- a/src/wallet/rpc/spend.cpp
+++ b/src/wallet/rpc/spend.cpp
@@ -155,7 +155,7 @@ UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vecto
std::shuffle(recipients.begin(), recipients.end(), FastRandomContext());
// Send
- auto res = CreateTransaction(wallet, recipients, std::nullopt, coin_control, true);
+ auto res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control, true);
if (!res) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, util::ErrorString(res).original);
}
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index 504c078b80..3bd37cfd0e 100644
--- a/src/wallet/spend.h
+++ b/src/wallet/spend.h
@@ -216,7 +216,7 @@ struct CreatedTransactionResult
/**
* Create a new transaction paying the recipients with a set of coins
* selected by SelectCoins(); Also create the change output, when needed
- * @note passing change_pos as -1 will result in setting a random position
+ * @note passing change_pos as std::nullopt will result in setting a random position
*/
util::Result<CreatedTransactionResult> CreateTransaction(CWallet& wallet, const std::vector<CRecipient>& vecSend, std::optional<unsigned int> change_pos, const CCoinControl& coin_control, bool sign = true);
diff --git a/src/wallet/test/spend_tests.cpp b/src/wallet/test/spend_tests.cpp
index b2d252b3f9..3509bc116f 100644
--- a/src/wallet/test/spend_tests.cpp
+++ b/src/wallet/test/spend_tests.cpp
@@ -33,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
coin_control.fOverrideFeeRate = true;
// 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
coin_control.m_change_type = OutputType::LEGACY;
- auto res = CreateTransaction(*wallet, {recipient}, std::nullopt, coin_control);
+ auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, coin_control);
BOOST_CHECK(res);
const auto& txr = *res;
BOOST_CHECK_EQUAL(txr.tx->vout.size(), 1);
@@ -97,12 +97,12 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
// so that the recipient's amount is no longer equal to the user's selected target of 299 BTC.
// First case, use 'subtract_fee_from_outputs=true'
- util::Result<CreatedTransactionResult> res_tx = CreateTransaction(*wallet, recipients, /*change_pos*/-1, coin_control);
+ util::Result<CreatedTransactionResult> res_tx = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
BOOST_CHECK(!res_tx.has_value());
// Second case, don't use 'subtract_fee_from_outputs'.
recipients[0].fSubtractFeeFromAmount = false;
- res_tx = CreateTransaction(*wallet, recipients, /*change_pos*/-1, coin_control);
+ res_tx = CreateTransaction(*wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
BOOST_CHECK(!res_tx.has_value());
}
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 3d1cbe36a8..1c5ca1483f 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -558,7 +558,7 @@ public:
CTransactionRef tx;
CCoinControl dummy;
{
- auto res = CreateTransaction(*wallet, {recipient}, std::nullopt, dummy);
+ auto res = CreateTransaction(*wallet, {recipient}, /*change_pos=*/std::nullopt, dummy);
BOOST_CHECK(res);
tx = res->tx;
}