Skip to content

Handle internal transfers completed after shutdown#36

Open
TheBlueMatt-macbook wants to merge 2 commits intolightningdevkit:masterfrom
TheBlueMatt-macbook:2025-12-background-rebalance
Open

Handle internal transfers completed after shutdown#36
TheBlueMatt-macbook wants to merge 2 commits intolightningdevkit:masterfrom
TheBlueMatt-macbook:2025-12-background-rebalance

Conversation

@TheBlueMatt-macbook
Copy link
Collaborator

Currently we only process setting TxMetadata for internal transfers if they complete in-line while the app is open and running the rebalance logic. If, however, an internal transfer is initiated but then does not complete the metadata is lost and instead our transaction list includes a LN payment received and no information about the trusted transaction at all.

Instead, here, we track enough information in
TxType::PendingRebalance to match the trusted transfer with an LN transaction and then do so in list_transactions, updating metadata as appropriate if we find a match.

We handle upgrades from previous versions of Orange gracefully, though I'm not sure if we really need to do that yet.

@benthecarman
Copy link
Collaborator

If, however, an internal transfer is initiated but then does not complete the metadata is lost and instead our transaction list includes a LN payment received and no information about the trusted transaction at all.

I am not sure this is true. We set the metadata based on the events which we only mark as handled if we successfully set everything.

I was hoping to avoid having list_transactions modify the state and only have the metadata be updated by events. Seems like this might be a race condition being hit possibly?

@TheBlueMatt-macbook
Copy link
Collaborator Author

The problem is that graduated-rebalancer generates the RebalancerEvent::RebalanceSuccessful inline in do_rebalance_if_needed. In my case I saw an issue where calling await_payment_success on the spark wallet didn't return at all for some reason (I still haven't had a chance to debug that), but if we crash after the trusted payment send has been initiated but before the LN wallet has received it, on restart we'll just receive the payment to the LN wallet and treat it like any other payment (though the trusted wallet transaction will still be hidden as we have metadata for it to mark it as pending-rebalance).

@TheBlueMatt-macbook
Copy link
Collaborator Author

The maybe-more-robust version of this would be to hand graduated-rebalancer LN-sourced events for it to process later. I'm not sure the extra work to refactor the whole thing to do that is worth it, but LMK.

Currently we only process setting `TxMetadata` for internal
transfers if they complete in-line while the app is open and
running the rebalance logic. If, however, an internal transfer is
initiated but then does not complete the metadata is lost and
instead our transaction list includes a LN payment received and no
information about the trusted transaction at all.

Instead, here, we track enough information in
`TxType::PendingRebalance` to match the trusted transfer with an
LN transaction and then do so in `list_transactions`, updating
metadata as appropriate if we find a match.

We handle upgrades from previous versions of Orange gracefully,
though I'm not sure if we really need to do that yet.
@TheBlueMatt-macbook TheBlueMatt-macbook force-pushed the 2025-12-background-rebalance branch from bb7ca31 to 2d3f899 Compare December 29, 2025 17:00
@TheBlueMatt-macbook
Copy link
Collaborator Author

Rebased.

@TheBlueMatt-macbook TheBlueMatt-macbook force-pushed the 2025-12-background-rebalance branch from 2d3f899 to 01d1f3d Compare December 29, 2025 17:22
@benthecarman
Copy link
Collaborator

The maybe-more-robust version of this would be to hand graduated-rebalancer LN-sourced events for it to process later. I'm not sure the extra work to refactor the whole thing to do that is worth it, but LMK.

Did #46 which is kinda like this. Should be a lot safer across restarts and failures

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.

2 participants