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

feat(wallet)!: use miniscript plan in place of old policy mod #1786

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ValuedMammal
Copy link
Contributor

This PR integrates features of the miniscript plan module into the wallet internals, in particular when it comes to coin selection and tx building. If accepted, the result is that the new interface may eventually replace bdk's current policy code.

fixes #1382

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

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

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Previously creating a PSBT was limited to certain descriptor types
that excluded e.g. `wsh`. That is fixed by using `for_each_key`
which visits every pubkey in the descriptor.
We can't easily plan the utxos before all of the assets are known,
so having `TxBuilder` try to create `WeightedUtxo`s creates a
chicken and egg problem that we fix by moving some logic to
`Wallet::create_tx`.

`TxParams::utxos` field is thus split into two: `utxos` is a list
of outpoints strictly to be used for getting locally owned outputs,
and `foreign_utxos` handles adding `WeightedUtxos` coming from
`add_foreign_utxo`. These are later combined with the manually
selected coins to form the list of utxos that must be spent.
The internal behavior is preserved insofar as the policy
path can influence the outcome of tx building. The difference
is instead of encode the path as nodes in a policy tree, the
plan is determined by the `Assets` available.

Note that creating a `Plan` is a pre-requisite to coin selection,
so if a UTXO in the wallet can't be planned, it won't be selected.
The wallet attempts to create a plan for each UTXO based on the
available information. The user may provide additional assets or
specify a particular set of assets in order to complete a plan.

New APIs include `TxBuilder::add_assets`, `set_assets` and
`Wallet::try_plan`.

To prevent confusion due to overlapping functionality, the
`TxBuilder` methods `policy_path` and `current_height` are
removed.
- clean up unused `fee_amount` in `create_tx`
@ValuedMammal ValuedMammal self-assigned this Dec 20, 2024
@ValuedMammal ValuedMammal added this to the 2.0.0 milestone Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Can we remove policy module and use rust-miniscript ?
1 participant