lightningd/gossip: clean up channel resolve failure handling.

We were getting an assert "!secp256k1_fe_is_zero(&ge->x)", because
an all-zero pubkey is invalid.  We allow marshal/unmarshal of NULL for
now, and clean up the error handling.

1. Use status_failed if master sends a bad message.
2. Similarly, kill the gossip daemon if it gives a bad reply.
3. Use an array for returned pubkeys: 0 or 2.
4. Use type_to_string(trc, struct short_channel_id, &scid) for tracing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-05-05 16:11:44 +09:30
parent 2641ecaafa
commit cd90c8408c
5 changed files with 54 additions and 33 deletions

View File

@@ -99,7 +99,10 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
if (!fromwire(cursor, max, der, sizeof(der)))
return;
if (!pubkey_from_der(der, sizeof(der), pubkey))
/* FIXME: Handing dummy keys through here is dumb.
* See towire_gossip_resolve_channel_reply --RR */
if (!memeqzero(der, sizeof(der))
&& !pubkey_from_der(der, sizeof(der), pubkey))
fail_pull(cursor, max);
}

View File

@@ -48,9 +48,13 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
u8 output[PUBKEY_DER_LEN];
size_t outputlen = sizeof(output);
secp256k1_ec_pubkey_serialize(secp256k1_ctx, output, &outputlen,
&pubkey->pubkey,
SECP256K1_EC_COMPRESSED);
if (pubkey)
secp256k1_ec_pubkey_serialize(secp256k1_ctx, output, &outputlen,
&pubkey->pubkey,
SECP256K1_EC_COMPRESSED);
else
memset(output, 0, sizeof(output));
towire(pptr, output, outputlen);
}