From 47d51fedb2a3d9c61820f77b42baa22407b435e5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 14 May 2021 10:26:05 +0930 Subject: [PATCH] channeld: implement pending_updates() Says if we have started an update which is still pending somewhere. Signed-off-by: Rusty Russell --- channeld/full_channel.c | 28 ++++++++++++++++++++++++++++ channeld/full_channel.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 53d504d5c8c0..55ae6214c0b3 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -1252,6 +1252,34 @@ static bool adjust_balance(struct balance view_owed[NUM_SIDES][NUM_SIDES], return true; } +bool pending_updates(const struct channel *channel, enum side side) +{ + struct htlc_map_iter it; + const struct htlc *htlc; + + /* Initiator might have fee changes in play. */ + if (side == channel->opener) { + if (!feerate_changes_done(channel->fee_states)) + return true; + } + + for (htlc = htlc_map_first(channel->htlcs, &it); + htlc; + htlc = htlc_map_next(channel->htlcs, &it)) { + /* If it's still being added, it's owner added it. */ + if (htlc_state_flags(htlc->state) & HTLC_ADDING) { + if (htlc_owner(htlc) == side) + return true; + /* If it's being removed, non-owner removed it */ + } else if (htlc_state_flags(htlc->state) & HTLC_REMOVING) { + if (htlc_owner(htlc) != side) + return true; + } + } + + return false; +} + bool channel_force_htlcs(struct channel *channel, const struct existing_htlc **htlcs) { diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 11a43451fbbf..8f04547eb70b 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -254,6 +254,13 @@ bool channel_force_htlcs(struct channel *channel, */ void dump_htlcs(const struct channel *channel, const char *prefix); +/** + * pending_updates: does this side have updates pending in channel? + * @channel: the channel + * @side: the side who is offering or failing/fulfilling HTLC, or feechange + */ +bool pending_updates(const struct channel *channel, enum side side); + const char *channel_add_err_name(enum channel_add_err e); const char *channel_remove_err_name(enum channel_remove_err e);