Skip to content

Add absolute fee rate convenience functions to FeeRate#1947

Merged
apoelstra merged 3 commits intorust-bitcoin:masterfrom
tcharding:07-20-absolute-fee
Aug 2, 2023
Merged

Add absolute fee rate convenience functions to FeeRate#1947
apoelstra merged 3 commits intorust-bitcoin:masterfrom
tcharding:07-20-absolute-fee

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Jul 19, 2023

  • Patch 1 is docs cleanup
  • Patch 2 adds two functions to FeeRate

From the commit log of patch 2:

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).

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.)

Make the docs use the same form as everywhere else, which also mimics
stdlib docs on integer types.
apoelstra
apoelstra previously approved these changes Jul 20, 2023
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 89c81193a71eaf6b55b0e09383c7188ee6b973ab

@tcharding tcharding changed the title Add absolute fee rate convenient functions to FeeRate Add absolute fee rate convenience functions to FeeRate Aug 1, 2023
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.

why not just use checked_mul_by_weight()?

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.

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?

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.

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.

Copy link
Copy Markdown
Contributor

@yancyribbens yancyribbens Aug 1, 2023

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?

Copy link
Copy Markdown
Member Author

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.

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.

an additional test would be nice to go along with this.

Copy link
Copy Markdown
Contributor

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

ACK 89c81193a71eaf6b55b0e09383c7188ee6b973ab

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.

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.

@tcharding tcharding force-pushed the 07-20-absolute-fee branch from 39f28b9 to 5a469be Compare August 1, 2023 22:29
@tcharding
Copy link
Copy Markdown
Member Author

Changes in force push:

  • Added an additional trivial rustdoc fix patch (as patch 2)
  • Rename functions by dropping the "absolute_" prefix
  • Added a unit test to verify the two convenience functions agree

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).
@tcharding tcharding force-pushed the 07-20-absolute-fee branch from 5a469be to 9eff2f2 Compare August 1, 2023 23:10
Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

utACK 9eff2f2

}

#[test]
fn fee_convenience_functions_agree() {
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.

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.

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 9eff2f2

@apoelstra
Copy link
Copy Markdown
Member

Removed the @ mention from the PR description because it's likely to cause more noise than intended.

@apoelstra apoelstra merged commit 49fa879 into rust-bitcoin:master Aug 2, 2023
@tcharding
Copy link
Copy Markdown
Member Author

Oh I thought it only spammed if in the commit not in the PR?

@apoelstra
Copy link
Copy Markdown
Member

@tcharding the merge script copies the PR message into the commit.

@tcharding
Copy link
Copy Markdown
Member Author

Oh of course. Thanks.

@tcharding tcharding deleted the 07-20-absolute-fee branch August 3, 2023 23:04
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.

5 participants