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

Gossip cleanup part 1: Removing reliance on private gossip messages #6869

Merged
merged 29 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dad0022
compiler: fix for -O3 errors.
rustyrussell Dec 6, 2023
522295a
common: prepare unit tests for lack of private channels.
rustyrussell Dec 6, 2023
84361ca
pytest: use wait_local_channel_active
endothermicdev Dec 6, 2023
9b34784
gossipd: correctly attribute our own channel update to ourselves
endothermicdev Dec 6, 2023
5a29dda
db: add private channel inbound fields
endothermicdev Dec 6, 2023
4dfe403
gossipd: pass remote private channel update to ld
endothermicdev Dec 6, 2023
2fa59d9
gossipd: always send information about our channels' gossip updates.
rustyrussell Dec 6, 2023
cc215c4
listpeerchannels: show gossip updates.
rustyrussell Dec 6, 2023
c0bc986
pyln-testing: when waiting for active channel, make sure remote has s…
rustyrussell Dec 6, 2023
9cb6644
gossmap: insert temporary per-caller flag to turn off private gossip.
rustyrussell Dec 6, 2023
adf5758
common: generic routine to turn listpeerchannels into gossmap local u…
rustyrussell Dec 6, 2023
53ffd08
plugins/topology: temporary hack to allow per-access private gossmap …
rustyrussell Dec 6, 2023
4a396e8
plugins/fetchinvoice: use gossmods_from_listpeerchannels instead of p…
rustyrussell Dec 13, 2023
fcc1010
libplugin-pay: make sure get_gossmap calls are balanced by put_gossmap.
rustyrussell Dec 13, 2023
2d06738
plugins/pay: use gossmods_from_listpeerchannels instead of private go…
rustyrussell Dec 13, 2023
dd3b594
common: add tests that json_scan can omit an entire object member.
rustyrussell Dec 13, 2023
88b41fe
plugins/renepay: add localmods later.
rustyrussell Dec 13, 2023
ccec35d
plugins/renepay: use gossmods_from_listpeerchannels instead of privat…
rustyrussell Dec 13, 2023
d536eeb
pytest: fix test_zeroconf_open()
rustyrussell Dec 13, 2023
08dda8d
lightningd: permit wrong-alias lookups for private channel_update.
rustyrussell Dec 13, 2023
06efdc7
lightningd: make listincoming use gossmods_from_listpeerchannels().
rustyrussell Dec 13, 2023
5a81edd
pytest: remove test waits for routehints.
rustyrussell Dec 13, 2023
da4ba26
topology: don't show private nodes in listnodes.
rustyrussell Dec 13, 2023
f6a2210
pytest: fix tests in assumption that listchannels will no longer show…
rustyrussell Dec 13, 2023
3362f74
pytest: skip test_hook_crash on liquid CI
endothermicdev Dec 13, 2023
9bf173c
topology: don't show private nodes in listchannels.
rustyrussell Dec 13, 2023
1d8f94e
common: gossmap now always ignores private gossip_store messages.
rustyrussell Dec 13, 2023
59a0479
topology: deprecate overriding `active` in `listchannels` with `listp…
rustyrussell Dec 13, 2023
406e6d0
plugins: re-enable listchannels local info in deprecated mode.
rustyrussell Dec 13, 2023
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
18 changes: 9 additions & 9 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
57 changes: 30 additions & 27 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
struct remote_priv_update remote_update;
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 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));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion gossipd/test/run-check_channel_announcement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion gossipd/test/run-txout_failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better name!

channel->channel_update = NULL;
channel->alias[LOCAL] = channel->alias[REMOTE] = NULL;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 17 additions & 15 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,20 @@ 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;

scid = channel->scid;
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));
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion wallet/test/run-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down