feat(selector): allow multiple change sources with ChangeDescriptor#18
Merged
ValuedMammal merged 1 commit intobitcoindevkit:masterfrom Oct 6, 2025
Merged
Conversation
c589508 to
bcb018f
Compare
Previously, the `change_descriptor` field only accepted a definite descriptor to derive the change output script pubkey. This worked for most cases but failed for scenarios - such as silent payments - where a definite descriptor is not available. Now `change_descriptor` is `change_script` and can take a ScriptSource, which can be a descriptor or the script itself. Also, `change_weights` field is added as a field of SelectorParams, to externalize the calculus of the satisfaction weight from the API. This allowed the remove of the `to_cs_change_weigths` method. `From<(ScriptSource, Amount)>` for Output is added for conveniency.
bcb018f to
aadeca5
Compare
Member
|
ApproachNACK There is a problem with the current approach:
The caller is responsible for keeping these in sync, but nothing enforces that. If |
ValuedMammal
added a commit
that referenced
this pull request
Apr 11, 2026
… SelectorParams 8189b03 refactor!: inline ChangePolicy fields into SelectorParams (志宇) ffd1211 feat: add constructor methods for ChangeScript and ChangePolicy (志宇) b9e7b42 refactor!: eliminate redundant satisfaction weight in SelectorParams (志宇) Pull request description: Fixes #40 Fixes #42 ## Summary This PR fixes two issues with `SelectorParams`: **1. Redundant satisfaction weight (invalid representation)** `SelectorParams` previously had two independent fields that could both specify the change output's satisfaction weight: - `change_script: ScriptSource` — when this is the `Descriptor` variant, the satisfaction weight is derivable from the descriptor via `max_weight_to_satisfy`. - `change_policy: ChangePolicy` — also encodes the satisfaction weight (the spend cost of the change output). Nothing enforced that these agreed with each other, so callers could silently provide inconsistent values. Fixed by introducing **`ChangeScript`**, which bundles a raw script with an optional `satisfaction_weight`, or holds a `DefiniteDescriptor` from which it is derived automatically. `DrainWeights` is now computed internally from `ChangeScript` — there is a single source of truth. `ChangeScript::Descriptor` also accepts optional `satisfaction_assets` — when provided, the satisfaction weight is computed via `Plan` for a tighter estimate (useful for multisig/complex descriptors). Otherwise it falls back to `max_weight_to_satisfy`. The raw `bdk_coin_select::ChangePolicy` is also replaced with a **`ChangePolicy` enum** (`NoDust`, `NoDustLeastWaste`) that is converted to the `bdk_coin_select` type internally. This is `Debug + Clone + PartialEq + Eq`. Both `ChangeScript` and `ChangePolicy` have constructor methods to reduce boilerplate: - `ChangeScript::from_descriptor(desc)`, `from_descriptor_with_assets(desc, assets)`, `from_script(script, weight)` - `ChangePolicy::no_dust()`, `no_dust_least_waste(rate)`, with a builder-style `.min_value(amt)` **2. Hacky `AbsoluteFee` implementation** `FeeStrategy::AbsoluteFee` was implemented by smuggling the fee into `value_sum` and setting the feerate to zero. This meant the coin selector had no awareness of the fee, which interacted poorly with RBF logic (the zero feerate bypasses the original tx's feerate floor). Removed in favor of a direct `target_feerate: FeeRate` field. ### Design rationale The satisfaction weight is a physical property of the script — it describes how much it costs to spend a particular output. It is not a policy choice. When `change_script` is a descriptor, the satisfaction weight is literally derived from it. The fact that it *affects* coin selection doesn't make it *part of* the change policy, any more than the dust threshold is (and dust is already derived from the script). For the raw script case (e.g. silent payments), the satisfaction weight can't be derived and must be provided externally — but it's still a property of the script, not a policy decision. Bundling it into `ChangeScript::Script` makes this explicit. ## Context * #18 (comment) * #32 (comment) ACKs for top commit: aagbotemi: ACK 8189b03 ValuedMammal: ACK 8189b03 Tree-SHA512: c3bd9af598ec55c60ab04656d7907ec3882bd50bbd0783add94057bd2603bc1d0cbe134a3a2d601988e73c57d4c83c91538060e4091e3a150005489c293d9b21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Previously, the
change_descriptorfield only accepted a definite descriptor to derive the change output script pubkey. This worked for most cases but failed for scenarios - such as silent payments - where a definite descriptor is not yet available.To address this, introduce the
ChangeDescriptorenum, which supports:This makes change output generation flexible enough to handle both standard and exceptional workflows.
Fixes #17
All Submissions:
cargo +nigthly fmtbefore committingNew Features: