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

Simplify change policy #14

Merged
merged 2 commits into from
Dec 21, 2023
Merged

Conversation

LLFourn
Copy link
Collaborator

@LLFourn LLFourn commented Dec 21, 2023

This PR makes a simplifying assumption: The decision about whether to add change or not can be reduced to a check whether the excess is over a certain threshold. The change policy is simply how to compute that threshold.

I originally didn't do this because I thought change policies could be more complicated than that -- and they probably could be! But @evanlinjin pointed out that you can easily run the coin selector multiple times with different policies and change output structures if you wanted to compare and contrast different approaches (rather than trying to embed this logic into the change policy itself).

I realized it is actually quite difficult to implement the metrics correctly without knowing the threshold that will case change to be added (and the weight of that change) up front. Knowing this we should be able to make the implementations much simpler.

It is now just a single threshold which if surpassed implies a change
outupt should be added.

Fix README examples as well
@LLFourn LLFourn force-pushed the simplify-change-policy branch 5 times, most recently from 474d832 to 8c85236 Compare December 21, 2023 02:16
@LLFourn LLFourn force-pushed the simplify-change-policy branch from 8c85236 to dac0641 Compare December 21, 2023 02:31
Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Concept ACK dac0641

@LLFourn LLFourn merged commit f147ebc into bitcoindevkit:master Dec 21, 2023
5 checks passed
@LLFourn LLFourn deleted the simplify-change-policy branch December 21, 2023 02:37
value: 0,
},
);
if excess > change_policy.min_value as i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this should have been >= instead of > . The min_value_and_waste change policy was previously returning change for excess equal to the min value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it should be >= indeed.

darosior added a commit to wizardsardine/liana that referenced this pull request Jan 13, 2024
5a15c74 commands: return warnings from spend creation (jp1ac4)
da474ad spend: add warning when adding change to fee (jp1ac4)
8d84f0d spend: return max possible change from coin selection (jp1ac4)
e4d8330 spend: use debug log level in coin selection (jp1ac4)

Pull request description:

  This is a first step towards #811. The GUI will be updated in a follow-up PR.

  It adds a warning if there is any change/excess available that has been added to the fee, building on the assumption from bitcoindevkit/coin-select#14 that the decision whether to include change depends on whether the excess is over a threshold. The function `select_coins_for_spend()` now returns this threshold so that the caller can check if the possible change amount is above it.

  I've used an `enum` for the different warnings, but could use strings directly.

  If the approach looks fine, I'll add some tests.

ACKs for top commit:
  darosior:
    ACK 5a15c74

Tree-SHA512: 12716b1e299d3154c520667c66aeb7a176a770f4a1d53125a8334d7c5a7e7bb2ce1dcb795ad5998bffc1303d9cb34c651cf8d3ef3dee8210572d75069012bddd
@evanlinjin evanlinjin mentioned this pull request Jan 15, 2024
evanlinjin added a commit that referenced this pull request Jan 15, 2024
f991504 chore: bump to v0.2 (志宇)

Pull request description:

  # Changelog

  * Fix lowest fee metric (#13)
  * Simplify change policy (#14)

Top commit has no ACKs.

Tree-SHA512: a92bbc99ef5c1ab06fdb019916e3c88970ce989a7dd36471d486f4601b2ecc439a0787432994e9b14f0f8fbdfb031c3e5db9c5723068245db1b5f981cfc9f1e9
darosior added a commit to wizardsardine/liana that referenced this pull request Apr 15, 2024
43ecd94 spend: change parameter type for rbf (jp1ac4)
6376909 commands: remove rbf rule 4 logic (jp1ac4)
936d7e9 spend: bump bdk_coin_select to 0.3.0 (jp1ac4)

Pull request description:

  This is to resolve #923.

  The `score` method of the `LowestFee` metric has been fixed upstream and so our temporary partial fix from #867 is no longer required.

  The `min_fee` parameter of `select_coins_for_spend`, if positive, now ensures that RBF rule 4 is satisfied. Accordingly, it has been renamed to `replaced_fee` and made an `Option`. We could potentially have used the `SpendTxFees` enum as a parameter directly instead of `feerate_vb` and `replaced_fee`, but `feerate_vb` is currently `f32` rather than `u64` and so I kept them as separate parameters.

  Thanks to how the `replaced_fee` parameter works, the fee iteration approach used in `rbf_psbt` to ensure the replacement satisfies [RBF rule 4](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md#current-replace-by-fee-policy) is no longer required.

  `base_weight` is no longer stored in `CoinSelector` and instead the output weights are stored in `Target`. This means that the `output_weight` of `DrainWeights` no longer needs to take into account a potential change in output count varint as this is now handled by bdk_coin_select.

  The min value for change no longer includes the threshold itself and so we have to subtract 1 from our change policy's min value (see bitcoindevkit/coin-select#14 (comment)). We already have a [test](https://github.com/wizardsardine/liana/blob/master/src/commands/mod.rs#L1653-#L1654) that fails without this subtraction as it expects a change output of 5000 sats.

ACKs for top commit:
  darosior:
    ACK 43ecd94

Tree-SHA512: a064bafef13abefcb8c4b640cfc4017eb288c62891a8b486add33c1499e7061bf262d6aadabbdd4c191ed9b81e3931b382c8c8445e6bb9c1b052380caf14b3f9
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.

3 participants