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
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
13 changes: 13 additions & 0 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ 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,

# 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,
40 changes: 39 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 @@ -1347,6 +1348,28 @@ 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;
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);
daemon_conn_send(rstate->daemon->master, take(msg));
}

bool routing_add_channel_update(struct routing_state *rstate,
const u8 *update TAKES,
u32 index,
Expand Down Expand Up @@ -1398,6 +1421,14 @@ 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);
return false;
}
sat = uc->sat;
Expand Down Expand Up @@ -1533,6 +1564,14 @@ bool routing_add_channel_update(struct routing_state *rstate,
hc->bcast.index = index;
hc->rgraph.index = index;
}
if (!source_peer)
return true;
endothermicdev marked this conversation as resolved.
Show resolved Hide resolved
/* 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 Expand Up @@ -2338,4 +2377,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
51 changes: 51 additions & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/type_to_string.h>
#include <gossipd/gossipd_wiregen.h>
#include <hsmd/permissions.h>
Expand Down Expand Up @@ -172,6 +173,51 @@ const u8 *get_channel_update(struct channel *channel)
return channel->channel_update;
}

static void set_channel_remote_update(struct lightningd *ld,
struct channel *channel,
struct remote_priv_update* update TAKES)
{
if (!node_id_eq(&update->source_node, &channel->peer->id)) {
log_unusual(ld->log, "%s sent us a channel update for a "
"channel they don't own (%s)",
type_to_string(tmpctx, struct node_id,
&update->source_node),
type_to_string(tmpctx, struct short_channel_id,
channel->scid));
if (taken(update))
tal_free(update);
return;
}
/* log_debug(ld->log, "updating channel %s with inbound settings",
* type_to_string(tmpctx, struct short_channel_id,
* channel->scid)); */
tal_free(channel->private_update);
channel->private_update = tal_dup(channel,
struct remote_priv_update, update);
if (taken(update))
tal_free(update);
wallet_channel_save(ld->wallet, channel);
rustyrussell marked this conversation as resolved.
Show resolved Hide resolved
}

static void handle_private_update_data(struct lightningd *ld, const u8 *msg)
{
struct channel *channel;
struct remote_priv_update *update;

update = tal(tmpctx, struct remote_priv_update);
if (!fromwire_gossipd_remote_channel_update(msg, 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 "
Copy link
Contributor

Choose a reason for hiding this comment

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

log the update source (which peer) and scid?

Copy link
Contributor

Choose a reason for hiding this comment

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

log_peer_unusual(ld->log, &update->source_node, "Could not find channel %s for peer's channel_update", type_to_string(tmpctx, struct short_channel_id, &update->scid));

"channel update");
return;
}

set_channel_remote_update(ld, channel, update);
}

static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
{
enum gossipd_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -213,6 +259,11 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE:
handle_local_channel_update(gossip->ld, msg);
break;
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
/* Please stash in database for us! */
handle_private_update_data(gossip->ld, msg);
tal_free(msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't tal_free(msg), it belongs to the caller (and nobody else does!).

break;
}
return 0;
}
Expand Down