get10101 / 10101

10101 (Ten-Ten-One): Self-custodial derivative trading at your fingertips.
https://10101.finance
MIT License
128 stars 23 forks source link

Collaboratively closing the ln channel lost the apps funds #543

Closed holzeis closed 1 year ago

holzeis commented 1 year ago

After ending up in a stuck state on my 10101 app (mainnet) Build 1.0.12 (985) I initiated a collaborative channel close through the coordinator api.

curl -X DELETE http://localhost:8000/api/admin/channels/f0bc467b35a4b6a72d0107d3a03556af4cb2aba3780cc7398c26b9bc9d42fc80

Both sides reported a successful channel closure and the commit transaction has been published https://mempool.space/tx/b5b3efb670887bf0dfa30f708835e5c3555796231d392da28dfe5a82cd4bc574 and confirmed.

Logs from the app

| 2023-04-28 08:33:50.451 | LogLevel.DEBUG | lightning::ln::peer_handler: Handling SendClosingSigned event in peer_handler for node 022ae8dbec1caa4dac93f07f2ebf5ad7a5dd08d375b79f11095e81b065c2155156 for channel f0bc467b35a4b6a72d0107d3a03556af4cb2aba3780cc7398c26b9bc9d42fc80  
| 2023-04-28 08:33:50.658 | LogLevel.INFO | lightning::ln::channelmanager: Broadcasting closing tx with txid b5b3efb670887bf0dfa30f708835e5c3555796231d392da28dfe5a82cd4bc574  
| 2023-04-28 08:33:50.705 | LogLevel.INFO | Received event event: ChannelClosed { channel_id: [240, 188, 70, 123, 53, 164, 182, 167, 45, 1, 7, 211, 160, 53, 86, 175, 76, 178, 171, 163, 120, 12, 199, 57, 140, 38, 185, 188, 157, 66, 252, 128], user_channel_id: 0, reason: CooperativeClosure } 
| 2023-04-28 08:33:50.706 | LogLevel.INFO | 
Channel closed channel: f0bc467b35a4b6a72d0107d3a03556af4cb2aba3780cc7398c26b9bc9d42fc80,reason: CooperativeClosure 
| 2023-04-28 08:33:50.707 | LogLevel.DEBUG | Successfully handled event event: "ChannelClosed { channel_id: [240, 188, 70, 123, 53, 164, 182, 167, 45, 1, 7, 211, 160, 53, 86, 175, 76, 178, 171, 163, 120, 12, 199, 57, 140, 38, 185, 188, 157, 66, 252, 128], user_channel_id: 0, reason: CooperativeClosure }"

The funds returned to the the coordinator but not to my app. I also recovered the seed in BlueWallet and Green, but neither wallet shows me a balance.

The funds will not end in the user's wallet because they are locked in a p2wsh script which is meant to be spent manually. LDK fires the event Event::SpendableOutputs for us when it's ready to be spent.

holzeis commented 1 year ago

This issue is reproducible with the following steps

  1. Fund wallet
  2. Open a position
  3. Close channel collaboratively (on the settings screen)

Expected Result

Funds appear in my on-chain wallet

Observed Result

Funds are gone

This might be related to #498

bonomat commented 1 year ago

Try this project to recover the funds. It currently only accepts a seed file but it shouldn't take much to change it to accept a seed phrase: https://github.com/get10101/10101-recovery

bonomat commented 1 year ago

The critical part of this ticket is that the money ends in a p2wsh script and not in your wallet, hence, you cannot recover your funds in a a different wallet. You will need to know how to spend said script. The corresponding event which is being fired by LDK is Event::SpendableOutputs.

@luckysori : afaik you looked into how we can change that the money should end up in the user's wallet directly instead of in an p2wsh script?

holzeis commented 1 year ago

This issue is reproducible with the following steps

1. Fund wallet

2. Open a position

3. Close channel collaboratively (on the settings screen)

Expected Result

Funds appear in my on-chain wallet

Observed Result

Funds are gone

This might be related to #498

Collaboratively closing the ln channel with an open dlc channel was incorrect in itself. ln does not know about the dlc channel and hence is not able to broadcast the required split and glue transactions correctly ending up in loosing the channels funds.

The correct way this should be done collaboratively is to first close the dlc channel and afterwards close the ln channel. I am going to setup a test for that to see if that is working.

We might want to close the ticket then. However, what should work is to force close the ln channel regardless if a dlc channel exists or not. This is because it might be triggered by the other side, or automatically through ldk. But given the history on this ticket, I guess its better to open a separate ticket for that then.

holzeis commented 1 year ago

Removing the critical flag as the position needs to be collaboratively closed before closing the channel.