Skip to content

Channel gossip rework #8136

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,11 @@ static const char *process_channel_update(const tal_t *ctx,
u32 prev_timestamp
= gossip_store_get_timestamp(gm->gs, chan->cupdate_off[dir]);
if (prev_timestamp >= timestamp) {
status_trace("Too-old update for %s",
fmt_short_channel_id(tmpctx, scid));
/* Too old, ignore */
/* Don't spam the logs for duplicates! */
if (timestamp < prev_timestamp)
status_trace("Too-old update for %s",
fmt_short_channel_id(tmpctx, scid));
/* Too old / redundant, ignore */
return NULL;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ static void updates_complete(struct chain_topology *topo)
{
if (!bitcoin_blkid_eq(&topo->tip->blkid, &topo->prev_tip)) {
/* Tell lightningd about new block. */
notify_new_block(topo->bitcoind->ld, topo->tip->height);
notify_new_block(topo->bitcoind->ld);

/* Tell watch code to re-evaluate all txs. */
watch_topology_changed(topo);
Expand All @@ -840,7 +840,7 @@ static void updates_complete(struct chain_topology *topo)

/* Send out an account balance snapshot */
if (!first_update_complete) {
send_account_balance_snapshot(topo->ld, topo->tip->height);
send_account_balance_snapshot(topo->ld);
first_update_complete = true;
}
}
Expand Down
23 changes: 23 additions & 0 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,29 @@ static inline bool channel_state_failing_onchain(enum channel_state state)
abort();
}

static inline bool channel_state_funding_spent_onchain(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case AWAITING_UNILATERAL:
return false;
case CLOSED:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
return true;
}
abort();
}

static inline bool channel_state_pre_open(enum channel_state state)
{
switch (state) {
Expand Down
23 changes: 11 additions & 12 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ static void try_update_feerates(struct lightningd *ld, struct channel *channel)
}

static void try_update_blockheight(struct lightningd *ld,
struct channel *channel,
u32 blockheight)
struct channel *channel)
{
u32 blockheight = get_block_height(ld->topology);
u8 *msg;

/* We don't update the blockheight for non-leased chans */
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void lockin_has_completed(struct channel *channel, bool record_push)
* so update now. */
try_update_feerates(ld, channel);

try_update_blockheight(ld, channel, get_block_height(ld->topology));
try_update_blockheight(ld, channel);

/* Emit an event for the channel open (or channel proposal if blockheight
* is zero) */
Expand Down Expand Up @@ -1878,8 +1878,7 @@ bool peer_start_channeld(struct channel *channel,
* might not be what we expect: adjust now. */
if (channel->opener == LOCAL) {
try_update_feerates(ld, channel);
try_update_blockheight(ld, channel,
get_block_height(ld->topology));
try_update_blockheight(ld, channel);
}

/* "Reestablished" if we've just opened. */
Expand Down Expand Up @@ -1925,9 +1924,10 @@ void channeld_tell_depth(struct channel *channel,
* If so, we should forget the channel. */
static bool
is_fundee_should_forget(struct lightningd *ld,
struct channel *channel,
u32 block_height)
struct channel *channel)
{
u32 block_height = get_block_height(ld->topology);

/* BOLT #2:
*
* A non-funding node (fundee):
Expand Down Expand Up @@ -1967,9 +1967,9 @@ is_fundee_should_forget(struct lightningd *ld,
}

/* Notify all channels of new blocks. */
void channel_notify_new_block(struct lightningd *ld,
u32 block_height)
void channel_notify_new_block(struct lightningd *ld)
{
u32 block_height = get_block_height(ld->topology);
struct peer *peer;
struct channel *channel;
struct channel **to_forget = tal_arr(NULL, struct channel *, 0);
Expand All @@ -1983,13 +1983,12 @@ void channel_notify_new_block(struct lightningd *ld,
list_for_each(&peer->channels, channel, list) {
if (channel_state_uncommitted(channel->state))
continue;
if (is_fundee_should_forget(ld, channel, block_height)) {
if (is_fundee_should_forget(ld, channel)) {
tal_arr_expand(&to_forget, channel);
} else
/* Let channels know about new blocks,
* required for lease updates */
try_update_blockheight(ld, channel,
block_height);
try_update_blockheight(ld, channel);
}
}

Expand Down
3 changes: 1 addition & 2 deletions lightningd/channel_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ void channeld_tell_depth(struct channel *channel,
u32 depth);

/* Notify channels of new blocks. */
void channel_notify_new_block(struct lightningd *ld,
u32 block_height);
void channel_notify_new_block(struct lightningd *ld);

/* Cancel the channel after `fundchannel_complete` succeeds
* but before funding broadcasts. */
Expand Down
Loading
Loading