channel: remove awaiting_revoke_and_ack flag.

We can tell this more generically because the count of revocations
received != count of commitments sent.  This is the correct condition
which allows us to restore the test we had to eliminate in
c3cb7f1c85.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-12-02 16:25:21 +10:30 committed by Christian Decker
parent fda77f27a5
commit 02411b04e4
5 changed files with 11 additions and 28 deletions

View File

@ -692,7 +692,9 @@ static void send_commit(struct peer *peer)
/* FIXME: Document this requirement in BOLT 2! */
/* We can't send two commits in a row. */
if (channel_awaiting_revoke_and_ack(peer->channel)) {
if (peer->revocations_received != peer->next_index[REMOTE] - 1) {
assert(peer->revocations_received
== peer->next_index[REMOTE] - 2);
status_trace("Can't send commit: waiting for revoke_and_ack");
/* Mark this as done and try again. */
peer->commit_timer = NULL;
@ -1141,9 +1143,12 @@ static struct io_plan *handle_peer_revoke_and_ack(struct io_conn *conn,
"Bad revoke_and_ack %s", tal_hex(msg, msg));
}
/* FIXME: We can get unexpected revoke_and_ack due to retransmit; we
* should really detect this case and set
* channel_awaiting_revoke_and_ack; normally it will be true here. */
if (peer->revocations_received != peer->next_index[REMOTE] - 2) {
peer_failed(io_conn_fd(peer->peer_conn),
&peer->pcs.cs,
&peer->channel_id,
"Unexpected revoke_and_ack");
}
/* BOLT #2:
*
@ -1178,7 +1183,7 @@ static struct io_plan *handle_peer_revoke_and_ack(struct io_conn *conn,
status_trace("No commits outstanding after recv revoke_and_ack");
/* Tell master about things this locks in, wait for response */
msg = got_revoke_msg(tmpctx, peer->next_index[REMOTE] - 2,
msg = got_revoke_msg(tmpctx, peer->revocations_received++,
&old_commit_secret, &next_per_commit,
changed_htlcs);
master_wait_sync_reply(tmpctx, peer, take(msg),
@ -1605,8 +1610,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
msg_enqueue(&peer->peer_out, take(msg));
tal_free(commit_sigs);
/* Now we have to wait for revoke_and_ack */
peer->channel->awaiting_revoke_and_ack = true;
assert(peer->revocations_received == peer->next_index[REMOTE] - 2);
}
static void peer_reconnect(struct peer *peer)

View File

@ -773,8 +773,6 @@ bool channel_sending_commit(struct channel *channel,
htlcs, "sending_commit");
channel->changes_pending[REMOTE] = false;
assert(!channel->awaiting_revoke_and_ack);
channel->awaiting_revoke_and_ack = true;
return true;
}
@ -795,8 +793,6 @@ bool channel_rcvd_revoke_and_ack(struct channel *channel,
if (change & HTLC_LOCAL_F_PENDING)
channel->changes_pending[LOCAL] = true;
channel->awaiting_revoke_and_ack = false;
/* For funder, ack also means time to apply new feerate locally. */
if (channel->funder == LOCAL &&
(channel->view[LOCAL].feerate_per_kw
@ -862,11 +858,6 @@ bool channel_sending_revoke_and_ack(struct channel *channel)
return channel->changes_pending[REMOTE];
}
bool channel_awaiting_revoke_and_ack(const struct channel *channel)
{
return channel->awaiting_revoke_and_ack;
}
bool channel_has_htlcs(const struct channel *channel)
{
struct htlc_map_iter it;

View File

@ -241,14 +241,6 @@ bool channel_rcvd_commit(struct channel *channel,
* anything changed for the remote commitment (ie. send a new commit).*/
bool channel_sending_revoke_and_ack(struct channel *channel);
/**
* channel_awaiting_revoke_and_ack: are we waiting for revoke_and_ack?
* @channel: the channel
*
* If true, we can't send a new commit message.
*/
bool channel_awaiting_revoke_and_ack(const struct channel *channel);
/**
* channel_has_htlcs: are there any (live) HTLCs at all in channel?
* @channel: the channel

View File

@ -40,7 +40,6 @@ struct channel *new_initial_channel(const tal_t *ctx,
channel->htlcs = NULL;
channel->changes_pending[LOCAL] = channel->changes_pending[REMOTE]
= false;
channel->awaiting_revoke_and_ack = false;
channel->view[LOCAL].feerate_per_kw
= channel->view[REMOTE].feerate_per_kw

View File

@ -55,9 +55,6 @@ struct channel {
/* Do we have changes pending for ourselves/other? */
bool changes_pending[NUM_SIDES];
/* Are we waiting for their revoke_and_ack? */
bool awaiting_revoke_and_ack;
/* What it looks like to each side. */
struct channel_view view[NUM_SIDES];
};