From d2673a4e6f90e7f4217efa63a1342175e646c692 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 13 Dec 2019 00:38:53 +1030 Subject: [PATCH] channeld: remove changes_pending flags. These used to be necessary as we could have feerate changes which we couldn't track: now we do, we don't need these flags. Signed-off-by: Rusty Russell --- channeld/channeld.c | 9 -------- channeld/full_channel.c | 48 +++++++++------------------------------- common/initial_channel.c | 2 -- common/initial_channel.h | 3 --- 4 files changed, 10 insertions(+), 52 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 8d35da0f3..899abed63 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2531,15 +2531,6 @@ static void peer_reconnect(struct peer *peer, send_fail_or_fulfill(peer, htlc); } - /* Corner case: we will get upset with them if they send - * commitment_signed with no changes. But it could be that we sent a - * feechange, they acked, and now they want to commit it; we can't - * even tell by seeing if fees are different (short of saving full fee - * state in database) since it could be a tiny feechange, or two - * feechanges which cancelled out. */ - if (peer->channel->funder == LOCAL) - peer->channel->changes_pending[LOCAL] = true; - peer_billboard(true, "Reconnected, and reestablished."); /* BOLT #2: diff --git a/channeld/full_channel.c b/channeld/full_channel.c index bfb3c9b13..f0d947fb8 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -624,13 +624,6 @@ static enum channel_add_err add_htlc(struct channel *channel, if (htlcp) *htlcp = htlc; - /* This is simply setting changes_pending[receiver] unless it's - * an exotic state (i.e. channel_force_htlcs) */ - if (htlc_state_flags(htlc->state) & HTLC_LOCAL_F_PENDING) - channel->changes_pending[LOCAL] = true; - if (htlc_state_flags(htlc->state) & HTLC_REMOTE_F_PENDING) - channel->changes_pending[REMOTE] = true; - return CHANNEL_ERR_ADD_OK; } @@ -720,8 +713,6 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel, htlc->id, htlc_state_name(htlc->state)); return CHANNEL_ERR_HTLC_NOT_IRREVOCABLE; } - /* The HTLC owner is the recipient of the fulfillment. */ - channel->changes_pending[owner] = true; dump_htlc(htlc, "FULFILL:"); @@ -765,8 +756,6 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel, htlc->id, htlc_state_name(htlc->state)); return CHANNEL_ERR_HTLC_NOT_IRREVOCABLE; } - /* The HTLC owner is the recipient of the failure. */ - channel->changes_pending[owner] = true; dump_htlc(htlc, "FAIL:"); if (htlcp) @@ -1008,29 +997,23 @@ bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw) side_to_str(!channel->funder), feerate_per_kw); start_fee_update(channel->fee_states, channel->funder, feerate_per_kw); - - channel->changes_pending[!channel->funder] = true; return true; } bool channel_sending_commit(struct channel *channel, const struct htlc ***htlcs) { + int change; const enum htlc_state states[] = { SENT_ADD_HTLC, SENT_REMOVE_REVOCATION, SENT_ADD_REVOCATION, SENT_REMOVE_HTLC }; status_debug("Trying commit"); - if (!channel->changes_pending[REMOTE]) { - assert(change_htlcs(channel, REMOTE, states, ARRAY_SIZE(states), - htlcs, "testing sending_commit") == 0); + change = change_htlcs(channel, REMOTE, states, ARRAY_SIZE(states), + htlcs, "sending_commit"); + if (!change) return false; - } - - change_htlcs(channel, REMOTE, states, ARRAY_SIZE(states), - htlcs, "sending_commit"); - channel->changes_pending[REMOTE] = false; return true; } @@ -1049,31 +1032,23 @@ bool channel_rcvd_revoke_and_ack(struct channel *channel, htlcs, "rcvd_revoke_and_ack"); /* Their ack can queue changes on our side. */ - if (change & HTLC_LOCAL_F_PENDING) - channel->changes_pending[LOCAL] = true; - - return channel->changes_pending[LOCAL]; + return (change & HTLC_LOCAL_F_PENDING); } /* FIXME: We can actually merge these two... */ bool channel_rcvd_commit(struct channel *channel, const struct htlc ***htlcs) { + int change; const enum htlc_state states[] = { RCVD_ADD_REVOCATION, RCVD_REMOVE_HTLC, RCVD_ADD_HTLC, RCVD_REMOVE_REVOCATION }; status_debug("Received commit"); - if (!channel->changes_pending[LOCAL]) { - assert(change_htlcs(channel, LOCAL, states, ARRAY_SIZE(states), - htlcs, "testing rcvd_commit") == 0); + change = change_htlcs(channel, LOCAL, states, ARRAY_SIZE(states), + htlcs, "rcvd_commit"); + if (!change) return false; - } - - change_htlcs(channel, LOCAL, states, ARRAY_SIZE(states), htlcs, - "rcvd_commit"); - - channel->changes_pending[LOCAL] = false; return true; } @@ -1089,10 +1064,7 @@ bool channel_sending_revoke_and_ack(struct channel *channel) "sending_revoke_and_ack"); /* Our ack can queue changes on their side. */ - if (change & HTLC_REMOTE_F_PENDING) - channel->changes_pending[REMOTE] = true; - - return channel->changes_pending[REMOTE]; + return (change & HTLC_REMOTE_F_PENDING); } size_t num_channel_htlcs(const struct channel *channel) diff --git a/common/initial_channel.c b/common/initial_channel.c index e6a943468..6074ee585 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -43,8 +43,6 @@ struct channel *new_initial_channel(const tal_t *ctx, channel->funding_pubkey[LOCAL] = *local_funding_pubkey; channel->funding_pubkey[REMOTE] = *remote_funding_pubkey; channel->htlcs = NULL; - channel->changes_pending[LOCAL] = channel->changes_pending[REMOTE] - = false; /* takes() if necessary */ channel->fee_states = dup_fee_states(channel, fee_states); diff --git a/common/initial_channel.h b/common/initial_channel.h index e0741d231..cf202127e 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -53,9 +53,6 @@ struct channel { /* All live HTLCs for this channel */ struct htlc_map *htlcs; - /* Do we have changes pending for ourselves/other? */ - bool changes_pending[NUM_SIDES]; - /* Fee changes, some which may be in transit */ struct fee_states *fee_states;