21#include <boost/test/unit_test.hpp>
32#define RANDOM_REPEATS 5
47 group.Insert(std::make_shared<COutput>(output), 0, 0);
59 group.Insert(coin, 0, 0);
60 coin->long_term_fee = long_term_fee;
79 const auto& txout = wtx.
tx->vout.at(
nInput);
80 available_coins.Add(
OutputType::BECH32, {
COutPoint(wtx.
GetHash(),
nInput), txout,
nAge,
custom_size == 0 ?
CalculateMaximumSignedInputSize(txout, &
wallet,
nullptr) :
custom_size,
true,
true, wtx.
GetTxTime(),
fIsFromMe, feerate});
88 return res ? std::optional<SelectionResult>(*
res) : std::nullopt;
94 return res ? std::optional<SelectionResult>(*
res) : std::nullopt;
101 std::vector<CAmount>
a_amts;
102 std::vector<CAmount>
b_amts;
103 for (
const auto& coin :
a.GetInputSet()) {
104 a_amts.push_back(coin->txout.nValue);
107 b_amts.push_back(coin->txout.nValue);
112 std::pair<std::vector<CAmount>::iterator, std::vector<CAmount>::iterator>
ret = std::mismatch(
a_amts.begin(),
a_amts.end(),
b_amts.begin());
119 std::pair<OutputSet::iterator, OutputSet::iterator>
ret = std::mismatch(
a.GetInputSet().begin(),
a.GetInputSet().end(), b.
GetInputSet().begin(),
120 [](
const std::shared_ptr<COutput>&
a,
const std::shared_ptr<COutput>& b) {
121 return a->outpoint == b->outpoint;
133 group.Insert(std::make_shared<COutput>(coin), 0, 0);
160 std::unique_ptr<CWallet>
wallet = std::make_unique<CWallet>(
m_node.
chain.get(), wallet_name, CreateMockableWalletDatabase());
162 wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
163 wallet->SetupDescriptorScriptPubKeyMans();
250 expected_result.Clear();
288 expected_result.Clear();
315 params.m_subtract_fee_outputs =
true;
316 params.m_change_fee = params.m_effective_feerate.
GetFee(params.change_output_size);
317 params.m_cost_of_change = params.m_discard_feerate.GetFee(params.change_spend_size) + params.m_change_fee;
318 params.m_min_change_target = params.m_cost_of_change + 1;
506 for (
int j = 0;
j < 20;
j++)
587 for (
int i2 = 0;
i2 < 100;
i2++)
650 for (
int i = 0; i < 1000; i++)
668 std::exponential_distribution<double>
distribution (100);
672 for (
int i = 0; i < 100; ++i)
678 for (
int j = 0;
j < 1000; ++
j)
715 const CAmount min_viable_change{300};
847 const CAmount min_viable_change{200};
857 const std::vector<std::shared_ptr<COutput>> inputs =
selection.GetShuffledInputVector();
859 for (
size_t i = 0; i < inputs.size(); ++i) {
860 inputs[i]->ApplyBumpFee(20*(i+1));
883 const std::vector<std::shared_ptr<COutput>> inputs =
selection.GetShuffledInputVector();
885 for (
size_t i = 0; i < inputs.size(); ++i) {
886 inputs[i]->ApplyBumpFee(20*(i+1));
902 const int input_bytes = 148;
979 for (
int j = 0;
j < 10; ++
j) {
997 for (
int j = 0;
j < 10; ++
j) {
1015 for (
int j = 0;
j < 60; ++
j) {
1018 for (
int i = 0; i < 10; i++) {
1024 for (
int i = 0; i < 10; ++i) {
1027 for (
int j = 0;
j < 17; ++
j) {
1066 for (
int j = 0;
j < 5; ++
j) {
1101 for (
int j = 0;
j < 100; ++
j) {
1104 for (
int j = 0;
j < 100; ++
j) {
1107 for (
int j = 0;
j < 100; ++
j) {
1110 for (
int j = 0;
j < 100; ++
j) {
1137 for (
int j = 0;
j < 100; ++
j) {
1161 for (
int i = 0; i < 18; ++i) {
1168 for (
int i = 0; i < 8; ++i) {
1179 for (
int i = 0; i < 19; ++i) {
1228 for (
int j = 0;
j < 10; ++
j) {
1246 for (
int j = 0;
j < 10; ++
j) {
1265 for (
int j = 0;
j < 60; ++
j) {
1268 for (
int i = 0; i < 10; i++) {
1286 const auto signedTxSize = 10 + 34 + 68 * result->GetInputSet().size();
1296 return std::any_of(set.begin(), set.end(), [&](
const auto& coin) { return coin->GetEffectiveValue() == amount; });
1329 for (
int j = 0;
j < 1515; ++
j) {
1355 for (
int j = 0;
j < 400; ++
j) {
1358 for (
int j = 0;
j < 2000; ++
j) {
1380 for (
int j = 0;
j < 1515; ++
j) {
1444 for (
int i=0; i<10; i++) {
1452 std::unordered_set<COutPoint, SaltedOutpointHasher>
outs_to_remove;
1454 for (
int i = 0; i < 2; i++) {
1463 return coin.outpoint == out;
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
BOOST_CHECK_LT(ZeroL, OneL)
#define Assert(val)
Identity function.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
An outpoint - a combination of a transaction hash and an index n into its vout.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
const Txid & GetHash() const LIFETIMEBOUND
int64_t GetTxTime() const
static const int WITNESS_SCALE_FACTOR
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
bilingual_str ErrorString(const Result< T > &result)
static const CoinEligibilityFilter filter_standard(1, 6, 0)
FilteredOutputGroups GroupOutputs(const CWallet &wallet, const CoinsResult &coins, const CoinSelectionParams &coin_sel_params, const std::vector< SelectionFilter > &filters, std::vector< OutputGroup > &ret_discarded_groups)
util::Result< CoinsResult > FetchSelectedInputs(const CWallet &wallet, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Fetch and validate coin control selected inputs.
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
util::Result< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_selection_weight)
static std::unique_ptr< CWallet > NewWallet(const node::NodeContext &m_node, const std::string &wallet_name="")
util::Result< SelectionResult > CoinGrinder(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, CAmount change_target, int max_selection_weight)
std::vector< OutputGroup > & GroupCoins(const std::vector< COutput > &available_coins, bool subtract_fee_outputs=false)
std::vector< OutputGroup > & KnapsackGroupOutputs(const CoinsResult &available_coins, CWallet &wallet, const CoinEligibilityFilter &filter)
util::Result< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue, CAmount change_target, FastRandomContext &rng, int max_selection_weight)
util::Result< SelectionResult > SelectCoins(const CWallet &wallet, CoinsResult &available_coins, const CoinsResult &pre_set_inputs, const CAmount &nTargetValue, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Select all coins from coin_control, and if coin_control 'm_allow_other_inputs=true',...
static bool has_coin(const OutputSet &set, CAmount amount)
static const CoinEligibilityFilter filter_standard_extra(6, 6, 0)
static bool EqualResult(const SelectionResult &a, const SelectionResult &b)
Check if this selection is equal to another one.
BOOST_AUTO_TEST_CASE(bnb_test)
std::set< std::shared_ptr< COutput >, OutputPtrComparator > OutputSet
static const CoinEligibilityFilter filter_confirmed(1, 1, 0)
int CalculateMaximumSignedInputSize(const CTxOut &txout, const COutPoint outpoint, const SigningProvider *provider, bool can_grind_r, const CCoinControl *coin_control)
static void add_coin(const CAmount &nValue, int nInput, SelectionResult &result)
static bool EquivalentResult(const SelectionResult &a, const SelectionResult &b)
Check if SelectionResult a is equivalent to SelectionResult b.
static void ApproximateBestSubset(FastRandomContext &insecure_rand, const std::vector< OutputGroup > &groups, const CAmount &nTotalLower, const CAmount &nTargetValue, std::vector< char > &vfBest, CAmount &nBest, int max_selection_weight, int iterations=1000)
Find a subset of the OutputGroups that is at least as large as, but as close as possible to,...
util::Result< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value, CAmount change_fee, FastRandomContext &rng, int max_selection_weight)
Select coins by Single Random Draw (SRD).
static util::Result< SelectionResult > select_coins(const CAmount &target, const CoinSelectionParams &cs_params, const CCoinControl &cc, std::function< CoinsResult(CWallet &)> coin_setup, const node::NodeContext &m_node)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
static constexpr CAmount CENT
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< interfaces::Chain > chain
A UTXO under consideration for use in funding a new transaction.
COutPoint outpoint
The outpoint identifying this UTXO.
CTxOut txout
The output itself.
Parameters for filtering which OutputGroups we may use in coin selection.
Parameters for one iteration of Coin Selection.
COutputs available for spending, stored by OutputType.
void Add(OutputType type, const COutput &out)
std::vector< OutputGroup > mixed_group
A group of UTXOs paid to the same output script.
Stores several 'Groups' whose were mapped by output type.
void AddInput(const OutputGroup &group)
const OutputSet & GetInputSet() const
Get m_selected_inputs.
State of transaction not confirmed or conflicting with a known block and not in the mempool.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
BOOST_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.