From 22b6e330303dcbc5397a3604b59908d7e48c0dff Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 3 May 2022 17:09:58 +0200 Subject: [PATCH] zeroconf: Trigger coin_movement on first real confirmation We don't trigger on depth=0 since that'd give us bogus blockheights and pointers into the chain, instead we defer until we get a first confirmation. This extracts some of the logic from `lockin_complete`, into the depth change listener (not the remote funding locked since at that point we're certainly locked in and we don't really care about that for bookkeeping anyway). --- lightningd/channel_control.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e158cae74..eafed96ba 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -841,11 +841,30 @@ bool channel_tell_depth(struct lightningd *ld, take(towire_channeld_funding_depth( NULL, channel->scid, channel->alias[LOCAL], depth))); - if (channel->remote_funding_locked - && channel->state == CHANNELD_AWAITING_LOCKIN - && depth >= channel->minimum_depth) + if (channel->remote_funding_locked && + channel->state == CHANNELD_AWAITING_LOCKIN && + depth >= channel->minimum_depth) lockin_complete(channel); + else if (depth == 1 && channel->minimum_depth == 0) { + /* If we have a zeroconf channel, i.e., no scid yet + * but have exchange `channel_ready` messages, then we + * need to fire a second time, in order to trigger the + * `coin_movement` event. This is a subset of the + * `lockin_complete` function below. */ + + assert(channel->scid != NULL); + /* Fees might have changed (and we use IMMEDIATE once we're + * funded), so update now. */ + try_update_feerates(channel->peer->ld, channel); + + try_update_blockheight( + channel->peer->ld, channel, + get_block_height(channel->peer->ld->topology)); + + /* Only record this once we get a real confirmation. */ + channel_record_open(channel); + } return true; }