Skip to content
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

refactor(wallet)!: Use Weight type instead of usize #1468

Conversation

oleonardolima
Copy link
Contributor

@oleonardolima oleonardolima commented Jun 7, 2024

fixes #1466
depends on #1448

Description

This PR is a follow-up on top of #1448, and should be rebased and merged after it, it uses the rust-bitcoin Weight type instead of the current usize usage.

NOTE: It also adds a new MiniscriptError variant, and remove the .unwrap() usage. As suggested I'll address this on another issue #1485, trying to reproduce the error first.

Notes to the reviewers

It should be ready to review after #1448 gets merged.

Changelog notice

  • Change WeightedUtxo satisfaction_weight has been changed to use Weight type.
  • Change TxBuilder methods add_foreign_utxo and add_foreign_utxo_with_sequence to expect Weight as satisfaction_weight type.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch 2 times, most recently from e0acc69 to fe0f5e5 Compare June 7, 2024 21:03
@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch 2 times, most recently from 44e446f to 3bcb211 Compare June 12, 2024 02:15
@oleonardolima oleonardolima changed the title wip(feat): use Weight type instead of usize feat: use Weight type instead of usize Jun 12, 2024
@notmandatory notmandatory added the api A breaking API change label Jun 13, 2024
@notmandatory notmandatory added this to the 1.0.0-alpha milestone Jun 13, 2024
@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch from 3bcb211 to 51e6f6d Compare June 13, 2024 13:39
@oleonardolima oleonardolima marked this pull request as ready for review June 13, 2024 13:39
@oleonardolima
Copy link
Contributor Author

oleonardolima commented Jun 13, 2024

Okay we need to create a ticket for what we should do when a caller creates a wallet with descriptors that are insatiable. Panicing with no clear reason when they try construct a tx is not the right behavior imo. Out of scope for this PR.

@evanlinjin mentioned it the #1448 (comment). I'm moving the discussion to here as I've tried to address it here at 51e6f6d.

edit: also refer to upstream issue rust-bitcoin/rust-miniscript#695

@apoelstra
Copy link

Ok, moving my comment here:

Regarding the error path of max_weight_to_satisfy when you try to give it a (literally) unspendable descriptor like wsh(0) or something, I see a couple ways you can handle this:

  • Try to propagate the error from the max_weight_to_satisfy call, treating it similarly to a transient "cannot spend" condition.
  • Use .unwrap_or(Weight::MAX) which will have roughly the correct semantics without causing errors (though it could cause panics down the line if you add with it)
  • Petition upstream to add a flag to ExtParams that would refuse to parse such scripts, then you can unwrap. Then users would be unable to import such scripts. Maybe you want them to be able to, though, for watch-only wallets?

@oleonardolima
Copy link
Contributor Author

Thanks for the suggestions! Although I've tried to do something similar to option (1), I'm now wondering about option (2), still need to think about the possible panics down the line 🤔

@ValuedMammal
Copy link
Contributor

I'm wondering whether it's even possible to create a bdk Wallet with an unsatisfiable descriptor

@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch from 51e6f6d to 6250c36 Compare June 14, 2024 14:59
@storopoli
Copy link
Contributor

I think that what idea (2) meant was to use the Weight::MAX which is actually u64::MAX (Ref: https://docs.rs/bitcoin-units/0.1.1/src/bitcoin_units/weight.rs.html#35).
That might hit the DEFAULT_MAX_FEE_RATE which is 25_000 sats/vB (Ref: https://docs.rs/bitcoin/latest/src/bitcoin/psbt/mod.rs.html#133.

If we hit that, then we get a ExtractTxError.

I think that's what it is meant as could cause panics.

What am I missing? I probably could be wrong here.
I am assuming that Psbt::extract_tx_fee_rate_limit() is being called somewhere down the line, right?

@ValuedMammal
Copy link
Contributor

I'm also ok with just fixing the usize to Weight stuff in this PR and creating a separate issue to decide how to handle an unsatisfiable descriptor

@oleonardolima
Copy link
Contributor Author

I'm also ok with just fixing the usize to Weight stuff in this PR and creating a separate issue to decide how to handle an unsatisfiable descriptor

Yes, I removed the other commit. I only fixes the usage of usize now.

@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch from 70a568b to 729fec6 Compare June 21, 2024 22:43
Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK 729fec6

I know this is picky but since this change is API breaking, the commit should tell us that in conventional commits style, so something like

refactor(wallet)!: change WeightedUtxo to use Weight type

In general the changelog should communicate any API changes so in this case the fact that WeightedUtxo is changed as well as the function signatures for add_foreign_utxo{_with_sequence}

Note to reviewers we didn't fix the unwrap for max_weight_to_satisfy but an issue has been created to discuss further.

@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch from 729fec6 to d8c609b Compare June 22, 2024 03:32
@oleonardolima
Copy link
Contributor Author

ACK 729fec6

I know this is picky but since this change is API breaking, the commit should tell us that in conventional commits style, so something like

refactor(wallet)!: change WeightedUtxo to use Weight type

In general the changelog should communicate any API changes so in this case the fact that WeightedUtxo is changed as well as the function signatures for add_foreign_utxo{_with_sequence}

Note to reviewers we didn't fix the unwrap for max_weight_to_satisfy but an issue has been created to discuss further.

No worries, thanks for the suggestions. 🚀

@oleonardolima oleonardolima force-pushed the feat/use-weight-type-instead-of-usize branch from d8c609b to 438cd46 Compare June 26, 2024 12:09
Copy link
Contributor

@storopoli storopoli left a comment

Choose a reason for hiding this comment

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

I'm also ok with just fixing the usize to Weight stuff in this PR and creating a separate issue to decide how to handle an unsatisfiable descriptor

I second this. Do we have the issue open? I did not see linked to this PR.

Anyways, ACK 438cd46

@oleonardolima
Copy link
Contributor Author

I second this. Do we have the issue open? I did not see linked to this PR.

Yes, it's on the PR description, issue: #1485

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK 438cd46

@notmandatory notmandatory merged commit 5c7cc30 into bitcoindevkit:master Jun 26, 2024
12 checks passed
@oleonardolima oleonardolima deleted the feat/use-weight-type-instead-of-usize branch June 27, 2024 13:08
@notmandatory notmandatory mentioned this pull request Jul 20, 2024
30 tasks
@notmandatory notmandatory changed the title feat: use Weight type instead of usize refactor(wallet)!: Use Weight type instead of usize Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

feat: use new Weight type throughout the BDK codebase, instead of usize for weight units
5 participants