aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/test
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-12-18 20:16:19 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2023-04-05 09:32:39 -0300
commit2d112584e384de10021c64e4700455d71326824e (patch)
treef12d9e4d23c041223b7df4fae9f91194184613fb /src/wallet/test
parentd3a1c098e4b5df2ebbae20c6e390c3d783950e93 (diff)
downloadbitcoin-2d112584e384de10021c64e4700455d71326824e.tar.xz
coin selection: BnB, don't return selection if exceeds max allowed tx weight
Diffstat (limited to 'src/wallet/test')
-rw-r--r--src/wallet/test/coinselector_tests.cpp8
-rw-r--r--src/wallet/test/fuzz/coinselection.cpp2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index 01ce6d76f4..f511a449ed 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -87,7 +87,7 @@ static void add_coin(CoinsResult& available_coins, CWallet& wallet, const CAmoun
available_coins.Add(OutputType::BECH32, {COutPoint(wtx.GetHash(), nInput), txout, nAge, CalculateMaximumSignedInputSize(txout, &wallet, /*coin_control=*/nullptr), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, feerate});
}
-// Helper
+// Helpers
std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue,
CAmount change_target, FastRandomContext& rng)
{
@@ -95,6 +95,12 @@ std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups,
return res ? std::optional<SelectionResult>(*res) : std::nullopt;
}
+std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const CAmount& cost_of_change)
+{
+ auto res{SelectCoinsBnB(utxo_pool, selection_target, cost_of_change, MAX_STANDARD_TX_WEIGHT)};
+ return res ? std::optional<SelectionResult>(*res) : std::nullopt;
+}
+
/** Check if SelectionResult a is equivalent to SelectionResult b.
* Equivalent means same input values, but maybe different inputs (i.e. same value, different prevout) */
static bool EquivalentResult(const SelectionResult& a, const SelectionResult& b)
diff --git a/src/wallet/test/fuzz/coinselection.cpp b/src/wallet/test/fuzz/coinselection.cpp
index a057eda393..9be8efab62 100644
--- a/src/wallet/test/fuzz/coinselection.cpp
+++ b/src/wallet/test/fuzz/coinselection.cpp
@@ -88,7 +88,7 @@ FUZZ_TARGET(coinselection)
GroupCoins(fuzzed_data_provider, utxo_pool, coin_params, /*positive_only=*/false, group_all);
// Run coinselection algorithms
- const auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change);
+ const auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);
auto result_srd = SelectCoinsSRD(group_pos, target, fast_random_context, MAX_STANDARD_TX_WEIGHT);
if (result_srd) result_srd->ComputeAndSetWaste(cost_of_change, cost_of_change, 0);