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).
This commit is contained in:
Christian Decker 2022-05-03 17:09:58 +02:00
parent 2dc86bf29b
commit 22b6e33030

View File

@ -841,11 +841,30 @@ bool channel_tell_depth(struct lightningd *ld,
take(towire_channeld_funding_depth( take(towire_channeld_funding_depth(
NULL, channel->scid, channel->alias[LOCAL], depth))); NULL, channel->scid, channel->alias[LOCAL], depth)));
if (channel->remote_funding_locked if (channel->remote_funding_locked &&
&& channel->state == CHANNELD_AWAITING_LOCKIN channel->state == CHANNELD_AWAITING_LOCKIN &&
&& depth >= channel->minimum_depth) depth >= channel->minimum_depth)
lockin_complete(channel); 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; return true;
} }