diff --git a/lightningd/channel.c b/lightningd/channel.c index e0bffb768..92c6f809d 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -430,6 +430,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->channel_flags = channel_flags; channel->our_config = *our_config; channel->minimum_depth = minimum_depth; + channel->depth = 0; channel->next_index[LOCAL] = next_index_local; channel->next_index[REMOTE] = next_index_remote; channel->next_htlc_id = next_htlc_id; diff --git a/lightningd/channel.h b/lightningd/channel.h index afd72e4a7..fbe86a63f 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -119,6 +119,12 @@ struct channel { /* Minimum funding depth (specified by us if they fund). */ u32 minimum_depth; + /* Depth of the funding TX as reported by the txout + * watch. Only used while we're in state + * CHANNELD_AWAITING_LOCKING, afterwards the watches do not + * trigger anymore. */ + u32 depth; + /* Tracking commitment transaction numbers. */ u64 next_index[NUM_SIDES]; u64 next_htlc_id; diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index eafed96ba..9c908b586 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -256,7 +256,9 @@ static void peer_got_funding_locked(struct channel *channel, const u8 *msg) /* Remember that we got the lockin */ wallet_channel_save(channel->peer->ld->wallet, channel); - lockin_complete(channel); + + if (channel->depth >= channel->minimum_depth) + lockin_complete(channel); } static void peer_got_announcement(struct channel *channel, const u8 *msg) @@ -805,6 +807,7 @@ bool channel_tell_depth(struct lightningd *ld, const char *txidstr; txidstr = type_to_string(tmpctx, struct bitcoin_txid, txid); + channel->depth = depth; if (!channel->owner) { log_debug(channel->log,