New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add absolute fee rate convenience functions to FeeRate
#1947
Conversation
Make the docs use the same form as everywhere else, which also mimics stdlib docs on integer types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 89c8119
FeeRate
FeeRate
bitcoin/src/blockdata/fee_rate.rs
Outdated
/// `None` if overflow occurred. | ||
/// | ||
/// This is equivalent to `Self::checked_mul_by_weight()`. | ||
pub fn absolute_fee_wu(self, weight: Weight) -> Option<Amount> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use checked_mul_by_weight()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why absolute fee
instead of fee_wu
? if the name checked_mul_by_weight
is confusing, maybe just rename that function instead of adding this wrapper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I like the absolute_fee_wu
name, I've always found bdk's fee_wu
to be quite confusing. I don't have any strong opinion on renaming vs adding a wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the word absolute
mean in the context of fee? Is there such a thing as a non-absolute fee?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dug around math and english definitions of "absolute" and, contrary to my gut feeling, it does not add any additional meaning although it was also [mis]used in this Bitocin Core PR.
I've removed the absolute_
prefix.
bitcoin/src/blockdata/fee_rate.rs
Outdated
/// | ||
/// This is equivalent to converting `vb` to `weight` using `Weight::from_vb` and then calling | ||
/// `Self::checked_mul_by_weight(weight)`. | ||
pub fn absolute_fee_vb(self, vb: u64) -> Option<Amount> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an additional test would be nice to go along with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 89c8119
bitcoin/src/blockdata/fee_rate.rs
Outdated
/// `None` if overflow occurred. | ||
/// | ||
/// This is equivalent to `Self::checked_mul_by_weight()`. | ||
pub fn absolute_fee_wu(self, weight: Weight) -> Option<Amount> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I like the absolute_fee_wu
name, I've always found bdk's fee_wu
to be quite confusing. I don't have any strong opinion on renaming vs adding a wrapper.
89c8119
to
39f28b9
Compare
39f28b9
to
5a469be
Compare
Changes in force push:
|
Calculating the absolute fee from a fee rate can currently be achieved by creating a `Weight` object and using `FeeRate::checked_mul_by_weight`. This is kind of hard to discover, we can add two public convenience functions that make discovery of the functionality easier. Add two functions for calculating the absolute fee by multiplying by weight units (`Weight`) and virtual bytes (by first converting to weight units).
5a469be
to
9eff2f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 9eff2f2
@@ -199,4 +225,20 @@ mod tests { | |||
let fee_rate = FeeRate(10).checked_div(0); | |||
assert!(fee_rate.is_none()); | |||
} | |||
|
|||
#[test] | |||
fn fee_convenience_functions_agree() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test could be boilled down to like two lines:
fn fee_convenience_functions_agree() {
let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/byte is valid");
assert_eq!(rate.fee_vb(1), rate.fee_wu(Weight::from_wu(4)));
}
after all, no need to test all of the transaction serialization stuff again here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 9eff2f2
Removed the @ mention from the PR description because it's likely to cause more noise than intended. |
Oh I thought it only spammed if in the commit not in the PR? |
@tcharding the merge script copies the PR message into the commit. |
Oh of course. Thanks. |
FeeRate
From the commit log of patch 2:
This seems like an obvious thing so I'm inclined to think that Kixunil left it out for a reason. (Mentioning you here Kix so even if this merges you'll see it in notifications later on.)