Skip to content

Commit 54de7b4

Browse files
committed
Allow the long term feerate to be configured, default of 10 sat/vb
The long term feerate is really the highest feerate that the user is comfortable with making consolidatory transactions. This is should thus be something that can be configured by the user via a new startup option -consolidatefeerate. The default value is 10 sat/vbyte, chosen arbitrarily (it seems like a reasonable number).
1 parent eb09c26 commit 54de7b4

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

src/dummywallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
2828
"-addresstype",
2929
"-avoidpartialspends",
3030
"-changetype",
31+
"-consolidatefeerate=<amt>",
3132
"-disablewallet",
3233
"-discardfee=<amt>",
3334
"-fallbackfee=<amt>",

src/wallet/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
4545
argsman.AddArg("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
4646
argsman.AddArg("-avoidpartialspends", strprintf("Group outputs by address, selecting many (possibly all) or none, instead of selecting on a per-output basis. Privacy is improved as addresses are mostly swept with fewer transactions and outputs are aggregated in clean change addresses. It may result in higher fees due to less optimal coin selection caused by this added limitation and possibly a larger-than-necessary number of inputs being used. Always enabled for wallets with \"avoid_reuse\" enabled, otherwise default: %u.", DEFAULT_AVOIDPARTIALSPENDS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
4747
argsman.AddArg("-changetype", "What type of change to use (\"legacy\", \"p2sh-segwit\", or \"bech32\"). Default is same as -addresstype, except when -addresstype=p2sh-segwit a native segwit output is used when sending to a native segwit address)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
48+
argsman.AddArg("-consolidatefeerate=<amt>", strprintf("The maximum feerate (in %s/kvB) at which transaction building may use more inputs than strictly necessary so that the wallet's UTXO pool can be reduced (default: %s).", CURRENCY_UNIT, FormatMoney(DEFAULT_CONSOLIDATE_FEERATE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
4849
argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
4950
argsman.AddArg("-discardfee=<amt>", strprintf("The fee rate (in %s/kvB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). "
5051
"Note: An output is discarded if it is dust at this rate, but we will always discard up to the dust relay fee and a discard fee above that is limited by the fee estimate for the longest target",

src/wallet/spend.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ bool CWallet::CreateTransactionInternal(
586586
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
587587
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
588588

589+
// Set the long term feerate estimate to the wallet's consolidate feerate
590+
coin_selection_params.m_long_term_feerate = m_consolidate_feerate;
591+
589592
CAmount recipients_sum = 0;
590593
const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
591594
ReserveDestination reservedest(this, change_type);
@@ -659,11 +662,6 @@ bool CWallet::CreateTransactionInternal(
659662
return false;
660663
}
661664

662-
// Get long term estimate
663-
CCoinControl cc_temp;
664-
cc_temp.m_confirm_target = chain().estimateMaxBlocks();
665-
coin_selection_params.m_long_term_feerate = GetMinimumFeeRate(*this, cc_temp, nullptr);
666-
667665
// Calculate the cost of change
668666
// Cost of change is the cost of creating the change output + cost of spending the change output in the future.
669667
// For creating the change output now, we use the effective feerate.

src/wallet/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,15 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
27012701
walletInstance->m_default_max_tx_fee = max_fee.value();
27022702
}
27032703

2704+
if (gArgs.IsArgSet("-consolidatefeerate")) {
2705+
if (std::optional<CAmount> consolidate_feerate = ParseMoney(gArgs.GetArg("-consolidatefeerate", ""))) {
2706+
walletInstance->m_consolidate_feerate = CFeeRate(*consolidate_feerate);
2707+
} else {
2708+
error = AmountErrMsg("consolidatefeerate", gArgs.GetArg("-consolidatefeerate", ""));
2709+
return nullptr;
2710+
}
2711+
}
2712+
27042713
if (chain && chain->relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB) {
27052714
warnings.push_back(AmountHighWarn("-minrelaytxfee") + Untranslated(" ") +
27062715
_("The wallet will avoid paying less than the minimum relay fee."));

src/wallet/wallet.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ static const CAmount DEFAULT_FALLBACK_FEE = 0;
7373
static const CAmount DEFAULT_DISCARD_FEE = 10000;
7474
//! -mintxfee default
7575
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
76+
//! -consolidatefeerate default
77+
static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte
7678
/**
7779
* maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled by default
7880
*
@@ -638,6 +640,12 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
638640
* output itself, just drop it to fees. */
639641
CFeeRate m_discard_rate{DEFAULT_DISCARD_FEE};
640642

643+
/** When the actual feerate is less than the consolidate feerate, we will tend to make transactions which
644+
* consolidate inputs. When the actual feerate is greater than the consolidate feerate, we will tend to make
645+
* transactions which have the lowest fees.
646+
*/
647+
CFeeRate m_consolidate_feerate{DEFAULT_CONSOLIDATE_FEERATE};
648+
641649
/** The maximum fee amount we're willing to pay to prioritize partial spend avoidance. */
642650
CAmount m_max_aps_fee{DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}; //!< note: this is absolute fee, not fee rate
643651
OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE};

0 commit comments

Comments
 (0)