ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.84k stars 901 forks source link

crash with --network=liquid #6955

Closed grubles closed 9 months ago

grubles commented 10 months ago

CLN v23.11-76-g56d42ea

When running CLN with --network=liquid it will crash soon after starting:

2023-12-19T18:30:19.946Z DEBUG   lightningd: Adding block 2643648: 105f1a22ffaaca7368f1b087f8639dc54968bbbca03919f77c960a1748f9a1f1
2023-12-19T18:30:19.967Z DEBUG   lightningd: Adding block 2643649: b0a98888e2daeb12ee638cff9bf7d5aef52f40faaee3d9b561546819673c9ba7
2023-12-19T18:30:20.029Z DEBUG   lightningd: Adding block 2643650: e52f425aa0c5f8b14a311ac4d955a1e0fda58aeef040a4992bad71856efe1405
2023-12-19T18:30:20.147Z **BROKEN** lightningd: FATAL SIGNAL 6 (version v23.11-76-g56d42ea)
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: common/daemon.c:38 (send_backtrace) 0x100c0827
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: common/daemon.c:75 (crashdump) 0x100c089f
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac7e0463
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac0b410c
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac05070b
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac03073b
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac044797
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac044843
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: bitcoin/psbt.c:63 (new_psbt) 0x100e5073
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: bitcoin/tx.c:665 (pull_bitcoin_tx) 0x100ee373
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: bitcoin/block.c:213 (bitcoin_block_from_hex) 0x100e3ddb
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/bitcoind.c:486 (getrawblockbyheight_callback) 0x100140d3
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:660 (plugin_response_handle) 0x10078bc3
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:772 (plugin_read_json_one) 0x1007e1a3
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:823 (plugin_read_json) 0x1007e4eb
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:59 (next_plan) 0x101f3107
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:407 (do_plan) 0x101f39e3
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:417 (io_ready) 0x101f3aeb
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: ccan/ccan/io/poll.c:453 (io_loop) 0x101f65bf
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/io_loop_with_timers.c:22 (io_loop_with_timers) 0x100404bb
2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/lightningd.c:1334 (main) 0x100483db
2023-12-19T18:30:20.148Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac030f2b
2023-12-19T18:30:20.148Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7fffac03116b
2023-12-19T18:30:20.148Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0xffffffffffffffff
vincenzopalazzo commented 10 months ago

From 2023-12-19T18:30:20.147Z **BROKEN** lightningd: backtrace: lightningd/bitcoind.c:486 (getrawblockbyheight_callback) 0x100140d3

looks like a problem with the rpc, I will look into it, thanks

vincenzopalazzo commented 10 months ago

Ok I reproduced it

2023-12-30T01:30:18.682Z INFO    plugin-folgore_plugin: cln request {\"height\":2659904}
2023-12-30T01:30:19.704Z **BROKEN** lightningd: FATAL SIGNAL 6 (version v23.11-79-g9d63166-modded)
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: common/daemon.c:38 (send_backtrace) 0x55787275ce30
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: common/daemon.c:75 (crashdump) 0x55787275ce70
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450eea670f
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450eef683c
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450eea6667
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450ee8e4b7
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450ee8e3db
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450ee9ed25
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: bitcoin/psbt.c:63 (new_psbt) 0x557872773b98
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: bitcoin/tx.c:665 (pull_bitcoin_tx) 0x557872779dbb
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: bitcoin/block.c:213 (bitcoin_block_from_hex) 0x55787277321f
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/bitcoind.c:486 (getrawblockbyheight_callback) 0x5578726e4bf5
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:660 (plugin_response_handle) 0x55787272ce49
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:772 (plugin_read_json_one) 0x557872730356
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/plugin.c:823 (plugin_read_json) 0x5578727305ef
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:59 (next_plan) 0x5578728ca8fa
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:407 (do_plan) 0x5578728cad81
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:417 (io_ready) 0x5578728cae1a
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: ccan/ccan/io/poll.c:453 (io_loop) 0x5578728cc67a
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/io_loop_with_timers.c:22 (io_loop_with_timers) 0x55787270544f
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: lightningd/lightningd.c:1334 (main) 0x55787270a595
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450ee8fccf
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x7f450ee8fd89
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0x5578726e2cc4
2023-12-30T01:30:19.704Z **BROKEN** lightningd: backtrace: (null):0 ((null)) 0xffffffffffffffff
vincenzopalazzo commented 10 months ago

Ok looks like this crash is not from the bcli plugin but from the libwally

lightningd: bitcoin/psbt.c:65: struct wally_psbt *new_psbt(const tal_t *, const struct wally_tx *): Assertion `wally_err == WALLY_OK' failed.
lightningd: FATAL SIGNAL 6 (version v23.11-84-ga59dbbd-modded)
0x19f6a0 send_backtrace
    /home/vincent/github/work/lightning/common/daemon.c:33
0x19fb29 crashdump
    /home/vincent/github/work/lightning/common/daemon.c:75
0x4ba170f ???
    ???:0
0x4bf183c ???
    ???:0
0x4ba1667 ???
    ???:0
0x4b894b7 ???
    ???:0
0x4b893db ???
    ???:0
0x4b99d25 ???
    ???:0
0x1bd052 new_psbt
    /home/vincent/github/work/lightning/bitcoin/psbt.c:65
0x1c6a45 pull_bitcoin_tx
    /home/vincent/github/work/lightning/bitcoin/tx.c:665
0x1bbcd0 bitcoin_block_from_hex
    /home/vincent/github/work/lightning/bitcoin/block.c:213
0x123f90 getrawblockbyheight_callback
    /home/vincent/github/work/lightning/lightningd/bitcoind.c:486
0x16ece7 plugin_response_handle

Unfortunately, the error is not useful at all, from my analysis the crash happens on psbt_input_from_tx_input when the psbt_input_from_tx_input_pegin is called.

The crash happens because the psbt_input_from_tx_input_pegin is not called, but the really strange thing is that cln should not use input_pegin. I am not sure about the input_pegin btw


This is a patch that avoids the crash, but I do not know if this is the correct thing to do because I am not comfortable with the wtx->inputs[i].features &= ~WALLY_TX_IS_PEGIN;

diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c
index 42a89bfb8..8ba7711d4 100644
--- a/bitcoin/psbt.c
+++ b/bitcoin/psbt.c
@@ -49,6 +49,7 @@ struct wally_psbt *clone_psbt(const tal_t *ctx, const struct wally_psbt *psbt)
 struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx)
 {
        struct wally_psbt *psbt;
+       size_t is_pset;
        int wally_err;

        psbt = create_psbt(ctx, wtx->num_inputs, wtx->num_outputs, wtx->locktime);
@@ -58,7 +59,14 @@ struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx)
        /* locktime and modifiable flags are set in create_psbt */
        wally_psbt_set_tx_version(psbt, wtx->version);

+       // FIXME(vincenzopalazzo): catch the return error
+       wally_psbt_is_elements(psbt, &is_pset);
+
        for (size_t i = 0; i < wtx->num_inputs; i++) {
+               /* FIXME: libwally is not supporting pegin, so we skip because in cln
+                * this is not using the pegin (maybe :P) */
+               if (is_pset)
+                       wtx->inputs[i].features &= ~WALLY_TX_IS_PEGIN;
                wally_err = wally_psbt_add_tx_input_at(psbt, i, 0, &wtx->inputs[i]);
                assert(wally_err == WALLY_OK);
jgriffiths commented 9 months ago

https://github.com/ElementsProject/lightning/pull/6983 should fix this issue assuming it doesn't cause any others (e.g. if plugins expect PSBTs to be present for block txs for some reason).

However based on my previous spelunking of the cln code I strongly recommend not putting real funds into Elements channels at this stage. I believe more work is needed before it works out of the box for Elements/Liquid.