mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
wallet: coin selection, add duplicated inputs checks
As no process should be able to trigger this error using the regular transaction creation process, throw a runtime_error if happens to tell users/devs to report the bug if happens.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <random.h>
|
||||
#include <util/system.h>
|
||||
#include <util/check.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -302,6 +304,17 @@ private:
|
||||
/** Total weight of the selected inputs */
|
||||
int m_weight{0};
|
||||
|
||||
template<typename T>
|
||||
void InsertInputs(const T& inputs)
|
||||
{
|
||||
// Store sum of combined input sets to check that the results have no shared UTXOs
|
||||
const size_t expected_count = m_selected_inputs.size() + inputs.size();
|
||||
util::insert(m_selected_inputs, inputs);
|
||||
if (m_selected_inputs.size() != expected_count) {
|
||||
throw std::runtime_error(STR_INTERNAL_BUG("Shared UTXOs among selection results"));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SelectionResult(const CAmount target, SelectionAlgorithm algo)
|
||||
: m_target(target), m_algo(algo) {}
|
||||
|
||||
Reference in New Issue
Block a user