Skip to content

fix: move RGB channel balance only when an HTLC settles - #52

Open
orbitalturtle wants to merge 1 commit into
RGB-Tools:rgbfrom
orbitalturtle:fix/rgb-settled-balance
Open

orbitalturtle wants to merge 1 commit into
RGB-Tools:rgbfrom
orbitalturtle:fix/rgb-settled-balance

Conversation

@orbitalturtle

@orbitalturtle orbitalturtle commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The pending RGB amounts moved when an HTLC was committed and never moved back when it failed, so a failed RGB HTLC handed its assets to the counterparty at close, as reproduced in the test in #[TBD]. This PR proposes a potential fix: track the settled RGB balance next to value_to_self_msat and color commitments from it, like LDK does for BTC.

Why settle-time and not reverting on failure

We considered two fixes: keep moving the balance at commit time and undo it when the HTLC fails, or move the balance only once the HTLC settles. We went with the second because:

  • There is no reason for moving the balance at commit time documented in the code. If there's a reason we're missing, happy to readjust the PR.
  • It matches LDK's BTC accounting. value_to_self_msat excludes pending HTLCs and only changes in the revoke_and_ack branches where an HTLC is irrevocably fulfilled (inbound LocalRemoved(Fulfill) and outbound AwaitingRemovedRemoteRevoke(Success)). An in-flight HTLC's value sits in its own HTLC output, not in either party's balance. RGB amounts now follow the same rule, so the RGB and BTC sides of the channel can't drift apart.
  • There is one success path but many failure paths. An HTLC can fail through update_fail_htlc, update_fail_malformed_htlc, timeouts, failures from the holding cell or after a reconnect, and on-chain resolution. Undoing the move would need correct handling on every one of these paths, and missing one brings the bug back. Moving the balance on settle touches a single place.

The pending RGB amounts moved when an HTLC was committed and never moved
back when it failed, so a failed RGB HTLC handed its assets to the
counterparty at close. Track the settled RGB balance next to
value_to_self_msat and color commitments from it, like LDK does for BTC.

Co-Authored-By: Claude
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.

1 participant