Integrate package context into fee and weight calculations; add absolute fee target#38
Draft
evanlinjin wants to merge 3 commits intobitcoindevkit:masterfrom
Draft
Integrate package context into fee and weight calculations; add absolute fee target#38evanlinjin wants to merge 3 commits intobitcoindevkit:masterfrom
evanlinjin wants to merge 3 commits intobitcoindevkit:masterfrom
Conversation
When a Package is set via with_package(), all fee and weight calculations now automatically include parent transaction context: - weight() returns child_weight + parent_weight - fee() returns child_fee + parent_fee - implied_feerate() returns package feerate New methods for when child-only values are needed: - weight_without_package() - fee_without_package() - package() accessor RBF calculations (replacement_excess) use child weight only since Bitcoin's RBF rule 4 applies to the replacing transaction, not the package. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6b6a402 to
ee587da
Compare
Tests cover: - weight() includes parent_weight when package is set - weight_without_package() returns child weight only - fee() includes parent_fee when package is set - fee_without_package() returns child fee only - implied_feerate() returns package feerate - package() accessor - with_package() auto-selects link indices - No package behaves normally (backwards compatible) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
aagbotemi
reviewed
Feb 16, 2026
Contributor
aagbotemi
left a comment
There was a problem hiding this comment.
The approach of adding Package to CoinSelector is good one and works well for the UTXO selection for CPFP use case.
Member
Author
|
I also want to add an absolute fee target. Payjoin (BIP 78): The payjoin proposal MUST NOT decrease the absolute fee of the original transaction. Some users may want to select their fee based on an absolute value (not sure why, but some wallets provide this feature). |
Add a `TargetFee::absolute` field that acts as a minimum absolute fee floor, checked independently alongside the existing feerate and replacement constraints. This supports use cases like Payjoin (BIP 78), where the receiver must not decrease the original transaction's absolute fee, and application-level policy minimums. Changes: - Add `absolute: u64` field to `TargetFee` - Add `CoinSelector::absolute_excess()` method - Integrate absolute excess into `CoinSelector::excess()` via `.min()` - Account for absolute fee in `CoinSelector::implied_fee()` - Handle absolute constraint in `LowestFee::bound()` for correct branch-and-bound behavior
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.
Package context for CPFP
When a
Packageis set viawith_package(), all fee and weight calculations now automatically include parent transaction context:weight()returnschild_weight + parent_weightfee()returnschild_fee + parent_feeimplied_feerate()returns package feerateNew methods for when child-only values are needed:
weight_without_package()fee_without_package()package()accessorRBF calculations (
replacement_excess) use child weight only since Bitcoin's RBF rule 4 applies to the replacing transaction, not the package.Absolute fee target
Adds a
TargetFee::absolutefield that acts as a minimum absolute fee floor, checked independently alongside the existing feerate and replacement constraints.Use cases:
bdk_wallet'sTxBuilder::fee_absolute()API where users set a fee floor regardless of feerate.Changes:
TargetFee::absolute: u64— minimum absolute fee the transaction must payCoinSelector::absolute_excess()— how much the selection overshoots the absolute fee requirementabsolute_excessintegrated intoexcess()via.min()so the most binding constraint winsimplied_fee()accounts forabsolutevia.max()LowestFee::bound()handles the absolute constraint for correct branch-and-bound behaviorNote: absolute fee is complementary to package context, not a replacement. Package context changes how the feerate constraint itself scales with child weight (the parent's fee/weight are inside the feerate calculation). An absolute fee floor is an independent constraint for cases where a fixed sat minimum comes from an external source.