Blockstream / greenlight

Build apps using self-custodial lightning nodes in the cloud
https://blockstream.github.io/greenlight/getting-started/
MIT License
106 stars 28 forks source link

Relai: Close channel output is not shown in onchain wallet #438

Closed roeierez closed 2 months ago

roeierez commented 2 months ago

relai issue: https://github.com/breez/breez-sdk-relai/issues/43 Node ID: 02e5f238372e62540a421b9777f6efd9ea7ae78edb299a0dac74376ce27c5f6e49

The channel was closed: https://blockstream.info/tx/463972904772472b38fa1cc907e5143a5af1a008cb373179c22f4d824d72e11f

The user node has swept its two outputs:

  1. amount: 72000 sats
  2. amount: 302744 sats

The user should see now 231722 in the onchain balance which seems missing the 72k sats output that was swept.

cdecker commented 2 months ago

I was able to verify that the wallet has exactly two UTXOs in the DB:

  1. Spent output for 272893sat, apparently used to sweep the 72ksat output at height 841340
  2. One unspent output for 231722sat representing the change from the sweep transaction

So it really looks like we're missing a sweep of an HTLC, being added to the internal wallet. I'm still unsure whether the HTLC is still locked, as this looks like a second stage transaction used to fan out the HTLCs from the commitment transaction, and it using the anchor spends to materialize the HTLC output on-chain. I'll look into the logs and see what I can find.

cdecker commented 2 months ago

The earliest logs I could access still had the HTLC and channel being tracked, so things are looking good that we should be able to figure out what happened here.

cdecker commented 2 months ago

The cause appears to be the outgoing HTLC hitting its deadline, thus causing the channel to close:

2024-04-08T21:13:56+02:00 {} stdout: DEBUG   0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-onchaind-chan#1: billboard perm: Tracking our own unilateral close
....`
2024-04-08T21:13:56+02:00 {} stdout: DEBUG   0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-onchaind-chan#1: Resolved FUNDING_TRANSACTION/FUNDING_OUTPUT by OUR_UNILATERAL (463972904772472b38fa1cc907e5143a5af1a008cb373179c22f4d824d72e11f)
...
2024-04-08T21:13:56+02:00 {} stdout: DEBUG   0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-onchaind-chan#1: Telling lightningd about OUR_HTLC_TIMEOUT_TX to resolve OUR_UNILATERAL/OUR_HTLC after block 835914 (-65 more blocks)
...
2024-04-08T21:13:56+02:00 {} stdout: UNUSUAL 0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-chan#1: We want to bump HTLC fee, but no funds!

Output 4 is the delayed return to us by the way:

2024-04-08T21:13:57+02:00 {} stdout: DEBUG   0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-onchaind-chan#1: Tracking output 463972904772472b38fa1cc907e5143a5af1a008cb373179c22f4d824d72e11f:4: OUR_UNILATERAL/DELAYED_OUTPUT_TO_US

And it looks like we have some sort of integer underrun:

2024-04-08T21:13:57+02:00 {} stdout: DEBUG   0264a62a4307d701c04a46994ce5f5323b1ca28c80c66b73c631dbcb0990d6e835-onchaind-chan#1: billboard: 6 outputs unresolved: in 4294967232 blocks will spend OUR_HTLC (463972904772472b38fa1cc907e5143a5af1a008cb373179c22f4d824d72e11f:2) using OUR_HTLC_TIMEOUT_TX

Interesting how that 65 blocks became UINT32_MAX - 2^6, that might be the real reason for this issue here.

cdecker commented 2 months ago

Closing and tracking the underlying issue in #439