Skip to content

Conversation

Camillarhi
Copy link
Contributor

@Camillarhi Camillarhi commented Aug 23, 2025

This PR enhances on-chain transaction management:

  1. Rebroadcast/bumping of on-chain wallet transactions

  2. Handle RBF'd Pending payments

Changes

  • Added background job for rebroadcasting unconfirmed onchain transactions with max attempt limit
  • Implemented RBF (Replace-by-Fee) functionality allowing users to bump fees on outbound unconfirmed transactions

Related Issues

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 23, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot ldk-reviews-bot requested a review from tnull August 23, 2025 16:56
@Camillarhi Camillarhi force-pushed the feat/tx-rebroadcast-fee-bumping branch from 39922cc to c228760 Compare August 23, 2025 16:58
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 4th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Just took an initial look and added a few high-level comments. I have yet to review any of the actual RBF logic changes.

However, as noted elsewhere, please don't make all the changes as single huge commit, but rather break the PR up in logical commits that all have descriptive commit messages outlining what the change is, why it's necessary, etc. For guidance you can have a look at https://cbea.ms/git-commit/

It would also make sense to not include the changes for #452 in this initial PR directly, but do it in a separate PR to keep the diff more manageable and reviewable.

};

dictionary AnchorChannelsConfig {
sequence<PublicKey> trusted_peers_no_reserve;
u64 per_channel_reserve_sats;
};

dictionary RebroadcastPolicy {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly not sure if we should expose this to the user at all, or if we should simply implement sane defaults, mod possibly allowing to disable auto-rebroadcast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I've set auto-rebroadcast to be enabled by default for reliability, but added a config option to disable it for users who need more control, while using the set sane default values.

@Camillarhi Camillarhi force-pushed the feat/tx-rebroadcast-fee-bumping branch 3 times, most recently from a52b1e5 to 3523954 Compare September 3, 2025 22:44
@Camillarhi Camillarhi requested a review from tnull September 3, 2025 22:50
@Camillarhi Camillarhi force-pushed the feat/tx-rebroadcast-fee-bumping branch from 3523954 to 609d0a0 Compare September 3, 2025 22:53
@moisesPompilio
Copy link
Contributor

Thanks for the PR.
It might be better to split this into at least two commits, one for rebroadcasting and one for RBF, to improve organization and reviewability.

Comment on lines +974 to +976
self.payment_store.remove(&payment_id)?;

self.payment_store.insert_or_update(payment_details)?;
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 not fully sure about this flow: since with RBF we can’t guarantee which transaction will eventually confirm (usually the last one, but not always), removing the previous payment here might cause issues. What happens if the earlier tx ends up confirming instead of the latest — would the wallet balance be deducted while the store still shows the payment as pending? If so, could this lead to a confusing UX for the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent catch. You're right to be concerned about the potential for state inconsistency.

However, the update_payment_store method acts as a reconciler that syncs the payment store with the actual state of the BDK wallet. Since the payment store is designed to be a reflection of the wallet's state.

Introduces a `RebroadcastPolicy` to manage the automatic rebroadcasting
of unconfirmed transactions with exponential backoff. This prevents
excessive network spam while systematically retrying stuck transactions.

The feature is enabled by default but can be disabled via the builder:
`builder.set_auto_rebroadcast_unconfirmed(false)`.

Configuration options:
- min_rebroadcast_interval: Base delay between attempts (seconds)
- max_broadcast_attempts: Total attempts before abandonment
- backoff_factor: Multiplier for exponential delay increase

Sensible defaults are provided (300s, 24 attempts, 1.5x backoff).
Add `Replace-by-Fee` functionality to allow users to increase fees on
pending outbound transactions, improving confirmation likelihood during
network congestion.

- Uses BDK's `build_fee_bump` for transaction replacement
- Validates transaction eligibility: must be outbound and unconfirmed
- Implements fee rate estimation with safety limits
- Maintains payment history consistency across wallet updates
- Includes integration tests for various RBF scenarios
@Camillarhi Camillarhi force-pushed the feat/tx-rebroadcast-fee-bumping branch from 609d0a0 to 8b7cf78 Compare September 5, 2025 13:17
@Camillarhi
Copy link
Contributor Author

Thanks for the PR. It might be better to split this into at least two commits, one for rebroadcasting and one for RBF, to improve organization and reviewability.

Thanks for the review! I've split the PR into two separate commits as suggested

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

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.

Rebroadcast/bumping of on-chain wallet transactions
4 participants