lightningd: don't assume zero-length tlv fields will be NULL.

1. We assumed an empty upfront_shutdown_script TLV would become NULL:

	RPC call failed: method: fundchannel, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'amount': 1000000, 'announce': True}, error: {'code': -1, 'message': 'They sent error channel e7c2d5d14462fe269631418fbfc3db327843382e6a2a5a9c2991d2d6ba31d9f5: Unacceptable upfront_shutdown_script ', 'data': {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'method': 'fundchannel_start'}}"

2. We were assuming an empty enctlv would become NULL, too.

We should not have done this (there's a semantic difference between
"empty" and not-present for TLVs), so prepare for the change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-07-21 15:08:25 +09:30 committed by neil saitug
parent 1eb7edb0bb
commit d38cfcf33b
2 changed files with 11 additions and 1 deletions

View file

@ -28,7 +28,7 @@ static void onion_message_serialize(struct onion_message_hook_payload *payload,
json_object_start(stream, NULL);
json_add_pubkey(stream, "id",
&payload->reply_path[i]->node_id);
if (payload->reply_path[i]->enctlv)
if (tal_bytelen(payload->reply_path[i]->enctlv) != 0)
json_add_hex_talarr(stream, "enctlv",
payload->reply_path[i]->enctlv);
if (i == 0)

View file

@ -329,6 +329,16 @@ static void set_remote_upfront_shutdown(struct state *state,
state->their_features,
OPT_SHUTDOWN_ANYSEGWIT);
/* BOLT #2:
*
* - MUST include `upfront_shutdown_script` with either a valid
* `shutdown_scriptpubkey` as required by `shutdown` `scriptpubkey`,
* or a zero-length `shutdown_scriptpubkey` (ie. `0x0000`).
*/
/* We turn empty into NULL. */
if (tal_bytelen(shutdown_scriptpubkey) == 0)
shutdown_scriptpubkey = tal_free(shutdown_scriptpubkey);
state->upfront_shutdown_script[REMOTE]
= tal_steal(state, shutdown_scriptpubkey);