Add max_fee_rate() method to Config to encapsulate default#1490
Add max_fee_rate() method to Config to encapsulate default#1490codaMW wants to merge 1 commit intopayjoin:masterfrom
Conversation
Coverage Report for CI Build 24809175609Coverage remained the same at 84.953%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
The Lint-FFI failure is a pre-existing clippy issue in payjoin-ffi unrelated to this PR. Opened #1491 to fix it separately. |
nothingmuch
left a comment
There was a problem hiding this comment.
concept ACK
i would prefer if this PR went a bit further, and made things consistent between v1 and v2
i think there's three ways this could happen:
-
either the new method could be removed and
Nonepassed in ensuring that everything is still correct with the hard coded min feerate in `payjoin::core::receive::common::WantsFeeRange::calculate_psbt_with_fee_range -
v1 CLI would provide this default for consistency with v2, and this would be redundant with the
unwrap_orincalculate_psbt_with_fee_range, it's just that both CLI implementations never passNone -
we remove the
Optionwrapping ofFeeRatein thepayjoinapi and require both v1 and v2
the first is the simplest, and i think my preference but it would need to be verified to ensure everything still behaves correctly, i didn't verify that it's sound, but max_fee_rate: None seems like there is no maximum enforced which can look wrong/scary.
the second is a bit meh.
the third is arguably the most misuse resistant, but breaks the API, and although more rigid since we treat None very conservatively and forcing wallet developers to pick a value explicitly may actually increase risk
i think my preference is the first option now that i know about this inconsistency and that the payjoin crate enforces the same default. perhaps there should be a comment in the payjoin-cli crate to clarify that when with_max_fee_rate
is given None it's actually a very low max?
another idea to clear that wrong connotation up: maybe that can be bikeshed to make it a bit better like enum OptionalFeerate { Some(FeeRate), MinRelayFee }
| } | ||
|
|
||
| /// Returns the maximum fee rate, defaulting to [`FeeRate::BROADCAST_MIN`] if not configured. | ||
| #[cfg(feature = "v2")] |
There was a problem hiding this comment.
i was not aware, but apparently v1 passes None all the way down and unwrap_or(FeeRate::BROADCAST_MIN) happens in payjoin/src/core/receive/common/mod.rs instead of in payjoin-cli
|
Thanks for the context @nothingmuch. I verified that payjoin/src/core/receive/common/mod.rs already handles None with unwrap_or(FeeRate::BROADCAST_MIN) on both min and max, so passing None from v2 is safe and consistent with v1's existing behavior. |
7b182e9 to
b87f16b
Compare
|
Updated. After checking the signatures, ReceiverBuilder::with_max_fee_rate() in v2 requires FeeRate directly (not Option), unlike v1's apply_fee_range which accepts Option and defaults to BROADCAST_MIN internally. So option 1 isn't directly applicable to v2 the unwrap_or must happen in the CLI layer. |
|
ah right, if you don't call changing the default value imo is a breaking change, so perhaps the reasoning for this is not very strong as the default value is very unlikely to change without significant other changes, but it just feels really off to me to have it applied in 3 redundant places in the v2 code path, that's confusing. it's not the prettiest, but consider: if let Some(max_fee_rate) = self.config.max_fee_rate {
receiver_builder = receiver_builder.with_max_fee_rate(max_fee_rate);
}IMO that makes more sense than unwrapping with that would bring the redundant default fallback count down to 2, once internally in then in a followup PR, since i think this would be an improvement even though it's just shuffling code around, because in the v2 code path it's this is very bikesheddy, so someone else should concept ACK this suggestion before you go ahead with this |
Concept ACK on the if let approach. Agreed that letting the payjoin crate own the default is the right call. It also brings v1 and v2 into alignment, which was the point. If it’s helpful, I’m happy to take on the followup PR to update calculate_psbt_context_with_fee_range to require a concrete FeeRate instead of Option once this lands. |
Instead of unwrap_or(FeeRate::BROADCAST_MIN) in payjoin-cli, use if let to only call with_max_fee_rate when a value is explicitly configured. This lets the payjoin crate own the default (BROADCAST_MIN in SessionContext), consistent with how v1 handles the absence of a configured max fee rate. See payjoin#1482 Disclosure: I consulted Claude to understand the codebase structure, but the solution was authored by myself.
b87f16b to
9ba7d70
Compare
|
Updated to use if let, with_max_fee_rate is only called when a value is explicitly configured, letting the payjoin crate own the default (BROADCAST_MIN in SessionContext). This is consistent with how v1 handles the absence of a configured max fee rate. |
caarloshenriq
left a comment
There was a problem hiding this comment.
tACK b87f16b
Ran cargo test -p payjoin and cargo test -p payjoin-cli, all tests pass. Change is exactly what was discussed, with_max_fee_rate only called when explicitly configured, default ownership stays in the payjoin crate, consistent with v1.
See #1482
Adds a
Config::max_fee_rate()method that encapsulates theunwrap_or(FeeRate::BROADCAST_MIN)default, removing that detailfrom the
AppTraitimpl and improving readability of the call site.Pull Request Checklist
Disclosure: I consulted Claude to understand the codebase structure,
but the solution was authored by myself.