diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index d7bde69d8..52eef8c22 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -127,16 +127,13 @@ void notify_feerate_change(struct lightningd *ld) * peer. We *could* do so, however. */ } -void channel_record_open(struct channel *channel) +void channel_record_open(struct channel *channel, u32 blockheight) { struct chain_coin_mvt *mvt; - u32 blockheight; struct amount_msat start_balance; bool is_pushed = !amount_msat_zero(channel->push); bool is_leased = channel->lease_expiry > 0; - blockheight = short_channel_id_blocknum(channel->scid); - /* If funds were pushed, add/sub them from the starting balance */ if (channel->opener == LOCAL) { if (!amount_msat_add(&start_balance, @@ -210,7 +207,8 @@ static void lockin_complete(struct channel *channel) /* Only record this once we get a real confirmation. */ if (channel->scid) - channel_record_open(channel); + channel_record_open(channel, + short_channel_id_blocknum(channel->scid)); } bool channel_on_funding_locked(struct channel *channel, @@ -869,7 +867,8 @@ bool channel_tell_depth(struct lightningd *ld, get_block_height(channel->peer->ld->topology)); /* Only record this once we get a real confirmation. */ - channel_record_open(channel); + channel_record_open(channel, + short_channel_id_blocknum(channel->scid)); } return true; } diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h index 8f3b8ab19..420754706 100644 --- a/lightningd/channel_control.h +++ b/lightningd/channel_control.h @@ -35,7 +35,7 @@ bool channel_on_funding_locked(struct channel *channel, struct pubkey *next_per_commitment_point); /* Record channel open (coin movement notifications) */ -void channel_record_open(struct channel *channel); +void channel_record_open(struct channel *channel, u32 blockheight); /* A channel has unrecoverably fallen behind */ void channel_fallen_behind(struct channel *channel, const u8 *msg); diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index ba8321f06..fba6ff1a4 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -3,6 +3,7 @@ * saves and funding tx watching for a channel open */ #include "config.h" +#include #include #include #include @@ -1748,7 +1749,8 @@ static void handle_channel_locked(struct subd *dualopend, CHANNELD_NORMAL, REASON_UNKNOWN, "Lockin complete"); - channel_record_open(channel); + channel_record_open(channel, + short_channel_id_blocknum(channel->scid)); /* Empty out the inflights */ wallet_channel_clear_inflights(dualopend->ld->wallet, channel); diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 2e8919751..02a728157 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -622,6 +623,17 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel_fail_permanent(channel, reason, "Funding transaction spent"); + /* If we haven't posted the open event yet, post an open */ + if (!channel->scid || !channel->remote_funding_locked) { + u32 blkh; + /* Note that blockheight will be zero if it's not in chain + * yet */ + blkh = wallet_transaction_height(channel->peer->ld->wallet, + &channel->funding.txid); + channel_record_open(channel, blkh); + } + + /* We could come from almost any state. */ /* NOTE(mschmoock) above comment is wrong, since we failed above! */ channel_set_state(channel,