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 split #6355

Closed
6 changes: 6 additions & 0 deletions contrib/pyln-testing/pyln/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ def has_funds_on_addr(addr):
if wait_for_active:
self.wait_local_channel_active(scid)
l2.wait_local_channel_active(scid)
wait_for(lambda: len(self.rpc.listprivateinbound()['private_channels']) > 0)
wait_for(lambda: any('short_channel_id' in c for c in self.rpc.listpeerchannels()['channels']))
wait_for(lambda: any('short_channel_id' in c for c in l2.rpc.listpeerchannels()['channels']))

return scid, res

Expand Down Expand Up @@ -1613,6 +1616,9 @@ def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_an
for i, n in enumerate(scids):
nodes[i].wait_local_channel_active(scids[i])
nodes[i + 1].wait_local_channel_active(scids[i])
wait_for(lambda: len(nodes[i].rpc.listprivateinbound()['private_channels']) > 0)
wait_for(lambda: any('short_channel_id' in c for c in nodes[i].rpc.listpeerchannels()['channels']))
wait_for(lambda: any('short_channel_id' in c for c in nodes[i + 1].rpc.listpeerchannels()['channels']))

if not wait_for_announce:
return
Expand Down
2 changes: 1 addition & 1 deletion gossipd/gossip_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ static void apply_update(struct daemon *daemon,
take(update);
}

msg = handle_channel_update(daemon->rstate, update, &chan->nodes[!direction]->id, NULL, true);
msg = handle_channel_update(daemon->rstate, update, &chan->nodes[direction]->id, NULL, true);
if (msg)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"%s: rejected local channel update %s: %s",
Expand Down
1 change: 1 addition & 0 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE:
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
break;
}

Expand Down
15 changes: 15 additions & 0 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,18 @@ msgdata,gossipd_used_local_channel_update,scid,short_channel_id,
# Tell gossipd we have verified a new public IP by the remote_addr feature
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,
subtypedata,remote_priv_update,channel_flags,u8,
subtypedata,remote_priv_update,timestamp,u32,

# 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,
53 changes: 52 additions & 1 deletion gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <bitcoin/script.h>
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <common/daemon_conn.h>
#include <common/gossip_store.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
Expand Down Expand Up @@ -912,6 +913,32 @@ static void remove_channel_from_store(struct routing_state *rstate,
delete_chan_messages_from_store(rstate, chan);
}

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,
u8 channel_flags,
u32 timestamp)
{
struct remote_priv_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;
remote_update.channel_flags = channel_flags;
remote_update.timestamp = timestamp;
msg = towire_gossipd_remote_channel_update(NULL, &remote_update);
daemon_conn_send(rstate->daemon->master, take(msg));
}

bool routing_add_channel_announcement(struct routing_state *rstate,
const u8 *msg TAKES,
struct amount_sat sat,
Expand Down Expand Up @@ -1006,6 +1033,11 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
delete_chan_messages_from_store(rstate, oldchan);
free_chans_from_node(rstate, oldchan);
tal_free(oldchan);
/* Effectively delete private update from db */
tell_lightningd_private_update(rstate, &node_id_1, scid,
0, 0, 0, amount_msat(0), amount_msat(0), 0, 0);
tell_lightningd_private_update(rstate, &node_id_2, scid,
0, 0, 0, amount_msat(0), amount_msat(0), 0, 0);
Comment on lines +1036 to +1040
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary? Once the channel is no longer private, this information is irrelevant, but in the meantime it's better than nothing.

}

return true;
Expand Down Expand Up @@ -1398,6 +1430,15 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* Maybe announcement was waiting for this update? */
uc = get_unupdated_channel(rstate, &short_channel_id);
if (!uc) {
if (index)
return false;
/* Allow ld to process a private channel update */
tell_lightningd_private_update(rstate, source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum,
channel_flags, timestamp);
return false;
}
sat = uc->sat;
Expand Down Expand Up @@ -1529,10 +1570,21 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* No need to separately track spam for private
* channels. */
hc->rgraph.index = hc->bcast.index;
/* give lightningd the channel's inbound info to
* store to db */
/* FIXME: Validate this is peer's and not our own */
tell_lightningd_private_update(rstate, source_peer,
short_channel_id, fee_base_msat,
fee_proportional_millionths,
expiry, htlc_minimum,
htlc_maximum,
channel_flags, timestamp);
} else {
hc->bcast.index = index;
hc->rgraph.index = index;
}
if (!source_peer)
return true;
return true;
}

Expand Down Expand Up @@ -2338,4 +2390,3 @@ void routing_channel_spent(struct routing_state *rstate,
type_to_string(msg, struct short_channel_id, &chan->scid));
remember_chan_dying(rstate, &chan->scid, deadline, index);
}

6 changes: 6 additions & 0 deletions gossipd/test/run-check_channel_announcement.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
const struct half_chan *hc UNNEEDED,
const u8 *cupdate UNNEEDED)
{ fprintf(stderr, "cupdate_different called!\n"); abort(); }
/* Generated stub for daemon_conn_send */
void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "daemon_conn_send called!\n"); abort(); }
/* Generated stub for gossip_store_add */
u64 gossip_store_add(struct gossip_store *gs UNNEEDED, const u8 *gossip_msg UNNEEDED,
u32 timestamp UNNEEDED, bool zombie UNNEEDED, bool spam UNNEEDED, bool dying UNNEEDED,
Expand Down Expand Up @@ -133,6 +136,9 @@ void status_fmt(enum log_level level UNNEEDED,
const char *fmt 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)
{ fprintf(stderr, "towire_gossipd_remote_channel_update called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

int main(int argc, char *argv[])
Expand Down
6 changes: 6 additions & 0 deletions gossipd/test/run-txout_failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
const struct half_chan *hc UNNEEDED,
const u8 *cupdate UNNEEDED)
{ fprintf(stderr, "cupdate_different called!\n"); abort(); }
/* Generated stub for daemon_conn_send */
void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "daemon_conn_send called!\n"); abort(); }
/* Generated stub for gossip_store_add */
u64 gossip_store_add(struct gossip_store *gs UNNEEDED, const u8 *gossip_msg UNNEEDED,
u32 timestamp UNNEEDED, bool zombie UNNEEDED, bool spam UNNEEDED, bool dying UNNEEDED,
Expand Down Expand Up @@ -99,6 +102,9 @@ void status_fmt(enum log_level level UNNEEDED,
const char *fmt 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)
{ fprintf(stderr, "towire_gossipd_remote_channel_update called!\n"); abort(); }
/* Generated stub for towire_warningfmt */
u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
Expand Down
9 changes: 8 additions & 1 deletion lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ 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->local_private_update = NULL;
channel->channel_update = NULL;
channel->alias[LOCAL] = channel->alias[REMOTE] = NULL;

Expand Down Expand Up @@ -405,7 +407,10 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u16 lease_chan_max_ppt,
struct amount_msat htlc_minimum_msat,
struct amount_msat htlc_maximum_msat,
bool ignore_fee_limits)
bool ignore_fee_limits,
/* NULL or stolen */
struct remote_priv_update *private_update STEALS,
struct remote_priv_update *local_private_update STEALS)
{
struct channel *channel = tal(peer->ld, struct channel);
struct amount_msat htlc_min, htlc_max;
Expand Down Expand Up @@ -530,6 +535,8 @@ 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->local_private_update = tal_steal(channel, local_private_update);
channel->blockheight_states = dup_height_states(channel, height_states);
channel->channel_update = NULL;

Expand Down
14 changes: 13 additions & 1 deletion lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <common/scb_wiregen.h>
#include <common/tx_roles.h>
#include <common/utils.h>
#include <gossipd/gossipd_wiregen.h>
#include <lightningd/channel_state.h>
#include <wallet/wallet.h>

Expand Down Expand Up @@ -282,6 +283,14 @@ 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
* peer. Used to generate route hints, blinded paths. */
struct remote_priv_update *private_update;

/* This information allows our local private channel update to
* be replicated by listchannels until deprectated. */
struct remote_priv_update *local_private_update;

/* Latest channel_update, for use in error messages. */
u8 *channel_update;

Expand Down Expand Up @@ -368,7 +377,10 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u16 lease_chan_max_ppt,
struct amount_msat htlc_minimum_msat,
struct amount_msat htlc_maximum_msat,
bool ignore_fee_limits);
bool ignore_fee_limits,
/* NULL or stolen */
struct remote_priv_update *private_update STEALS,
struct remote_priv_update *local_private_update STEALS);

/* new_inflight - Create a new channel_inflight for a channel */
struct channel_inflight *new_inflight(struct channel *channel,
Expand Down
Loading