Add fee_amount() and fee_rate() functions to PsbtUtils trait#728
Add fee_amount() and fee_rate() functions to PsbtUtils trait#728afilini merged 1 commit intobitcoindevkit:masterfrom
Conversation
0608644 to
7a9ed14
Compare
vladimirfomene
left a comment
There was a problem hiding this comment.
Tested ACK. Just have one question.
| } | ||
| } | ||
|
|
||
| fn fee_amount(&self) -> u64 { |
There was a problem hiding this comment.
I'm wondering why the output_amount is calculated using the unsigned_tx outputs and not the PSBT outputs.
There was a problem hiding this comment.
The PSBT and transactions inputs and outputs should all be the same. But your questions made me think about moving these functions to the TransactionDetails struct, or maybe as new util trait on Transaction. Will noodle around with that and see how it works out.
There was a problem hiding this comment.
Also I just remembered the reason I needed to use PSBT to calculate the fee_amount is because it contains the full details for the transaction inputs, which includes the input amounts, if you only look at the Transaction structure it contains essentially "pointers" to the unspent outputs that become the inputs (the OutPoint) and this structure does not contain the input amounts. So I'm leaving these helper functions on the PsbtUtils trait.
|
Linking bitcoindevkit/bdk_wallet#187 to this. |
There was a problem hiding this comment.
Concept ACK. It will be helpful to get the feerate in the unsigned stage.
And if I understand correctly, the ask of #524 is to have the fee rate in unsigned transaction specifically, which is a special annoying problem. As we don't know the size before fully signing it. Its straight forward to calculate the fee rate from a signed tx just from the transaction data itself. We know both the fee and the size after signing.
I think one way could be to return the FeeRate in the TransactionDetails itself from create_tx() function. The fee rate value exists in the create_tx() function, we just happen to throw it away after coinselection. here
Lines 848 to 855 in 0a3734e
So instead why not just keep the value alive and store it in the TransactionDetails.
Edge Case: If I understand correctly the interplay between fee_rate and fee_amount happening here
Lines 743 to 770 in 0a3734e
It seems if the user sets a FeePolicy::FeeAmount(fee) then fee_rate will always be 0, and in that case we should have that value as None in the TrasnactionDetails.
|
Another idea.. We have a Bad idea: The wallet might have inputs for which it can't produce satisfaction. |
|
@rajarshimaitra you're right that the initial request was for an estimate of the fee rate before signing. Since I didn't see an easy way to do that so I went for giving the exact fee rate of the PSBT after it's finalized. I didn't think of using the |
There was a problem hiding this comment.
@notmandatory Noted.. This can be done in separate PR..
tACK 7a9ed14
Although I am thinking if its much useful to provide this as a separate function, as its mostly straight forward calculation from any signed transaction data. But I guess having extra utility never hurts..
danielabrozzoni
left a comment
There was a problem hiding this comment.
utACK 7a9ed14
I've also added this PR to the milestone, as it seems super close to getting in :)
|
BTW, I didn't add a CHANGELOG message since I'm assuming we'll have #544 in for this next release. If not I'll need to update CHANGELOG before this goes in. |
7a9ed14 to
8ee055d
Compare
|
rebased to pickup ci and other changes |
8ee055d to
7d07e48
Compare
7d07e48 to
9f4bcc0
Compare
PsbtUtils.fee_amount(), calculates the PSBT total transaction fee amount in Sats. PsbtUtils.fee_rate(), calculates the PSBT FeeRate, the value is only accurate AFTER the PSBT is finalized.
9f4bcc0 to
ab41679
Compare
34987d5 Make psbt mod public and add required docs (Steve Myers) Pull request description: ### Description Make psbt mod public and add required docs. The module needs to be public so `bdk-ffi` can expose the new PSBT `fee_amount()` and `fee_rate()` functions. ### Notes to the reviewers I should have done this as part of #728. ### Changelog notice Make psbt module public to expose PsbtUtils trait to downstream projects. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: rajarshimaitra: Concept + tACK 34987d5 Tree-SHA512: 99e91e948bccb7593a3da3ac5468232103d4ba90ad4e5888ef6aebb0d16511ad3a3286951779789c05587b4bb996bc359baa28b0f4c3c55e29b24bfc12a10073
Description
The purpose of the PR is to provide a more convenient way to calculate the transaction fee amount and fee rate for a PSBT. This PR adds
fee_amountandfee_ratefunctions to the existingPsbtUtilstrait and implements them forPartiallySignedBitcoinTransaction. Thefee_ratevalue is only valid if the PSBT it is called on is fully signed and finalized.See related discussion: bitcoindevkit/bdk-ffi#179
Changelog
Added
Notes to the reviewers
Ideally I'd like
fee_rateto return anOptionand returnNoneif the PSBT isn't finalized. But I'm not quite sure how to determine if a PSBT is finalized without having aWalletand running it through the finalize code first. Or there might be a way to fill in missing signatures with properly sized fake data prior to calculating the fee rate. For now I think it's enough to do this simple approach with usage warning in the rust docs.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: