diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c index 9e5b396f4..8709b9107 100644 --- a/lightningd/channel/channel.c +++ b/lightningd/channel/channel.c @@ -1219,7 +1219,8 @@ static void init_channel(struct peer *peer) u64 local_msatoshi; struct pubkey funding_pubkey[NUM_SIDES]; struct sha256_double funding_txid; - bool am_funder; + bool am_funder, last_was_revoke; + struct changed_htlc *last_sent_commit; u8 *funding_signed; u8 *msg; @@ -1243,6 +1244,8 @@ static void init_channel(struct peer *peer) &peer->node_ids[REMOTE], &peer->commit_msec, &peer->cltv_delta, + &last_was_revoke, + &last_sent_commit, &funding_signed)) status_failed(WIRE_CHANNEL_BAD_COMMAND, "Init: %s", tal_hex(msg, msg)); diff --git a/lightningd/channel/channel_wire.csv b/lightningd/channel/channel_wire.csv index 97a58ae82..5a6906f88 100644 --- a/lightningd/channel/channel_wire.csv +++ b/lightningd/channel/channel_wire.csv @@ -40,6 +40,9 @@ channel_init,,local_node_id,struct pubkey channel_init,,remote_node_id,struct pubkey channel_init,,commit_msec,4 channel_init,,cltv_delta,u16 +channel_init,,last_was_revoke,bool +channel_init,,num_last_sent_commit,u16 +channel_init,,last_sent_commit,num_last_sent_commit*struct changed_htlc channel_init,,init_peer_pkt_len,u16 channel_init,,init_peer_pkt,init_peer_pkt_len*u8 diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 450cf51fd..03bb28a1b 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -297,6 +297,8 @@ void add_peer(struct lightningd *ld, u64 unique_id, peer->state = UNINITIALIZED; peer->channel_info = NULL; peer->next_per_commitment_point = NULL; + peer->last_was_revoke = false; + peer->last_sent_commit = NULL; peer->num_commits_sent = peer->num_commits_received = peer->num_revocations_received = 0; shachain_init(&peer->their_shachain); @@ -960,6 +962,8 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp, &peer->id, time_to_msec(cfg->commit_time), cfg->deadline_blocks, + peer->last_was_revoke, + peer->last_sent_commit, peer->funding_signed); /* Don't need this any more (we never re-transmit it) */ diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 6b805b229..5050fbd96 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -86,6 +86,10 @@ struct peer { /* Gossip client fd, forwarded to the respective owner */ int gossip_client_fd; + + /* Reestablishment stuff: last sent commit and revocation details. */ + bool last_was_revoke; + struct changed_htlc *last_sent_commit; }; static inline bool peer_can_add_htlc(const struct peer *peer) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 391132d16..02a49e3de 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -793,6 +793,11 @@ int peer_sending_commitsig(struct peer *peer, const u8 *msg) peer->num_commits_sent++; + /* Last was commit. */ + peer->last_was_revoke = false; + tal_free(peer->last_sent_commit); + peer->last_sent_commit = tal_steal(peer, changed_htlcs); + /* Tell it we've got it, and to go ahead with commitment_signed. */ subd_send_msg(peer->owner, take(towire_channel_sending_commitsig_reply(msg))); @@ -860,6 +865,7 @@ static bool peer_sending_revocation(struct peer *peer, } } + peer->last_was_revoke = true; return true; }