From 279f21620875826fcbbc674045ef6c2adf8411d6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Feb 2017 14:35:10 +1030 Subject: [PATCH] gen_peer_wire_csv: update to latest spec. In particular, 860990fa0afb55f839e882a5e9abe8abe6ccb981 reordered channel_announcement and c93bf5cf8c48eab1b028e85214cb35feeeffcbb3 reordered the update_fail_malformed_htlc message. Signed-off-by: Rusty Russell --- daemon/p2p_announce.c | 14 +++++++++----- wire/gen_peer_wire_csv | 10 +++++----- wire/test/run-peer-wire.c | 6 +++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/daemon/p2p_announce.c b/daemon/p2p_announce.c index f08e43cf6..93f0186a3 100644 --- a/daemon/p2p_announce.c +++ b/daemon/p2p_announce.c @@ -219,9 +219,9 @@ void handle_channel_announcement( serialized = tal_dup_arr(tmpctx, u8, announce, len, 0); if (!fromwire_channel_announcement(tmpctx, serialized, NULL, &node_signature_1, &node_signature_2, - &channel_id, &bitcoin_signature_1, &bitcoin_signature_2, + &channel_id, &node_id_1, &node_id_2, &bitcoin_key_1, &bitcoin_key_2, &features)) { @@ -525,24 +525,28 @@ static void broadcast_channel_announcement(struct lightningd_state *dstate, stru towire_pubkey(&serialized, &dstate->id); privkey_sign(dstate, serialized, tal_count(serialized), my_bitcoin_signature); - /* Sign the entire packet with `node_id`, proves integrity and origin */ + /* BOLT #7: + * + * The creating node MUST compute the double-SHA256 hash `h` of the + * message, starting at offset 256, up to the end of the message. + */ serialized = towire_channel_announcement(tmpctx, &node_signature[0], &node_signature[1], - &channel_id, &bitcoin_signature[0], &bitcoin_signature[1], + &channel_id, node_id[0], node_id[1], bitcoin_key[0], bitcoin_key[1], NULL); - privkey_sign(dstate, serialized + 128, tal_count(serialized) - 128, my_node_signature); + privkey_sign(dstate, serialized + 256, tal_count(serialized) - 256, my_node_signature); serialized = towire_channel_announcement(tmpctx, &node_signature[0], &node_signature[1], - &channel_id, &bitcoin_signature[0], &bitcoin_signature[1], + &channel_id, node_id[0], node_id[1], bitcoin_key[0], diff --git a/wire/gen_peer_wire_csv b/wire/gen_peer_wire_csv index 4598a2cd8..f90e3ee77 100644 --- a/wire/gen_peer_wire_csv +++ b/wire/gen_peer_wire_csv @@ -78,8 +78,8 @@ update_fail_htlc,18,reason,len update_fail_malformed_htlc,135 update_fail_malformed_htlc,0,channel-id,8 update_fail_malformed_htlc,8,id,8 -update_fail_malformed_htlc,16,failure-code,4 -update_fail_malformed_htlc,20,sha256-of-onion,32 +update_fail_malformed_htlc,16,sha256-of-onion,32 +update_fail_malformed_htlc,48,failure-code,2 commit_sig,132 commit_sig,0,channel-id,8 commit_sig,8,signature,64 @@ -98,9 +98,9 @@ update_fee,8,feerate-per-kw,4 channel_announcement,256 channel_announcement,0,node-signature-1,64 channel_announcement,64,node-signature-2,64 -channel_announcement,128,channel-id,8 -channel_announcement,136,bitcoin-signature-1,64 -channel_announcement,200,bitcoin-signature-2,64 +channel_announcement,128,bitcoin-signature-1,64 +channel_announcement,192,bitcoin-signature-2,64 +channel_announcement,256,channel-id,8 channel_announcement,264,node-id-1,33 channel_announcement,297,node-id-2,33 channel_announcement,330,bitcoin-key-1,33 diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 97baee083..8ccbadcc3 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -185,9 +185,9 @@ struct msg_update_fail_htlc { struct msg_channel_announcement { secp256k1_ecdsa_signature node_signature_1; secp256k1_ecdsa_signature node_signature_2; - struct channel_id channel_id; secp256k1_ecdsa_signature bitcoin_signature_1; secp256k1_ecdsa_signature bitcoin_signature_2; + struct channel_id channel_id; struct pubkey node_id_1; struct pubkey node_id_2; struct pubkey bitcoin_key_1; @@ -217,9 +217,9 @@ static void *towire_struct_channel_announcement(const tal_t *ctx, return towire_channel_announcement(ctx, &s->node_signature_1, &s->node_signature_2, - &s->channel_id, &s->bitcoin_signature_1, &s->bitcoin_signature_2, + &s->channel_id, &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1, @@ -233,9 +233,9 @@ static struct msg_channel_announcement *fromwire_struct_channel_announcement(con if (!fromwire_channel_announcement(s, p, plen, &s->node_signature_1, &s->node_signature_2, - &s->channel_id, &s->bitcoin_signature_1, &s->bitcoin_signature_2, + &s->channel_id, &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1,