mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
wallet: Move long term feerate setting to CreateTransaction
Instead of setting the long term feerate for each SelectCoinsMinConf iteration, set it once during CreateTransaction and let it be shared with each SelectCoinsMinConf through coin_selection_params.m_long_term_feerate. Does not change behavior.
This commit is contained in:
parent
e2f429e6bb
commit
448d04b931
@ -49,7 +49,10 @@ static void CoinSelection(benchmark::Bench& bench)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CoinEligibilityFilter filter_standard(1, 6, 0);
|
const CoinEligibilityFilter filter_standard(1, 6, 0);
|
||||||
const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0, false);
|
const CoinSelectionParams coin_selection_params(/* use_bnb= */ true, /* change_output_size= */ 34,
|
||||||
|
/* change_spend_size= */ 148, /* effective_fee= */ CFeeRate(0),
|
||||||
|
/* long_term_feerate= */ CFeeRate(0),
|
||||||
|
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
|
||||||
bench.run([&] {
|
bench.run([&] {
|
||||||
std::set<CInputCoin> setCoinsRet;
|
std::set<CInputCoin> setCoinsRet;
|
||||||
CAmount nValueRet;
|
CAmount nValueRet;
|
||||||
|
@ -35,7 +35,10 @@ static CAmount balance = 0;
|
|||||||
CoinEligibilityFilter filter_standard(1, 6, 0);
|
CoinEligibilityFilter filter_standard(1, 6, 0);
|
||||||
CoinEligibilityFilter filter_confirmed(1, 1, 0);
|
CoinEligibilityFilter filter_confirmed(1, 1, 0);
|
||||||
CoinEligibilityFilter filter_standard_extra(6, 6, 0);
|
CoinEligibilityFilter filter_standard_extra(6, 6, 0);
|
||||||
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(0), 0, false);
|
CoinSelectionParams coin_selection_params(/* use_bnb= */ false, /* change_output_size= */ 0,
|
||||||
|
/* change_spend_size= */ 0, /* effective_fee= */ CFeeRate(0),
|
||||||
|
/* long_term_feerate= */ CFeeRate(0),
|
||||||
|
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
|
||||||
|
|
||||||
static void add_coin(const CAmount& nValue, int nInput, std::vector<CInputCoin>& set)
|
static void add_coin(const CAmount& nValue, int nInput, std::vector<CInputCoin>& set)
|
||||||
{
|
{
|
||||||
@ -269,7 +272,10 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that effective value is working in SelectCoinsMinConf when BnB is used
|
// Make sure that effective value is working in SelectCoinsMinConf when BnB is used
|
||||||
CoinSelectionParams coin_selection_params_bnb(true, 0, 0, CFeeRate(3000), 0, false);
|
CoinSelectionParams coin_selection_params_bnb(/* use_bnb= */ true, /* change_output_size= */ 0,
|
||||||
|
/* change_spend_size= */ 0, /* effective_fee= */ CFeeRate(3000),
|
||||||
|
/* long_term_feerate= */ CFeeRate(1000),
|
||||||
|
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
|
||||||
CoinSet setCoinsRet;
|
CoinSet setCoinsRet;
|
||||||
CAmount nValueRet;
|
CAmount nValueRet;
|
||||||
bool bnb_used;
|
bool bnb_used;
|
||||||
@ -639,8 +645,14 @@ BOOST_AUTO_TEST_CASE(SelectCoins_test)
|
|||||||
CAmount target = rand.randrange(balance - 1000) + 1000;
|
CAmount target = rand.randrange(balance - 1000) + 1000;
|
||||||
|
|
||||||
// Perform selection
|
// Perform selection
|
||||||
CoinSelectionParams coin_selection_params_knapsack(false, 34, 148, CFeeRate(0), 0, false);
|
CoinSelectionParams coin_selection_params_knapsack(/* use_bnb= */ false, /* change_output_size= */ 34,
|
||||||
CoinSelectionParams coin_selection_params_bnb(true, 34, 148, CFeeRate(0), 0, false);
|
/* change_spend_size= */ 148, /* effective_fee= */ CFeeRate(0),
|
||||||
|
/* long_term_feerate= */ CFeeRate(0),
|
||||||
|
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
|
||||||
|
CoinSelectionParams coin_selection_params_bnb(/* use_bnb= */ true, /* change_output_size= */ 34,
|
||||||
|
/* change_spend_size= */ 148, /* effective_fee= */ CFeeRate(0),
|
||||||
|
/* long_term_feerate= */ CFeeRate(0),
|
||||||
|
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
|
||||||
CoinSet out_set;
|
CoinSet out_set;
|
||||||
CAmount out_value = 0;
|
CAmount out_value = 0;
|
||||||
bool bnb_used = false;
|
bool bnb_used = false;
|
||||||
|
@ -2364,12 +2364,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
|||||||
nValueRet = 0;
|
nValueRet = 0;
|
||||||
|
|
||||||
if (coin_selection_params.use_bnb) {
|
if (coin_selection_params.use_bnb) {
|
||||||
// Get long term estimate
|
|
||||||
FeeCalculation feeCalc;
|
|
||||||
CCoinControl temp;
|
|
||||||
temp.m_confirm_target = 1008;
|
|
||||||
CFeeRate long_term_feerate = GetMinimumFeeRate(*this, temp, &feeCalc);
|
|
||||||
|
|
||||||
// Get the feerate for effective value.
|
// Get the feerate for effective value.
|
||||||
// When subtracting the fee from the outputs, we want the effective feerate to be 0
|
// When subtracting the fee from the outputs, we want the effective feerate to be 0
|
||||||
CFeeRate effective_feerate{0};
|
CFeeRate effective_feerate{0};
|
||||||
@ -2377,7 +2371,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
|
|||||||
effective_feerate = coin_selection_params.effective_fee;
|
effective_feerate = coin_selection_params.effective_fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, effective_feerate, long_term_feerate, eligibility_filter, true /* positive_only */);
|
std::vector<OutputGroup> groups = GroupOutputs(coins, !coin_selection_params.m_avoid_partial_spends, effective_feerate, coin_selection_params.m_long_term_feerate, eligibility_filter, true /* positive_only */);
|
||||||
|
|
||||||
// Calculate cost of change
|
// Calculate cost of change
|
||||||
CAmount cost_of_change = GetDiscardRate(*this).GetFee(coin_selection_params.change_spend_size) + coin_selection_params.effective_fee.GetFee(coin_selection_params.change_output_size);
|
CAmount cost_of_change = GetDiscardRate(*this).GetFee(coin_selection_params.change_spend_size) + coin_selection_params.effective_fee.GetFee(coin_selection_params.change_output_size);
|
||||||
@ -2820,6 +2814,11 @@ bool CWallet::CreateTransactionInternal(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get long term estimate
|
||||||
|
CCoinControl cc_temp;
|
||||||
|
cc_temp.m_confirm_target = chain().estimateMaxBlocks();
|
||||||
|
coin_selection_params.m_long_term_feerate = GetMinimumFeeRate(*this, cc_temp, nullptr);
|
||||||
|
|
||||||
nFeeRet = 0;
|
nFeeRet = 0;
|
||||||
bool pick_new_inputs = true;
|
bool pick_new_inputs = true;
|
||||||
CAmount nValueIn = 0;
|
CAmount nValueIn = 0;
|
||||||
|
@ -607,16 +607,19 @@ struct CoinSelectionParams
|
|||||||
size_t change_output_size = 0;
|
size_t change_output_size = 0;
|
||||||
size_t change_spend_size = 0;
|
size_t change_spend_size = 0;
|
||||||
CFeeRate effective_fee = CFeeRate(0);
|
CFeeRate effective_fee = CFeeRate(0);
|
||||||
|
CFeeRate m_long_term_feerate;
|
||||||
size_t tx_noinputs_size = 0;
|
size_t tx_noinputs_size = 0;
|
||||||
//! Indicate that we are subtracting the fee from outputs
|
//! Indicate that we are subtracting the fee from outputs
|
||||||
bool m_subtract_fee_outputs = false;
|
bool m_subtract_fee_outputs = false;
|
||||||
bool m_avoid_partial_spends = false;
|
bool m_avoid_partial_spends = false;
|
||||||
|
|
||||||
CoinSelectionParams(bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_fee, size_t tx_noinputs_size, bool avoid_partial) :
|
CoinSelectionParams(bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_fee,
|
||||||
|
CFeeRate long_term_feerate, size_t tx_noinputs_size, bool avoid_partial) :
|
||||||
use_bnb(use_bnb),
|
use_bnb(use_bnb),
|
||||||
change_output_size(change_output_size),
|
change_output_size(change_output_size),
|
||||||
change_spend_size(change_spend_size),
|
change_spend_size(change_spend_size),
|
||||||
effective_fee(effective_fee),
|
effective_fee(effective_fee),
|
||||||
|
m_long_term_feerate(long_term_feerate),
|
||||||
tx_noinputs_size(tx_noinputs_size),
|
tx_noinputs_size(tx_noinputs_size),
|
||||||
m_avoid_partial_spends(avoid_partial)
|
m_avoid_partial_spends(avoid_partial)
|
||||||
{}
|
{}
|
||||||
|
Loading…
Reference in New Issue
Block a user