diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index ac5580856..fcde98ba1 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1452,6 +1452,7 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_ADDGOSSIP_REPLY: case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY: case WIRE_GOSSIPD_GET_ADDRS_REPLY: + case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE: break; } diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index f0a6a9c89..6df53358a 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -116,3 +116,9 @@ msgdata,gossipd_get_addrs,id,node_id, msgtype,gossipd_get_addrs_reply,3150 msgdata,gossipd_get_addrs_reply,num,u16, msgdata,gossipd_get_addrs_reply,addrs,wireaddr,num + +# Tell master a local channel update (so it can serve errors). +msgtype,gossipd_got_local_channel_update,3151 +msgdata,gossipd_got_local_channel_update,scid,short_channel_id, +msgdata,gossipd_got_local_channel_update,len,u16, +msgdata,gossipd_got_local_channel_update,channel_update,u8,len diff --git a/lightningd/channel.c b/lightningd/channel.c index 79eee3248..10f388672 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -253,6 +253,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->channel_update = NULL; /* Channel is connected! */ channel->connected = true; @@ -461,6 +462,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->lease_chan_max_msat = lease_chan_max_msat; channel->lease_chan_max_ppt = lease_chan_max_ppt; channel->blockheight_states = dup_height_states(channel, height_states); + channel->channel_update = NULL; list_add_tail(&peer->channels, &channel->list); channel->rr_number = peer->ld->rr_counter++; diff --git a/lightningd/channel.h b/lightningd/channel.h index 4f3fb1d28..729ac8599 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -237,6 +237,9 @@ struct channel { u32 lease_chan_max_msat; /* Lease commited max part per thousandth channel fee (ppm * 1000) */ u16 lease_chan_max_ppt; + + /* Latest channel_update, for use in error messages. */ + u8 *channel_update; }; /* For v2 opens, a channel that has not yet been committed/saved to disk */ diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 9b82d9b79..11b2463e5 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -5,10 +5,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -107,6 +109,32 @@ static void get_txout(struct subd *gossip, const u8 *msg) } } +static void handle_local_channel_update(struct lightningd *ld, const u8 *msg) +{ + struct short_channel_id scid; + u8 *update; + struct channel *channel; + + if (!fromwire_gossipd_got_local_channel_update(msg, msg, + &scid, &update)) { + fatal("Gossip gave bad GOSSIP_GOT_LOCAL_CHANNEL_UPDATE %s", + tal_hex(msg, msg)); + } + + /* In theory this could vanish before gossipd gets around to telling + * us. */ + channel = any_channel_by_scid(ld, &scid); + if (!channel) { + log_broken(ld->log, "Local update for bad scid %s", + type_to_string(tmpctx, struct short_channel_id, + &scid)); + return; + } + + tal_free(channel->channel_update); + channel->channel_update = tal_steal(channel, update); +} + static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) { enum gossipd_wire t = fromwire_peektype(msg); @@ -144,6 +172,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_GET_TXOUT: get_txout(gossip, msg); break; + case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE: + handle_local_channel_update(gossip->ld, msg); + break; } return 0; }