aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coinselection.cpp
diff options
context:
space:
mode:
authorAurèle Oulès <aurele@oules.com>2022-10-04 14:17:11 +0200
committerAurèle Oulès <aurele@oules.com>2022-12-05 19:32:11 +0100
commit6b563cae92957dc30dc35103a7c321fdb0115ef3 (patch)
treec5c1b2cffe292a60c9be010733758c1a93851b1e /src/wallet/coinselection.cpp
parent7734a0160debfeea039b77cca1366cd9ee83feb6 (diff)
downloadbitcoin-6b563cae92957dc30dc35103a7c321fdb0115ef3.tar.xz
wallet: Check max tx weight in coin selector
Co-authored-by: Andrew Chow <github@achow101.com>
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r--src/wallet/coinselection.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index b889d31928..ba1d60fe44 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -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