coin selection: BnB, don't return selection if exceeds max allowed tx weight

This commit is contained in:
furszy
2022-12-18 20:16:19 -03:00
parent d3a1c098e4
commit 2d112584e3
6 changed files with 23 additions and 7 deletions

View File

@@ -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)