gossipd: infrastructure to tell lightningd about local channel updates.

We want it to keep the latest, so it can make its own error msgs without
asking us.  This installs (but does not use!) the message handler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-01-25 06:28:52 +10:30
parent a8bed542f7
commit 51d23ffcd3
5 changed files with 43 additions and 0 deletions

View File

@ -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;
}

View File

@ -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

1 #include <common/cryptomsg.h>
116
117
118
119
120
121
122
123
124

View File

@ -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++;

View File

@ -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 */

View File

@ -5,10 +5,12 @@
#include <common/json_helpers.h>
#include <common/json_tok.h>
#include <common/param.h>
#include <common/type_to_string.h>
#include <gossipd/gossipd_wiregen.h>
#include <hsmd/capabilities.h>
#include <lightningd/bitcoind.h>
#include <lightningd/chaintopology.h>
#include <lightningd/channel.h>
#include <lightningd/gossip_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/jsonrpc.h>
@ -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;
}