Skip to content

Commit

Permalink
channeld: implement pending_updates()
Browse files Browse the repository at this point in the history
Says if we have started an update which is still pending somewhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and cdecker committed May 25, 2021
1 parent 2137286 commit 378d1c4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 378d1c4

Please sign in to comment.