18 static void AddCoin(
const CAmount& value,
int n_input,
int n_input_bytes,
int locktime, std::vector<COutput>& coins,
CFeeRate fee_rate)
21 tx.
vout.resize(n_input + 1);
22 tx.
vout[n_input].nValue = value;
24 coins.emplace_back(
COutPoint(tx.
GetHash(), n_input), tx.
vout.at(n_input), 0, n_input_bytes,
true,
true,
true, 0,
true, fee_rate);
31 bool valid_outputgroup{
false};
32 for (
auto& coin : coins) {
33 if (!positive_only || (positive_only && coin.GetEffectiveValue() > 0)) {
34 output_group.Insert(std::make_shared<COutput>(coin), 0, 0);
38 valid_outputgroup = !positive_only || output_group.GetSelectionAmount() > 0;
39 if (valid_outputgroup && fuzzed_data_provider.
ConsumeBool()) {
40 output_groups.push_back(output_group);
42 valid_outputgroup =
false;
45 if (valid_outputgroup) output_groups.push_back(output_group);
54 std::vector<COutput> utxo_pool;
60 const bool subtract_fee_outputs{fuzzed_data_provider.ConsumeBool()};
65 coin_params.m_long_term_feerate = long_term_fee_rate;
66 coin_params.m_effective_feerate = effective_fee_rate;
67 coin_params.change_output_size = fuzzed_data_provider.ConsumeIntegralInRange<
int>(10, 1000);
68 coin_params.m_change_fee = effective_fee_rate.GetFee(coin_params.change_output_size);
75 const int n_input{fuzzed_data_provider.ConsumeIntegralInRange<
int>(0, 10)};
76 const int n_input_bytes{fuzzed_data_provider.ConsumeIntegralInRange<
int>(100, 10000)};
78 if (total_balance + amount >=
MAX_MONEY) {
81 AddCoin(amount, n_input, n_input_bytes, ++next_locktime, utxo_pool, coin_params.m_effective_feerate);
82 total_balance += amount;
85 std::vector<OutputGroup> group_pos;
86 GroupCoins(fuzzed_data_provider, utxo_pool, coin_params,
true, group_pos);
87 std::vector<OutputGroup> group_all;
88 GroupCoins(fuzzed_data_provider, utxo_pool, coin_params,
false, group_all);
94 if (result_srd) result_srd->ComputeAndSetWaste(cost_of_change, cost_of_change, 0);
98 if (result_knapsack) result_knapsack->ComputeAndSetWaste(cost_of_change, cost_of_change, 0);
102 if (total_balance >= target && subtract_fee_outputs && !
HasErrorMsg(result_knapsack)) {
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
An outpoint - a combination of a transaction hash and an index n into its vout.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
bilingual_str ErrorString(const Result< T > &result)
util::Result< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_weight)
static void AddCoin(const CAmount &value, int n_input, int n_input_bytes, int locktime, std::vector< COutput > &coins, CFeeRate fee_rate)
CAmount GenerateChangeTarget(const CAmount payment_value, const CAmount change_fee, FastRandomContext &rng)
Choose a random change target for each transaction to make it harder to fingerprint the Core wallet b...
std::vector< OutputGroup > & GroupCoins(const std::vector< COutput > &available_coins, bool subtract_fee_outputs=false)
util::Result< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue, CAmount change_target, FastRandomContext &rng, int max_weight)
util::Result< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value, FastRandomContext &rng, int max_weight)
Select coins by Single Random Draw.
FUZZ_TARGET(coinselection)
static bool HasErrorMsg(const util::Result< SelectionResult > &res)
static constexpr unsigned int MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
Parameters for one iteration of Coin Selection.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
A group of UTXOs paid to the same output script.
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept