gossipd: always send information about our channels' gossip updates.

Not just when it's a private channel.  This is useful for listpeerchannels in the next patch.
Most of this is renaming.

It also means that source can be NULL, so move it out of the struct and put it in the message,
where it logically belongs, and make it an optional field.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-12-07 06:44:05 +10:30
parent 8e897746e2
commit 5583f730de
9 changed files with 72 additions and 68 deletions

View file

@ -137,15 +137,15 @@ msgdata,gossipd_used_local_channel_update,scid,short_channel_id,
msgtype,gossipd_discovered_ip,3009
msgdata,gossipd_discovered_ip,discovered_ip,wireaddr,
subtype,remote_priv_update
subtypedata,remote_priv_update,source_node,node_id,
subtypedata,remote_priv_update,scid,short_channel_id,
subtypedata,remote_priv_update,fee_base,u32,
subtypedata,remote_priv_update,fee_ppm,u32,
subtypedata,remote_priv_update,cltv_delta,u16,
subtypedata,remote_priv_update,htlc_minimum_msat,amount_msat,
subtypedata,remote_priv_update,htlc_maximum_msat,amount_msat,
subtype,peer_update
subtypedata,peer_update,scid,short_channel_id,
subtypedata,peer_update,fee_base,u32,
subtypedata,peer_update,fee_ppm,u32,
subtypedata,peer_update,cltv_delta,u16,
subtypedata,peer_update,htlc_minimum_msat,amount_msat,
subtypedata,peer_update,htlc_maximum_msat,amount_msat,
# Tell lightningd we received channel update info for a local channel
msgtype,gossipd_remote_channel_update,3010
msgdata,gossipd_remote_channel_update,update,remote_priv_update,
msgdata,gossipd_remote_channel_update,source_node,?node_id,
msgdata,gossipd_remote_channel_update,peer_update,peer_update,

1 #include <common/cryptomsg.h>
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

View file

@ -1348,25 +1348,24 @@ static bool is_chan_dying(struct routing_state *rstate,
return false;
}
static void tell_lightningd_private_update(struct routing_state *rstate,
const struct node_id *source_peer,
struct short_channel_id scid,
u32 fee_base_msat,
u32 fee_ppm,
u16 cltv_delta,
struct amount_msat htlc_minimum,
struct amount_msat htlc_maximum)
static void tell_lightningd_peer_update(struct routing_state *rstate,
const struct node_id *source_peer,
struct short_channel_id scid,
u32 fee_base_msat,
u32 fee_ppm,
u16 cltv_delta,
struct amount_msat htlc_minimum,
struct amount_msat htlc_maximum)
{
struct remote_priv_update remote_update;
struct peer_update remote_update;
u8* msg;
remote_update.source_node = *source_peer;
remote_update.scid = scid;
remote_update.fee_base = fee_base_msat;
remote_update.fee_ppm = fee_ppm;
remote_update.cltv_delta = cltv_delta;
remote_update.htlc_minimum_msat = htlc_minimum;
remote_update.htlc_maximum_msat = htlc_maximum;
msg = towire_gossipd_remote_channel_update(NULL, &remote_update);
msg = towire_gossipd_remote_channel_update(NULL, source_peer, &remote_update);
daemon_conn_send(rstate->daemon->master, take(msg));
}
@ -1425,13 +1424,11 @@ bool routing_add_channel_update(struct routing_state *rstate,
if (index)
return false;
/* Allow ld to process a private channel update */
if (source_peer) {
tell_lightningd_private_update(rstate, source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum);
}
tell_lightningd_peer_update(rstate, source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum);
return false;
}
sat = uc->sat;
@ -1542,6 +1539,20 @@ bool routing_add_channel_update(struct routing_state *rstate,
if (!spam)
hc->bcast.timestamp = timestamp;
/* If this is a peer's update to one of our local channels, tell lightningd. */
if (node_id_eq(&chan->nodes[!direction]->id, &rstate->daemon->id)) {
/* give lightningd the channel's inbound info to store to db */
tell_lightningd_peer_update(rstate,
/* Note: we can get public
* channel_updates from other than
* direct peer! */
is_chan_public(chan) ? NULL : source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum);
}
/* BOLT #7:
* - MUST consider the `timestamp` of the `channel_announcement` to be
* the `timestamp` of a corresponding `channel_update`.
@ -1569,14 +1580,6 @@ bool routing_add_channel_update(struct routing_state *rstate,
hc->bcast.index = index;
hc->rgraph.index = index;
}
if (source_peer) {
/* give lightningd the channel's inbound info to store to db */
tell_lightningd_private_update(rstate, source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum);
}
return true;
}

View file

@ -137,7 +137,7 @@ void status_fmt(enum log_level level UNNEEDED,
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_remote_channel_update */
u8 *towire_gossipd_remote_channel_update(const tal_t *ctx UNNEEDED, const struct remote_priv_update *update UNNEEDED)
u8 *towire_gossipd_remote_channel_update(const tal_t *ctx UNNEEDED, const struct node_id *source_node UNNEEDED, const struct peer_update *peer_update UNNEEDED)
{ fprintf(stderr, "towire_gossipd_remote_channel_update called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

View file

@ -103,7 +103,7 @@ void status_fmt(enum log_level level UNNEEDED,
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_remote_channel_update */
u8 *towire_gossipd_remote_channel_update(const tal_t *ctx UNNEEDED, const struct remote_priv_update *update UNNEEDED)
u8 *towire_gossipd_remote_channel_update(const tal_t *ctx UNNEEDED, const struct node_id *source_node UNNEEDED, const struct peer_update *peer_update UNNEEDED)
{ fprintf(stderr, "towire_gossipd_remote_channel_update called!\n"); abort(); }
/* Generated stub for towire_warningfmt */
u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,

View file

@ -264,7 +264,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
= CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE;
channel->shutdown_wrong_funding = NULL;
channel->closing_feerate_range = NULL;
channel->private_update = NULL;
channel->peer_update = NULL;
channel->channel_update = NULL;
channel->alias[LOCAL] = channel->alias[REMOTE] = NULL;
@ -430,7 +430,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
struct amount_msat htlc_maximum_msat,
bool ignore_fee_limits,
/* NULL or stolen */
struct remote_priv_update *private_update STEALS)
struct peer_update *peer_update STEALS)
{
struct channel *channel = tal(peer->ld, struct channel);
struct amount_msat htlc_min, htlc_max;
@ -556,7 +556,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->lease_commit_sig = tal_steal(channel, lease_commit_sig);
channel->lease_chan_max_msat = lease_chan_max_msat;
channel->lease_chan_max_ppt = lease_chan_max_ppt;
channel->private_update = tal_steal(channel, private_update);
channel->peer_update = tal_steal(channel, peer_update);
channel->blockheight_states = dup_height_states(channel, height_states);
channel->channel_update = NULL;

View file

@ -298,9 +298,9 @@ struct channel {
/* Lease commited max part per thousandth channel fee (ppm * 1000) */
u16 lease_chan_max_ppt;
/* Private channel incoming fee rates, cltv delta min/max htlc from
/* Channel incoming fee rates, cltv delta min/max htlc from
* peer. Used to generate route hints, blinded paths. */
struct remote_priv_update *private_update;
const struct peer_update *peer_update;
/* Latest channel_update, for use in error messages. */
u8 *channel_update;
@ -390,7 +390,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
struct amount_msat htlc_maximum_msat,
bool ignore_fee_limits,
/* NULL or stolen */
struct remote_priv_update *private_update STEALS);
struct peer_update *peer_update STEALS);
/* new_inflight - Create a new channel_inflight for a channel */
struct channel_inflight *new_inflight(struct channel *channel,

View file

@ -175,7 +175,8 @@ const u8 *get_channel_update(struct channel *channel)
static void set_channel_remote_update(struct lightningd *ld,
struct channel *channel,
struct remote_priv_update* update TAKES)
const struct node_id *source,
struct peer_update *update TAKES)
{
struct short_channel_id *scid;
@ -183,11 +184,11 @@ static void set_channel_remote_update(struct lightningd *ld,
if (!scid)
scid = channel->alias[LOCAL];
if (!node_id_eq(&update->source_node, &channel->peer->id)) {
/* NULL source means it's from gossipd itself */
if (source && !node_id_eq(source, &channel->peer->id)) {
log_unusual(ld->log, "Bad gossip order: %s sent us a channel update for a "
"channel owned by %s (%s)",
type_to_string(tmpctx, struct node_id,
&update->source_node),
type_to_string(tmpctx, struct node_id, source),
type_to_string(tmpctx, struct node_id,
&channel->peer->id),
type_to_string(tmpctx, struct short_channel_id, scid));
@ -197,31 +198,32 @@ static void set_channel_remote_update(struct lightningd *ld,
}
log_debug(ld->log, "updating channel %s with private inbound settings",
type_to_string(tmpctx, struct short_channel_id, scid));
tal_free(channel->private_update);
channel->private_update = tal_dup(channel,
struct remote_priv_update, update);
tal_free(channel->peer_update);
channel->peer_update = tal_dup(channel, struct peer_update, update);
if (taken(update))
tal_free(update);
wallet_channel_save(ld->wallet, channel);
}
static void handle_private_update_data(struct lightningd *ld, const u8 *msg)
static void handle_peer_update_data(struct lightningd *ld, const u8 *msg)
{
struct channel *channel;
struct remote_priv_update *update;
struct peer_update *update;
struct node_id *source;
update = tal(tmpctx, struct remote_priv_update);
if (!fromwire_gossipd_remote_channel_update(msg, update))
update = tal(tmpctx, struct peer_update);
if (!fromwire_gossipd_remote_channel_update(msg, msg, &source, update))
fatal("Gossip gave bad GOSSIPD_REMOTE_CHANNEL_UPDATE %s",
tal_hex(msg, msg));
channel = any_channel_by_scid(ld, &update->scid, true);
if (!channel) {
log_unusual(ld->log, "could not find channel for peer's "
"private channel update");
log_unusual(ld->log, "Bad gossip: could not find channel %s for peer's "
"channel update",
short_channel_id_to_str(tmpctx, &update->scid));
return;
}
set_channel_remote_update(ld, channel, update);
set_channel_remote_update(ld, channel, source, update);
}
static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
@ -267,7 +269,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
break;
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
/* Please stash in database for us! */
handle_private_update_data(gossip->ld, msg);
handle_peer_update_data(gossip->ld, msg);
tal_free(msg);
break;
}

View file

@ -178,7 +178,7 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
struct amount_msat htlc_maximum_msat UNNEEDED,
bool ignore_fee_limits UNNEEDED,
/* NULL or stolen */
struct remote_priv_update* remote_update STEALS UNNEEDED)
struct peer_update *peer_update STEALS UNNEEDED)
{ fprintf(stderr, "new_channel called!\n"); abort(); }
/* Generated stub for new_coin_wallet_deposit */
struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED,

View file

@ -1514,7 +1514,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
u32 lease_chan_max_msat;
u16 lease_chan_max_ppt;
bool ignore_fee_limits;
struct remote_priv_update *remote_update;
struct peer_update *remote_update;
peer_dbid = db_col_u64(stmt, "peer_id");
peer = find_peer_by_dbid(w->ld, peer_dbid);
@ -1680,8 +1680,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
}
if (!db_col_is_null(stmt, "remote_cltv_expiry_delta")) {
remote_update = tal(NULL, struct remote_priv_update);
remote_update->source_node = peer->id;
remote_update = tal(NULL, struct peer_update);
if (scid)
remote_update->scid = *scid;
else
@ -2354,12 +2353,12 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
db_bind_null(stmt);
db_bind_int(stmt, chan->ignore_fee_limits);
if (chan->private_update) {
db_bind_int(stmt, chan->private_update->fee_base);
db_bind_int(stmt, chan->private_update->fee_ppm);
db_bind_int(stmt, chan->private_update->cltv_delta);
db_bind_amount_msat(stmt, &chan->private_update->htlc_minimum_msat);
db_bind_amount_msat(stmt, &chan->private_update->htlc_maximum_msat);
if (chan->peer_update) {
db_bind_int(stmt, chan->peer_update->fee_base);
db_bind_int(stmt, chan->peer_update->fee_ppm);
db_bind_int(stmt, chan->peer_update->cltv_delta);
db_bind_amount_msat(stmt, &chan->peer_update->htlc_minimum_msat);
db_bind_amount_msat(stmt, &chan->peer_update->htlc_maximum_msat);
} else {
db_bind_null(stmt);
db_bind_null(stmt);