lightninglabs / chantools

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

chantools forceclose --channeldb crashes on taproot channels: malformed signature: no header magic #108

Open starius opened 9 months ago

starius commented 9 months ago

Problem

I stopped LND and ran the following command:

$ chantools --testnet forceclose --channeldb ./.lnd/data/graph/testnet/channel.db --fromchanneldb ./.lnd/data/graph/testnet/channel.db
Input your 24-word mnemonic separated by spaces: ***
Input your cipher seed passphrase (press enter if your seed doesn't have a passphrase):

If the node does not have a taproot channel, this command completes successfully:

2023-12-31 18:32:20.935 [INF] CHAN: Writing result to results/forceclose-2023-12-31-18-32-20.json

After I opened a taproot channel, it started crashing with the following error:

Error: malformed signature: no header magic
Usage:
  chantools forceclose [flags]
...

I verified this observation on two nodes (testnet and signet).

Analysis

I think, that the root cause is in the function LightningChannel.CreateSignDesc which is not aware of taproot channels.

lnd's function createSignDesc has taproot aware implementation.

In https://github.com/lightninglabs/chantools/pull/95 I'm adding the code building SignDescriptor from a channel backup. I think most of that code can be factored into a generic function, which can be used by LightningChannel.CreateSignDesc as well. Maybe even chantools can use a common function from LND to avoid diversions in the future.