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

Merged
5 changes: 3 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -4788,7 +4788,8 @@ static void peer_in(struct peer *peer, const u8 *msg)
check_tx_abort(peer, msg, NULL);

/* If we're in STFU mode and aren't waiting for a STFU mode
* specific message, the only valid message was tx_abort */
* specific message, the only valid message was tx_abort (or a
* belated announcement_signatures!) */
if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) {
if (peer->splicing && type == WIRE_TX_SIGNATURES) {
if (peer->splicing->tx_sig_msg)
Expand All @@ -4798,7 +4799,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
peer->splicing->tx_sig_msg = tal_steal(peer->splicing,
msg);
return;
} else {
} else if (type != WIRE_ANNOUNCEMENT_SIGNATURES) {
peer_failed_warn(peer->pps, &peer->channel_id,
"Received message %s when only TX_ABORT was"
" valid", peer_wire_name(type));
Expand Down
4 changes: 2 additions & 2 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ receive_offer(struct per_peer_state *pps,
*/
else if (fromwire_peektype(msg) == WIRE_SHUTDOWN)
msg = tal_free(msg);
/* channeld may have sent ping: ignore pong! */
else if (fromwire_peektype(msg) == WIRE_PONG)
/* We can get announcement signatures: too late! */
else if (fromwire_peektype(msg) == WIRE_ANNOUNCEMENT_SIGNATURES)
msg = tal_free(msg);
} while (!msg);

Expand Down
8 changes: 5 additions & 3 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,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 @@ -822,7 +822,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 @@ -838,7 +838,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
2 changes: 0 additions & 2 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ struct channel *new_unsaved_channel(struct peer *peer,
/* Nothing happened yet */
memset(&channel->stats, 0, sizeof(channel->stats));
channel->state_changes = tal_arr(channel, struct channel_state_change *, 0);
channel->replied_to_announcement_sigs = false;

/* No shachain yet */
channel->their_shachain.id = 0;
Expand Down Expand Up @@ -633,7 +632,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->num_onchain_spent_calls = 0;
channel->stats = *stats;
channel->state_changes = tal_steal(channel, state_changes);
channel->replied_to_announcement_sigs = false;

/* Populate channel->channel_gossip */
channel_gossip_init(channel, take(peer_update));
Expand Down
26 changes: 23 additions & 3 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ struct channel {

/* Our change history. */
struct channel_state_change **state_changes;

/* Have we replied to announcement_signatures once? */
bool replied_to_announcement_sigs;
};

/* Is channel owned (and should be talking to peer) */
Expand Down Expand Up @@ -610,6 +607,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
22 changes: 10 additions & 12 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,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 @@ -1030,7 +1030,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 @@ -1899,8 +1899,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 @@ -1946,9 +1945,9 @@ 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);
/* 2016 by default */
u32 max_funding_unconfirmed = ld->dev_max_funding_unconfirmed;

Expand Down Expand Up @@ -1992,8 +1991,7 @@ static int cmp_channel_start(struct channel *const *a, struct channel *const *b,
}

/* 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)
{
struct peer *peer;
struct channel *channel;
Expand Down Expand Up @@ -2024,12 +2022,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);

/* Let channels know about new blocks,
* required for lease updates */
try_update_blockheight(ld, channel, block_height);
try_update_blockheight(ld, channel);
}
}

Expand All @@ -2055,7 +2053,7 @@ void channel_notify_new_block(struct lightningd *ld,
"confirmed. "
"We are fundee and can forget channel without "
"loss of funds.",
block_height - channel->first_blocknum,
get_block_height(ld->topology) - channel->first_blocknum,
fmt_bitcoin_txid(tmpctx, &channel->funding.txid));
/* FIXME: Send an error packet for this case! */
/* And forget it. COMPLETELY. */
Expand Down
3 changes: 1 addition & 2 deletions lightningd/channel_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,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