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

WIP: bdk_core::coin_select integration #773

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Oct 3, 2022

Description

This is just a showcase of how coin selection will look with bdk_core integration. Tests are failing badly at the moment and I still need to figure out why.

Notes to the reviewers

This is still WIP, but let me know what you think.

Changelog notice

Integrate bdk_core::coin_select module.

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

@evanlinjin evanlinjin force-pushed the bdk_core_coin_select_integration branch 4 times, most recently from be40647 to f8d9c97 Compare October 4, 2022 05:34
There is a bug in miniscript where they fail to take into consideration
an `OP_PUSH..` (4 weight units) when calculating
`max_satisfaction_weight` for `pkh` script types.

We add this weight explicitly for `pkh` script types during coin
selection.
Weight units should always be whole units. However, virtual bytes will
need decimal places and the conversion from weight unit to vbytes should
not be rounded.

This commit has the following changes:
* vbytes should always be represented in `f32`
* conversion between vbytes and weight units should never be rounded
* simple calculations (such as those for feerates) should be explicitly
  defined (instead of using multiple small functions)
Since `CoinSelectionAlgorithm` is a trait, if the database is really
needed, one can create a struct that contains a database field which
implements the `CoinSelectionAlgorithm` trait.

Most `CoinSelectionAlgorithm` implementations do not require a database.
Use `iter_unspent` instead, as it returns an iterator directly.
If `exclude_hash` is set, we split the input data, and if a checksum
already existed within the original data, we check the calculated
checksum against the original checksum.

Additionally, the implementation of `IntoWalletDescriptor` for `&str`
has been refactored for clarity.
`Wallet` stores the descriptors' checksum in the database for safety.
Previously, the checksum used was a checksum of a descriptor that
already had a checksum.

This PR allows for backward-compatibility of databases created with this
bug.
This begins work on the `wallet::coin_control` module. The idea is to
filter coins, and determine which coins are fit for coin selection.

`Wallet::avaliable_utxos` is introduced to use `CoinFilterParams`.
@evanlinjin evanlinjin force-pushed the bdk_core_coin_select_integration branch from eff7a50 to 543b263 Compare October 4, 2022 14:40
@evanlinjin evanlinjin force-pushed the bdk_core_coin_select_integration branch from 618cece to 429e505 Compare October 4, 2022 16:24
@evanlinjin
Copy link
Member Author

evanlinjin commented Oct 5, 2022

---- blockchain::rpc::test::bdk_blockchain_tests::test_taproot_key_spend stdout ----
- wv satisfaction weight: 65
pool: [(0, WeightedValue { value: 50000, weight: 225, input_count: 1, is_segwit: true })]
selected: index=0, value=50000
create_tx: weight=563, fee=141, feerate=0.25044405sats/wu
create_tx: feerate=1.0017762sats/vb
thread 'blockchain::rpc::test::bdk_blockchain_tests::test_taproot_key_spend' panicked at 'called `Result::unwrap()` on an `Err` value: Rpc(JsonRpc(Rpc(RpcError { code: -26, message: "min relay fee not met, 141 < 142", data: None })))', src/blockchain/rpc.rs:886:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    blockchain::rpc::test::bdk_blockchain_tests::test_taproot_key_spend

Something is still off with weight calculations. Is this a problem with bdk_core or miniscript?


Update: Held up by bugs in miniscript. Await upgrade to miniscript 8.0.0 (#770).

@notmandatory
Copy link
Member

@evanlinjin is the PR ready to be revived now that rust-miniscript 0.8.0 (and 0.9.0) is released? I noticed it as a dependency to close LLFourn/bdk_core_staging#36.

@evanlinjin
Copy link
Member Author

I will close this as @LLFourn has reworked the bdk chain's coin selector so this is no longer relevant.

@evanlinjin evanlinjin closed this Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants