ElementsProject / lightning

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

reserveinputs + signpsbt crashes #4285

Closed fiatjaf closed 1 year ago

fiatjaf commented 3 years ago

Issue and Steps to Reproduce

Commands:

~> ./cli/lightning-cli --network regtest reserveinputs -k psbt='cHNidP8BAHEBAAAAAZ+dQXWMU0UUQW5guh1gAqRk6qV1EfswIxDz/l6pI4BYAAAAAAD/////AuQGAAAAAAAAFgAUNiXEouqXR2CoFjaP0V3ncVlEdue0RKASAAAAABYAFKswhKbTAJ6fHwhnBttaS62vUkitAAAAAAAAAAA='
{
   "reservations": [
      {
         "txid": "588023a95efef3102330fb1175a5ea64a402601dba606e411445538c75419d9f",
         "vout": 0,
         "was_reserved": false,
         "reserved": true,
         "reserved_to_block": 1027
      }
   ]
}
~> ./cli/lightning-cli --network regtest signpsbt -k psbt='cHNidP8BAHEBAAAAAZ+dQXWMU0UUQW5guh1gAqRk6qV1EfswIxDz/l6pI4BYAAAAAAD/////AuQGAAAAAAAAFgAUNiXEouqXR2CoFjaP0V3ncVlEdue0RKASAAAAABYAFKswhKbTAJ6fHwhnBttaS62vUkitAAAAAAAAAAA='
lightning-cli: reading response: socket closed

Crash log:

+43.438693667 jsonrpc#36IO_IN: 7b20226a736f6e727063223a2022322e30222c20226d6574686f64223a20226e6f74696669636174696f6e73222c20226964223a20302c2022706172616d7322
+43.438712684 jsonrpc#36IO_IN: 3a207b2022656e61626c65223a2074727565207d207d
+43.438998011 jsonrpc#36IO_IN: 7b20226a736f6e72706322203a2022322e30222c20226d6574686f6422203a20227369676e70736274222c2022696422203a20226c696768746e696e672d636c692d33373437303938222c2022706172616d7322203a7b20227073627422203a202263484e69645038424148454241414141415a2b645158574d553055555157
+43.439010969 jsonrpc#36IO_IN: 3567756831674171526b36715631456673774978447a2f6c367049344259414141414141442f2f2f2f2f417551474141414141414141466741554e6958456f7571585232436f466a61503056336e63566c4564756530524b41534141414141425941464b7377684b6254414a36664877686e4274746153363276556b69744141
+43.439021145 jsonrpc#36IO_IN: 4141414141414141413d227d207d
+43.459448552 lightningdBROKEN: HSM gave bad sign_withdrawal_reply
+43.478715809 lightningdBROKEN: FATAL SIGNAL 6 (version v0.9.1-360-g5e71de7)
+43.478745971 lightningdBROKEN: backtrace: common/daemon.c:43 (send_backtrace) 0x55afc34433ba
+43.478761029 lightningdBROKEN: backtrace: common/daemon.c:51 (crashdump) 0x55afc3443409
+43.478774716 lightningdBROKEN: backtrace: (null):0 ((null)) 0x7f13ba3b469f
+43.478809357 lightningdBROKEN: backtrace: (null):0 ((null)) 0x7f13ba3b4615
+43.478821589 lightningdBROKEN: backtrace: (null):0 ((null)) 0x7f13ba39d861
+43.478834042 lightningdBROKEN: backtrace: lightningd/log.c:787 (fatal) 0x55afc33fa33d
+43.478846943 lightningdBROKEN: backtrace: wallet/walletrpc.c:720 (json_signpsbt) 0x55afc343731f
+43.478887646 lightningdBROKEN: backtrace: lightningd/jsonrpc.c:643 (command_exec) 0x55afc33f403e
+43.478901486 lightningdBROKEN: backtrace: lightningd/jsonrpc.c:753 (rpc_command_hook_callback) 0x55afc33f44dd
+43.478914432 lightningdBROKEN: backtrace: lightningd/plugin_hook.c:288 (plugin_hook_call_) 0x55afc341fece
+43.478951562 lightningdBROKEN: backtrace: lightningd/jsonrpc.c:808 (plugin_hook_call_rpc_command) 0x55afc33f4812
+43.478965294 lightningdBROKEN: backtrace: lightningd/jsonrpc.c:888 (parse_request) 0x55afc33f4c25
+43.478977719 lightningdBROKEN: backtrace: lightningd/jsonrpc.c:977 (read_json) 0x55afc33f4f51
+43.478990543 lightningdBROKEN: backtrace: ccan/ccan/io/io.c:59 (next_plan) 0x55afc348cc1d
+43.479002961 lightningdBROKEN: backtrace: ccan/ccan/io/io.c:407 (do_plan) 0x55afc348d7a4
+43.479044491 lightningdBROKEN: backtrace: ccan/ccan/io/io.c:417 (io_ready) 0x55afc348d7e2
+43.479058199 lightningdBROKEN: backtrace: ccan/ccan/io/poll.c:445 (io_loop) 0x55afc348f9a1
+43.479070803 lightningdBROKEN: backtrace: lightningd/io_loop_with_timers.c:24 (io_loop_with_timers) 0x55afc33f234a
+43.479127873 lightningdBROKEN: backtrace: lightningd/lightningd.c:1016 (main) 0x55afc33f7980
+43.479141772 lightningdBROKEN: backtrace: (null):0 ((null)) 0x7f13ba39f151
+43.479178841 lightningdBROKEN: backtrace: (null):0 ((null)) 0x55afc33dc29d
+43.479191389 lightningdBROKEN: backtrace: (null):0 ((null)) 0xffffffffffffffff

getinfo output

{
   "id": "02812bb5806368e1623ae62635c32747e23a7edd3be0f2790b217f49748b84b33b",
   "alias": "LIGHTNINGCHEF-0.9.1-360-g5e71de7",
   "color": "02812b",
   "num_peers": 5,
   "num_pending_channels": 1,
   "num_active_channels": 3,
   "num_inactive_channels": 1,
   "address": [],
   "binding": [
      {
         "type": "ipv4",
         "address": "127.0.0.1",
         "port": 9738
      }
   ],
   "version": "v0.9.1-360-g5e71de7",
   "blockheight": 955,
   "network": "regtest",
   "msatoshi_fees_collected": 0,
   "fees_collected_msat": "0msat",
   "lightning-dir": "/home/fiatjaf/.lightning/regtest",
   "warning_bitcoind_sync": "Bitcoind is not up-to-date with network."
}
cdecker commented 3 years ago

This is the line where the error occurs:

https://github.com/ElementsProject/lightning/blob/5e71de781997733393495288e5eebc3eeedfb833/wallet/walletrpc.c#L719-L721

Since the hsmd keeps working and apparently doesn't print any error messages related to this request (or logs are just missing) it appears that the signed PSBT returned from the hsmd could not be parsed.

fiatjaf commented 1 year ago

This was fixed.