mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
wallet: Check max tx weight in coin selector
Co-authored-by: Andrew Chow <github@achow101.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user