channeld: include last sent commit and last revoke in init message.

It's easiest to have the master keep the last commit we sent, for
re-transmission.  We could recalculate it, but it's made more difficult
by the before/after revoke case.

And because revoke_and_ack changes the channel state, we need to
remember which order we sent them in for re-transmission.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-06-20 15:33:03 +09:30
parent 6700a48d42
commit c1d5e41dfe
5 changed files with 21 additions and 1 deletions

View file

@ -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));

View file

@ -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

1 # Shouldn't happen
40 channel_init,,init_peer_pkt,init_peer_pkt_len*u8 channel_init,,num_last_sent_commit,u16
41 # Tx is deep enough, go! channel_init,,last_sent_commit,num_last_sent_commit*struct changed_htlc
42 channel_funding_locked,2 channel_init,,init_peer_pkt_len,u16
43 channel_init,,init_peer_pkt,init_peer_pkt_len*u8
44 # Tx is deep enough, go!
45 channel_funding_locked,2
46 channel_funding_locked,,short_channel_id,struct short_channel_id
47 # Tell the channel that we may announce the channel's existence
48 channel_funding_announce_depth,3

View file

@ -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) */

View file

@ -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)

View file

@ -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;
}