diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 53d504d5c..55ae6214c 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 11a43451f..8f04547eb 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);