From 1a3ed1895909416d7c10fbc51f1bb375d991825a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 18 Feb 2020 10:31:58 +1030 Subject: [PATCH] channeld: add routing to get our own channel's channel_update. We'll use this in the next patch for when we need to create errors to send back to lightningd; most commonly when the channel doesn't have capacity for the HTLC. Signed-off-by: Rusty Russell --- channeld/channeld.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/channeld/channeld.c b/channeld/channeld.c index bc03cad54..a17369d9c 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -307,6 +307,28 @@ static void send_channel_update(struct peer *peer, int disable_flag) wire_sync_write(peer->pps->gossip_fd, take(msg)); } +/* Get the latest channel update for this channel from gossipd */ +static NEEDED const u8 *get_local_channel_update(const tal_t *ctx, struct peer *peer) +{ + const u8 *msg; + + msg = towire_gossipd_get_update(NULL, &peer->short_channel_ids[LOCAL]); + wire_sync_write(peer->pps->gossip_fd, take(msg)); + + /* Wait for reply to come back; handle other gossipd msgs meanwhile */ + while ((msg = wire_sync_read(tmpctx, peer->pps->gossip_fd)) != NULL) { + u8 *update; + if (fromwire_gossipd_get_update_reply(ctx, msg, &update)) + return update; + + handle_gossip_msg(peer->pps, take(msg)); + } + + /* Gossipd hangs up on us to kill us when a new + * connection comes in. */ + peer_failed_connection_lost(); +} + /** * Add a channel locally and send a channel update to the peer *