@@ -144,17 +144,24 @@ inline std::vector<OutputGroup>& GroupCoins(const std::vector<COutput>& coins)
144144    return  static_groups;
145145}
146146
147- inline  std::optional<SelectionResult> KnapsackSolver (std::vector<OutputGroup>& groups, const  CAmount& nTargetValue)
147+ inline  std::optional<SelectionResult> KnapsackSolver (std::vector<OutputGroup>& groups, const  CAmount& nTargetValue, FastRandomContext& rng )
148148{
149-     return  KnapsackSolver (groups, nTargetValue, /* fFullyMixedOnly=*/ false , /* maxTxFee=*/  DEFAULT_TRANSACTION_MAXFEE);
149+     return  KnapsackSolver (groups, nTargetValue, rng,  /* fFullyMixedOnly=*/ false , /* maxTxFee=*/  DEFAULT_TRANSACTION_MAXFEE);
150150}
151151
152152inline  std::vector<OutputGroup>& KnapsackGroupOutputs (const  std::vector<COutput>& coins, CWallet& wallet, const  CoinEligibilityFilter& filter)
153153{
154-     CoinSelectionParams coin_selection_params (/*  change_output_size= */   0 ,
155-                                               /*  change_spend_size= */   0 , /*  effective_feerate= */   CFeeRate (0 ),
156-                                               /*  long_term_feerate= */   CFeeRate (0 ), /*  discard_feerate= */   CFeeRate (0 ),
157-                                               /*  tx_noinputs_size= */   0 , /*  avoid_partial= */   false );
154+     FastRandomContext rand{};
155+     CoinSelectionParams coin_selection_params{
156+         rand,
157+         /*  change_output_size= */   0 ,
158+         /*  change_spend_size= */   0 ,
159+         /*  effective_feerate= */   CFeeRate (0 ),
160+         /*  long_term_feerate= */   CFeeRate (0 ),
161+         /*  discard_feerate= */   CFeeRate (0 ),
162+         /*  tx_noinputs_size= */   0 ,
163+         /*  avoid_partial= */   false ,
164+     };
158165    static  std::vector<OutputGroup> static_groups;
159166    static_groups = GroupOutputs (wallet, coins, coin_selection_params, filter, /* positive_only=*/ false );
160167    return  static_groups;
@@ -163,6 +170,7 @@ inline std::vector<OutputGroup>& KnapsackGroupOutputs(const std::vector<COutput>
163170//  Branch and bound coin selection tests
164171BOOST_AUTO_TEST_CASE (bnb_search_test)
165172{
173+     FastRandomContext rand{};
166174    //  Setup
167175    std::vector<COutput> utxo_pool;
168176    SelectionResult expected_result (CAmount (0 ));
@@ -288,10 +296,16 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
288296    }
289297
290298    //  Make sure that effective value is working in AttemptSelection when BnB is used
291-     CoinSelectionParams coin_selection_params_bnb (/*  change_output_size= */   0 ,
292-                                                   /*  change_spend_size= */   0 , /*  effective_feerate= */   CFeeRate (3000 ),
293-                                                   /*  long_term_feerate= */   CFeeRate (1000 ), /*  discard_feerate= */   CFeeRate (1000 ),
294-                                                   /*  tx_noinputs_size= */   0 , /*  avoid_partial= */   false );
299+     CoinSelectionParams coin_selection_params_bnb{
300+         rand,
301+         /*  change_output_size= */   0 ,
302+         /*  change_spend_size= */   0 ,
303+         /*  effective_feerate= */   CFeeRate (3000 ),
304+         /*  long_term_feerate= */   CFeeRate (1000 ),
305+         /*  discard_feerate= */   CFeeRate (1000 ),
306+         /*  tx_noinputs_size= */   0 ,
307+         /*  avoid_partial= */   false ,
308+     };
295309    {
296310        std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain .get (), /* coinjoin_loader=*/ nullptr , " "  , m_args, CreateMockWalletDatabase ());
297311        wallet->LoadWallet ();
@@ -338,6 +352,9 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
338352
339353BOOST_AUTO_TEST_CASE (knapsack_solver_test)
340354{
355+     FastRandomContext rand{};
356+     const  auto  temp1{[&rand](std::vector<OutputGroup>& g, const  CAmount& v) { return  KnapsackSolver (g, v, rand); }};
357+     const  auto  KnapsackSolver{temp1};
341358    std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain .get (), /* coinjoin_loader=*/ nullptr , " "  , m_args, CreateMockWalletDatabase ());
342359    wallet->LoadWallet ();
343360    LOCK (wallet->cs_wallet );
@@ -647,6 +664,7 @@ BOOST_AUTO_TEST_CASE(knapsack_solver_test)
647664
648665BOOST_AUTO_TEST_CASE (ApproximateBestSubset)
649666{
667+     FastRandomContext rand{};
650668    std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain .get (), /* coinjoin_loader=*/ nullptr , " "  , m_args, CreateMockWalletDatabase ());
651669    wallet->LoadWallet ();
652670    LOCK (wallet->cs_wallet );
@@ -660,7 +678,7 @@ BOOST_AUTO_TEST_CASE(ApproximateBestSubset)
660678        add_coin (coins, *wallet, 1000  * COIN);
661679    add_coin (coins, *wallet, 3  * COIN);
662680
663-     const  auto  result = KnapsackSolver (KnapsackGroupOutputs (coins, *wallet, filter_standard), 1003  * COIN);
681+     const  auto  result = KnapsackSolver (KnapsackGroupOutputs (coins, *wallet, filter_standard), 1003  * COIN, rand );
664682    BOOST_CHECK (result);
665683    BOOST_CHECK_EQUAL (result->GetSelectedValue (), 1003  * COIN);
666684    BOOST_CHECK_EQUAL (result->GetInputSet ().size (), 2U );
@@ -701,10 +719,16 @@ BOOST_AUTO_TEST_CASE(SelectCoins_test)
701719        CAmount target = rand.randrange (balance - 1000 ) + 1000 ;
702720
703721        //  Perform selection
704-         CoinSelectionParams cs_params (/*  change_output_size= */   34 ,
705-                                       /*  change_spend_size= */   148 , /*  effective_feerate= */   CFeeRate (0 ),
706-                                       /*  long_term_feerate= */   CFeeRate (0 ), /*  discard_feerate= */   CFeeRate (0 ),
707-                                       /*  tx_noinputs_size= */   0 , /*  avoid_partial= */   false );
722+         CoinSelectionParams cs_params{
723+             rand,
724+             /*  change_output_size= */   34 ,
725+             /*  change_spend_size= */   148 ,
726+             /*  effective_feerate= */   CFeeRate (0 ),
727+             /*  long_term_feerate= */   CFeeRate (0 ),
728+             /*  discard_feerate= */   CFeeRate (0 ),
729+             /*  tx_noinputs_size= */   0 ,
730+             /*  avoid_partial= */   false ,
731+         };
708732        CCoinControl cc;
709733        const  auto  result = SelectCoins (*wallet, coins, target, cc, cs_params);
710734        BOOST_CHECK (result);
0 commit comments