wallet: Check max tx weight in coin selector

Co-authored-by: Andrew Chow <github@achow101.com>
This commit is contained in:
Aurèle Oulès
2022-10-04 14:17:11 +02:00
parent 7734a0160d
commit 6b563cae92
4 changed files with 41 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
#include <wallet/coinselection.h>
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <policy/feerate.h>
#include <util/check.h>
#include <util/system.h>
@@ -354,6 +355,10 @@ void OutputGroup::Insert(const COutput& output, size_t ancestors, size_t descend
// descendants is the count as seen from the top ancestor, not the descendants as seen from the
// coin itself; thus, this value is counted as the max, not the sum
m_descendants = std::max(m_descendants, descendants);
if (output.input_bytes > 0) {
m_weight += output.input_bytes * WITNESS_SCALE_FACTOR;
}
}
bool OutputGroup::EligibleForSpending(const CoinEligibilityFilter& eligibility_filter) const
@@ -436,18 +441,25 @@ void SelectionResult::Clear()
{
m_selected_inputs.clear();
m_waste.reset();
m_weight = 0;
}
void SelectionResult::AddInput(const OutputGroup& group)
{
util::insert(m_selected_inputs, group.m_outputs);
m_use_effective = !group.m_subtract_fee_outputs;
m_weight += group.m_weight;
}
void SelectionResult::AddInputs(const std::set<COutput>& inputs, bool subtract_fee_outputs)
{
util::insert(m_selected_inputs, inputs);
m_use_effective = !subtract_fee_outputs;
m_weight += std::accumulate(inputs.cbegin(), inputs.cend(), 0, [](int sum, const auto& coin) {
return sum + std::max(coin.input_bytes, 0) * WITNESS_SCALE_FACTOR;
});
}
void SelectionResult::Merge(const SelectionResult& other)
@@ -462,6 +474,8 @@ void SelectionResult::Merge(const SelectionResult& other)
}
util::insert(m_selected_inputs, other.m_selected_inputs);
assert(m_selected_inputs.size() == expected_count);
m_weight += other.m_weight;
}
const std::set<COutput>& SelectionResult::GetInputSet() const