From 996567c2504a736456ad5f7c57fbd80bf2781f20 Mon Sep 17 00:00:00 2001
From: Rusty Russell <rusty@rustcorp.com.au>
Date: Tue, 20 Jun 2017 15:10:03 +0930
Subject: [PATCH] lightningd: update BOLT to add channel_reestablish message.

We don't handle it yet though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 lightningd/channel/channel.c | 1 +
 lightningd/gossip/gossip.c   | 1 +
 lightningd/peer_control.c    | 2 +-
 lightningd/peer_control.h    | 4 ++--
 wire/gen_peer_wire_csv       | 4 ++++
 wire/peer_wire.c             | 1 +
 6 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c
index 8c1581d71..7c555d1a2 100644
--- a/lightningd/channel/channel.c
+++ b/lightningd/channel/channel.c
@@ -977,6 +977,7 @@ static struct io_plan *peer_in(struct io_conn *conn, struct peer *peer, u8 *msg)
 	case WIRE_ACCEPT_CHANNEL:
 	case WIRE_FUNDING_CREATED:
 	case WIRE_FUNDING_SIGNED:
+	case WIRE_CHANNEL_REESTABLISH:
 		goto badmessage;
 
 	case WIRE_SHUTDOWN:
diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c
index 1ff51484d..3fed80845 100644
--- a/lightningd/gossip/gossip.c
+++ b/lightningd/gossip/gossip.c
@@ -241,6 +241,7 @@ static struct io_plan *peer_msgin(struct io_conn *conn,
 		return peer_read_message(conn, &peer->pcs, peer_msgin);
 
 	case WIRE_OPEN_CHANNEL:
+	case WIRE_CHANNEL_REESTABLISH:
 	case WIRE_ACCEPT_CHANNEL:
 	case WIRE_FUNDING_CREATED:
 	case WIRE_FUNDING_SIGNED:
diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c
index 2a2101a33..97c142b1a 100644
--- a/lightningd/peer_control.c
+++ b/lightningd/peer_control.c
@@ -192,7 +192,7 @@ static bool peer_reconnected(struct lightningd *ld,
 		 *
 		 * On disconnection, the funder MUST remember the channel for
 		 * reconnection if it has broadcast the funding transaction,
-		 * otherwise it MUST NOT.
+		 * otherwise it SHOULD NOT.
 		 */
 		/* Free peer, which will discard HSM response. */
 		tal_free(peer);
diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h
index d96b08d74..83886db9b 100644
--- a/lightningd/peer_control.h
+++ b/lightningd/peer_control.h
@@ -104,11 +104,11 @@ static inline bool peer_on_chain(const struct peer *peer)
  *
  * On disconnection, the funder MUST remember the channel for
  * reconnection if it has broadcast the funding transaction, otherwise it
- * MUST NOT.
+ * SHOULD NOT.
  *
  * On disconnection, the non-funding node MUST remember the channel for
  * reconnection if it has sent the `funding_signed` message, otherwise
- * it MUST NOT.
+ * it SHOULD NOT.
  */
 static inline bool peer_persists(const struct peer *peer)
 {
diff --git a/wire/gen_peer_wire_csv b/wire/gen_peer_wire_csv
index 0ab68db1a..7e5d027a6 100644
--- a/wire/gen_peer_wire_csv
+++ b/wire/gen_peer_wire_csv
@@ -97,6 +97,10 @@ revoke_and_ack,64,next_per_commitment_point,33
 update_fee,134
 update_fee,0,channel_id,32
 update_fee,32,feerate_per_kw,4
+channel_reestablish,136
+channel_reestablish,0,channel_id,32
+channel_reestablish,32,commitments_received,8
+channel_reestablish,40,revocations_received,8
 announcement_signatures,259
 announcement_signatures,0,channel_id,32
 announcement_signatures,32,short_channel_id,8
diff --git a/wire/peer_wire.c b/wire/peer_wire.c
index db62ddf1a..e49791968 100644
--- a/wire/peer_wire.c
+++ b/wire/peer_wire.c
@@ -19,6 +19,7 @@ static bool unknown_type(enum wire_type t)
 	case WIRE_COMMITMENT_SIGNED:
 	case WIRE_REVOKE_AND_ACK:
 	case WIRE_UPDATE_FEE:
+	case WIRE_CHANNEL_REESTABLISH:
 	case WIRE_ANNOUNCEMENT_SIGNATURES:
 	case WIRE_CHANNEL_ANNOUNCEMENT:
 	case WIRE_NODE_ANNOUNCEMENT: