lightninglabs / chantools

A loose collection of tools all somehow related to lnd and Lightning Network channels.
MIT License
224 stars 34 forks source link

invalid memory address or nil pointer dereference #77

Closed hashharvest closed 1 year ago

hashharvest commented 1 year ago

My node crashed about a month ago due to a hard drive failure. I was able to backup the channels and my channel.db fortunately.

After all said and done, I had 10 channels, 8 of them closed and funded the on-chain. The other 2 have remained "closing" for the last month. Ran the following the chantools summary on my channel.db I was able to recover.

I ran the following: chantools --fromchanneldb ./results/compacted.db summary

Which generated a summary showing that 8 of the channels are closed and 2 are open with funds. Great. That's good to know.

Then I ran the following: chantools --fromsummary ./results/summary-2023-09-14-02-00-56.json rescueclosed --channeldb ./results/compacted.db

Which generated a rescueclosed-2023....json file. This file shows ALL the channels with their closing_tx -> txid EXCEPT the 2 open channels. They show the similar:

...
{
   "remote_pubkey": "0...3",
   "channel_point": "7...6:1",
   "funding_txid": "7...6",
   "funding_tx_index": 1,
   "capacity": 300000,
   "initiator": true,
   "local_balance": 253107,
   "remote_balance": 46893,
   "chan_exists_onchain": true,
   "has_potential_funds": true,
   "force_close": null
  },
 ...

Both channels that are still open show this. Not sure what I'm expected to see here. But it looks like it did not close them.

I then ran the following command: chantools triggerforceclose --peer 0...3 --channel_point 7...6:1

Get the following result (after entering 24-word mnemonic):

Attempting to connect to peer 0...3, dial timeout is 1m0s
2023-09-14 02:54:04.608 [DBG] CHDB: Populating in-memory channel graph, this might take a while...
2023-09-14 02:54:07.172 [DBG] CHDB: Finished populating in-memory channel graph (took 2.557730194s, num_node_features=19601, num_nodes=19308, num_channels=149954)
2023-09-14 02:54:07.172 [INF] CHDB: Checking for schema update: latest_version=29, db_version=29
2023-09-14 02:54:07.172 [INF] CHDB: Checking for optional update: prune_revocation_log=false, db_version=empty
2023-09-14 02:54:07.174 [DBG] PEER: Peer(0...3): Sending Init to 0...3@111.111.111.111:9735
2023-09-14 02:54:07.174 [DBG] PEER: Peer(0...3): Received Init from 0...3@111.111.111.111:9735
2023-09-14 02:54:07.175 [DBG] PEER: Peer(0...3): Loaded 1 active channels from database
2023-09-14 02:54:07.189 [INF] PEER: Peer(0...3): loading ChannelPoint(7....6:1)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c2a64]

goroutine 1 [running]:
github.com/lightningnetwork/lnd/channeldb.(*ChannelGraph).FetchChannelEdgesByOutpoint(0x0, 0x400001f1a8)
        github.com/lightningnetwork/lnd@v0.16.0-beta/channeldb/graph.go:3524 +0x54
github.com/lightningnetwork/lnd/peer.(*Brontide).loadActiveChannels(0x400001e700, {0x40013aa910, 0x1, 0x400b42c020?})
        github.com/lightningnetwork/lnd@v0.16.0-beta/peer/brontide.go:836 +0x838
github.com/lightningnetwork/lnd/peer.(*Brontide).Start(0x400001e700)
        github.com/lightningnetwork/lnd@v0.16.0-beta/peer/brontide.go:616 +0x520
github.com/lightninglabs/chantools/lnd.ConnectPeer(0x400026a400, 0x4000596000, 0x1a2c0a0, {0x1190140, 0x4000520010})
        github.com/lightninglabs/chantools/lnd/brontide.go:240 +0xa68
main.(*triggerForceCloseCommand).Execute(0x400026b1c0, 0xa0b9f0?, {0x400016bb60?, 0x400016bb38?, 0x0?})
        github.com/lightninglabs/chantools/cmd/chantools/triggerforceclose.go:113 +0x570
github.com/spf13/cobra.(*Command).execute(0x40003c5180, {0x400026b400, 0x4, 0x4})
        github.com/spf13/cobra@v1.1.3/command.go:852 +0x4dc
github.com/spf13/cobra.(*Command).ExecuteC(0x1a2d440)
        github.com/spf13/cobra@v1.1.3/command.go:960 +0x358
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.1.3/command.go:897
main.main()
        github.com/lightninglabs/chantools/cmd/chantools/root.go:124 +0x2d8

So couple things, is I'm trying to get the other side to trigger a force close, as they think the channel is still open it looks like. My node says it's trying to close it.

Anyone help with this and help recover funds?

guggero commented 1 year ago

First of all, did you attempt to recover the two channels using the standard recovery process before using chantools? That will attempt to connect to the peers and ask them to force close.

The triggerforceclose command is only for very specific versions of CLN and don't work for any other nodes.

hashharvest commented 1 year ago

Yes, I followed everything on that page. I have not done a Forced In-Place rescan however. I can try that and report back when it's completed.

hashharvest commented 1 year ago

Looks like after I ran forceclose from chantools again, it rebroadcast. Everything seems to be working. Thanks for the help.

guggero commented 1 year ago

Okay, thanks for the update, seem like I can close the issue then.