Skip to content

units: add consolidate_feerate as cli arg - #77

Merged
rustaceanrob merged 1 commit into
kernel-node:masterfrom
yancyribbens:0701-add-long-term-fee-rate
Jul 18, 2026
Merged

units: add consolidate_feerate as cli arg#77
rustaceanrob merged 1 commit into
kernel-node:masterfrom
yancyribbens:0701-add-long-term-fee-rate

Conversation

@yancyribbens

Copy link
Copy Markdown
Contributor

The current behavior of hard-coding the long_term_fee_rate to be 1 can result in incorrect coin-selection behavior.

@yancyribbens
yancyribbens force-pushed the 0701-add-long-term-fee-rate branch from 435f5b2 to bac72d5 Compare July 3, 2026 16:32
@yancyribbens

Copy link
Copy Markdown
Contributor Author

I added a commit to match more closely the conventions used in the core client (see commit message).

@yancyribbens yancyribbens changed the title units: add long_term_fee_rate as cli arg units: add consolidate_feerate as cli arg Jul 3, 2026
@pzafonte

pzafonte commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

For latent safety purposes would it make more sense to put the 10 sat/vB default at the ipc.rs boundary, with a named constant?

// mirrors bitcoin-core's DEFAULT_CONSOLIDATE_FEERATE (10 sat/vB)
const DEFAULT_CONSOLIDATE_FEE_RATE_SAT_PER_VB: f64 = 10.0;

let raw = p.get_consolidate_fee_rate_sat_per_vb();
if !raw.is_finite() || raw < 0.0 {
    return Err(capnp::Error::failed(
        "consolidate fee rate must be a non-negative number".to_string(),
    ));
}
let long_term_sat_per_vb = if raw == 0.0 {
    DEFAULT_CONSOLIDATE_FEE_RATE_SAT_PER_VB
} else {
    raw
};

@yancyribbens

Copy link
Copy Markdown
Contributor Author

For latent safety purposes would it make more sense to put the 10 sat/vB default at the ipc.rs boundary, with a named constant?

Thanks for the suggestion, although, im not sure I fully understand. Clap allows default arguments, so in the CLI options, there needs to be something done if the option is not provided I believe. Are you suggesting changing the way the defaults are handled in cli.rs as well as the suggestion above?

I think the other part of your suggestion is that if a value is provided, and the value is 0.0, that it should be changed to a default value instead? Not sure, I find that not so intuitive and maybe we should just error on a 0.0 consolidate_fee_rate. However, it looks like currently 0.0 for fee-rate is accepted, which I think is actually a problem since the network will never propagate a transaction with a 0.0 feerate.

@pzafonte

Copy link
Copy Markdown
Contributor

Right now 0 is accepted. My preference is to let the server own the default, which looks like how Core does it. Erroring on 0 makes sense but pulls the default back onto the CLI and capnp can't tell "sent 0" from "sent nothing," so once you reject 0 the client has to supply the value. That's what I was trying to avoid, so I lean server-side default.

@yancyribbens
yancyribbens force-pushed the 0701-add-long-term-fee-rate branch from bac72d5 to 8792960 Compare July 14, 2026 15:55
@yancyribbens

Copy link
Copy Markdown
Contributor Author

Right now 0 is accepted. My preference is to let the server own the default, which looks like how Core does it. Erroring on 0 makes sense but pulls the default back onto the CLI and capnp can't tell "sent 0" from "sent nothing," so once you reject 0 the client has to supply the value. That's what I was trying to avoid, so I lean server-side default.

It sounds like a good idea to enforce the default on the server. However, I'm still a little unclear how the CLI should behave when it gets no argument, since it must then set a value which may as well be the default. Never the less, I have added your suggestion as a fixup even though this now means the default is being set twice. Please let me know if this is what you had in mind or what I am missing.

Comment thread crates/wallet/src/silentpayments/sending.rs Outdated
Comment thread crates/wallet/src/silentpayments/sending.rs Outdated
@yancyribbens
yancyribbens force-pushed the 0701-add-long-term-fee-rate branch from 58c48b9 to eeeb968 Compare July 15, 2026 16:31
@yancyribbens

Copy link
Copy Markdown
Contributor Author

If there's no further feedback I can autosquash the commits then. I don't think Github is smart enough to autosqush on merge.

Comment thread src/bin/cli.rs Outdated
Comment thread src/bin/cli.rs Outdated
Comment thread src/ipc.rs Outdated
Comment thread crates/wallet/src/silentpayments/sending.rs Outdated
Comment thread capnp/wallet.capnp Outdated
Comment thread src/bin/cli.rs
/// use more inputs than strictly necessary so that the wallet's UTXO
/// pool can be reduced (default: 10 sats/vB). Long term fee rate,
/// in satoshis per virtual byte.
consolidate_fee_rate_sat_per_vb: Option<f64>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still lost as to what this value is for. Can we explain how this interacts with the fee_rate_sat_per_vb here? I think that is what most users would care about

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add a little more to the docs comment, the consolidation fee (also known as long_term_fee_rate) helps to determine if the current fee_rate is high or low. So, if fee_rate > consolidation_fee_rate, then the current fee_rate is high based on historical trends, and if consolidation_fee_rate > fee_rate then the current fee_rate level is considered cheap. The reason this matters is that BnB will select more inputs to build a transaction when fees are cheap to consolidate the utxo set. Likewise, if the current environment is a low fee_rate environment, BnB will try to find a solution with the least number of UTXOs possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is why hard_coding the long_term_fee_rate to 1.0 is bad, because it will direct the selection algorithms to think that we are always in a high fee environment, since it's fairly likely that fee_rate is greater than 1 sat/vB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, by adding this as a parameter, its possible you could do a curl or wget request from some external API to find this value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok much clearer now. Would you be able to condense that a bit and add that logic in the doc comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done, with the caveat that this is how the bitcoin core selection works, as well as rust bitcoin coin-selection. However, I'm reasonably sure that's how bdk coin-select works as well. Although, as stated before, I'm not really as well versed on that project.

@yancyribbens
yancyribbens force-pushed the 0701-add-long-term-fee-rate branch 4 times, most recently from 724e446 to 20556ca Compare July 17, 2026 21:56
The current behavior of hard-coding the long_term_fee_rate to be 1
can result in incorrect coin-selection behavior.

In bitcoin-core, long-term-feerate is set on the command line using the
flag consolidate_feerate, and then changed to long_term_fee_rate in
spend.cpp before calling coin-selection algorithms [1].

The text was also copied verbatim (besides units) from the bitcoin-core
client [2] and expanded.

The default was set to match that of bitcoin-core (10 sats/vB) [3].
This is accomplished by setting a default value via the capnproto
interface.

[1] ref: https://github.com/bitcoin/bitcoin/blob/32ddfc92d9fdad40880f4c1aa3ad8884d3c8981a/src/wallet/spend.cpp#L1083
[2] ref: https://github.com/bitcoin/bitcoin/blob/32ddfc92d9fdad40880f4c1aa3ad8884d3c8981a/src/wallet/init.cpp#L52
[3] ref: https://github.com/bitcoin/bitcoin/blob/32ddfc92d9fdad40880f4c1aa3ad8884d3c8981a/src/wallet/init.cpp#L52
@yancyribbens
yancyribbens force-pushed the 0701-add-long-term-fee-rate branch from 20556ca to 99c4ce8 Compare July 17, 2026 22:05

@rustaceanrob rustaceanrob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rustaceanrob
rustaceanrob merged commit 819b1cf into kernel-node:master Jul 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants