Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onchaind: replay using real block data, not db #7343

Merged
6 changes: 6 additions & 0 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,12 @@ void gossmap_manage_channel_spent(struct gossmap_manage *gm,
return;
}

/* Is it already dying? It's lightningd re-telling us */
for (size_t i = 0; i < tal_count(gm->dying_channels); i++) {
if (short_channel_id_eq(gm->dying_channels[i].scid, scid))
return;
}

/* BOLT #7:
* - once its funding output has been spent OR reorganized out:
* - SHOULD forget a channel after a 12-block delay.
Expand Down
3 changes: 3 additions & 0 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
channel->ignore_fee_limits = ld->config.ignore_fee_limits;
channel->last_stable_connection = 0;
channel->stable_conn_timer = NULL;
channel->onchaind_replay_watches = NULL;
/* Nothing happened yet */
memset(&channel->stats, 0, sizeof(channel->stats));
channel->state_changes = tal_arr(channel, struct channel_state_change *, 0);
Expand Down Expand Up @@ -607,6 +608,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->ignore_fee_limits = ignore_fee_limits;
channel->last_stable_connection = last_stable_connection;
channel->stable_conn_timer = NULL;
channel->onchaind_replay_watches = NULL;
channel->num_onchain_spent_calls = 0;
channel->stats = *stats;
channel->state_changes = tal_steal(channel, state_changes);

Expand Down
7 changes: 7 additions & 0 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ struct channel {
/* Watch we have on funding output. */
struct txowatch *funding_spend_watch;

/* If we're doing a replay for onchaind, here are the txids it's watching */
struct replay_tx_hash *onchaind_replay_watches;
/* Number of outstanding onchaind_spent calls */
size_t num_onchain_spent_calls;
/* Height we're replaying at (if onchaind_replay_watches set) */
u32 onchaind_replay_height;

/* Our original funds, in funding amount */
struct amount_sat our_funds;

Expand Down
22 changes: 21 additions & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,

/* Now, finally update getinfo's blockheight */
gossipd->ld->gossip_blockheight = ptr2int(blockheight);

/* And use that to trim old entries in the UTXO set */
wallet_utxoset_prune(gossipd->ld->wallet,
gossipd->ld->gossip_blockheight);
}

void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
Expand All @@ -247,9 +251,25 @@ static void gossipd_init_done(struct subd *gossipd,
const int *fds,
void *unused)
{
struct lightningd *ld = gossipd->ld;
u32 oldspends;

/* Any channels without channel_updates, we populate now: gossipd
* might have lost its gossip_store. */
channel_gossip_init_done(gossipd->ld);
channel_gossip_init_done(ld);

/* Tell it about any closures it might have missed! */
oldspends = wallet_utxoset_oldest_spentheight(tmpctx, ld->wallet);
if (oldspends) {
while (oldspends <= get_block_height(ld->topology)) {
const struct short_channel_id *scids;

scids = wallet_utxoset_get_spent(tmpctx, ld->wallet,
oldspends);
gossipd_notify_spends(ld, oldspends, scids);
oldspends++;
}
}

/* Break out of loop, so we can begin */
log_debug(gossipd->ld->log, "io_break: %s", __func__);
Expand Down
Loading
Loading