From b017ca12400fc3f13e4ad02cdd4bbb7f5b28baea Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Mar 2016 17:08:35 +1030 Subject: [PATCH] protocol: include next revocation hash in open packet. This means we send the first two revocation hashes; this is important once we move to a commit model as we need to send (unsolicited) the signature for the *next* commit tx so we need its commit hash. Signed-off-by: Rusty Russell --- daemon/packets.c | 2 ++ daemon/peer.c | 1 + daemon/peer.h | 2 ++ lightning.pb-c.c | 19 ++++++++++++++++--- lightning.pb-c.h | 6 +++++- lightning.proto | 2 ++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index e259a088e..6aa50106f 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -74,6 +74,7 @@ Pkt *pkt_open(const tal_t *ctx, const struct peer *peer, open_channel__init(o); o->revocation_hash = sha256_to_proto(ctx, &peer->us.revocation_hash); + o->next_revocation_hash = sha256_to_proto(ctx, &peer->us.next_revocation_hash); o->commit_key = pubkey_to_proto(o, &peer->us.commitkey); o->final_key = pubkey_to_proto(o, &peer->us.finalkey); o->delay = tal(o, Locktime); @@ -317,6 +318,7 @@ Pkt *accept_pkt_open(const tal_t *ctx, o->final_key, &peer->them.finalkey)) return pkt_err(ctx, "Bad finalkey"); proto_to_sha256(o->revocation_hash, &peer->them.revocation_hash); + proto_to_sha256(o->next_revocation_hash, &peer->them.next_revocation_hash); /* Redeemscript for anchor. */ peer->anchor.redeemscript diff --git a/daemon/peer.c b/daemon/peer.c index 7d67e2a23..ed8adf65e 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -270,6 +270,7 @@ static struct io_plan *peer_crypto_on(struct io_conn *conn, struct peer *peer) { peer_secrets_init(peer); peer_get_revocation_hash(peer, 0, &peer->us.revocation_hash); + peer_get_revocation_hash(peer, 1, &peer->us.next_revocation_hash); assert(peer->state == STATE_INIT); diff --git a/daemon/peer.h b/daemon/peer.h index 17f469ab2..54f787f7f 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -55,6 +55,8 @@ struct peer_visible_state { u64 commit_fee; /* Revocation hash for latest commit tx. */ struct sha256 revocation_hash; + /* Revocation hash for next commit tx. */ + struct sha256 next_revocation_hash; /* Current commit tx. */ struct bitcoin_tx *commit; }; diff --git a/lightning.pb-c.c b/lightning.pb-c.c index 15bddeb11..96e89abbd 100644 --- a/lightning.pb-c.c +++ b/lightning.pb-c.c @@ -1381,7 +1381,7 @@ const ProtobufCEnumDescriptor open_channel__anchor_offer__descriptor = NULL,NULL,NULL,NULL /* reserved[1234] */ }; static const uint32_t open_channel__min_depth__default_value = 0u; -static const ProtobufCFieldDescriptor open_channel__field_descriptors[7] = +static const ProtobufCFieldDescriptor open_channel__field_descriptors[8] = { { "delay", @@ -1467,6 +1467,18 @@ static const ProtobufCFieldDescriptor open_channel__field_descriptors[7] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "next_revocation_hash", + 8, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(OpenChannel, next_revocation_hash), + &sha256_hash__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned open_channel__field_indices_by_name[] = { 4, /* field[4] = anch */ @@ -1475,12 +1487,13 @@ static const unsigned open_channel__field_indices_by_name[] = { 0, /* field[0] = delay */ 3, /* field[3] = final_key */ 5, /* field[5] = min_depth */ + 7, /* field[7] = next_revocation_hash */ 1, /* field[1] = revocation_hash */ }; static const ProtobufCIntRange open_channel__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 7 } + { 0, 8 } }; const ProtobufCMessageDescriptor open_channel__descriptor = { @@ -1490,7 +1503,7 @@ const ProtobufCMessageDescriptor open_channel__descriptor = "OpenChannel", "", sizeof(OpenChannel), - 7, + 8, open_channel__field_descriptors, open_channel__field_indices_by_name, 1, open_channel__number_ranges, diff --git a/lightning.pb-c.h b/lightning.pb-c.h index 2a435ca6a..be8575a00 100644 --- a/lightning.pb-c.h +++ b/lightning.pb-c.h @@ -180,6 +180,10 @@ struct _OpenChannel * Hash for revoking first commitment transaction. */ Sha256Hash *revocation_hash; + /* + * Hash for revoking second commitment transaction. + */ + Sha256Hash *next_revocation_hash; /* * Pubkey for anchor to pay into commitment tx. */ @@ -201,7 +205,7 @@ struct _OpenChannel }; #define OPEN_CHANNEL__INIT \ { PROTOBUF_C_MESSAGE_INIT (&open_channel__descriptor) \ - , NULL, NULL, NULL, NULL, 0, 0,0u, 0 } + , NULL, NULL, NULL, NULL, NULL, 0, 0,0u, 0 } /* diff --git a/lightning.proto b/lightning.proto index f97e8a38d..45c5b0368 100644 --- a/lightning.proto +++ b/lightning.proto @@ -65,6 +65,8 @@ message open_channel { required locktime delay = 1; // Hash for revoking first commitment transaction. required sha256_hash revocation_hash = 2; + // Hash for revoking second commitment transaction. + required sha256_hash next_revocation_hash = 8; // Pubkey for anchor to pay into commitment tx. required bitcoin_pubkey commit_key = 3; // How to pay money to us from commit_tx.