mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
channeld: send channel updates and announcements via lightningd.
We're weaning per-peer daemons off having a direct gossipd connection. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <lightningd/closing_control.h>
|
||||
#include <lightningd/coin_mvts.h>
|
||||
#include <lightningd/dual_open_control.h>
|
||||
#include <lightningd/gossip_control.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
@@ -412,6 +413,23 @@ static void handle_error_channel(struct channel *channel,
|
||||
forget(channel);
|
||||
}
|
||||
|
||||
static void handle_local_private_channel(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
struct amount_sat capacity;
|
||||
u8 *features;
|
||||
|
||||
if (!fromwire_channeld_local_private_channel(msg, msg, &capacity,
|
||||
&features)) {
|
||||
channel_internal_error(channel,
|
||||
"bad channeld_local_private_channel %s",
|
||||
tal_hex(channel, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
tell_gossipd_local_private_channel(channel->peer->ld, channel,
|
||||
capacity, features);
|
||||
}
|
||||
|
||||
static void forget_channel(struct channel *channel, const char *why)
|
||||
{
|
||||
channel->error = towire_errorfmt(channel, &channel->cid, "%s", why);
|
||||
@@ -508,6 +526,15 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||
/* This tells gossipd we used it. */
|
||||
get_channel_update(sd->channel);
|
||||
break;
|
||||
case WIRE_CHANNELD_LOCAL_CHANNEL_UPDATE:
|
||||
tell_gossipd_local_channel_update(sd->ld, sd->channel, msg);
|
||||
break;
|
||||
case WIRE_CHANNELD_LOCAL_CHANNEL_ANNOUNCEMENT:
|
||||
tell_gossipd_local_channel_announce(sd->ld, sd->channel, msg);
|
||||
break;
|
||||
case WIRE_CHANNELD_LOCAL_PRIVATE_CHANNEL:
|
||||
handle_local_private_channel(sd->channel, msg);
|
||||
break;
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
case WIRE_CHANNELD_UPGRADED:
|
||||
handle_channel_upgrade(sd->channel, msg);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/ptrint/ptrint.h>
|
||||
#include <channeld/channeld_wiregen.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_helpers.h>
|
||||
#include <common/json_tok.h>
|
||||
@@ -167,6 +168,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
|
||||
case WIRE_GOSSIPD_ADDGOSSIP:
|
||||
case WIRE_GOSSIPD_GET_ADDRS:
|
||||
case WIRE_GOSSIPD_USED_LOCAL_CHANNEL_UPDATE:
|
||||
case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE:
|
||||
case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT:
|
||||
case WIRE_GOSSIPD_LOCAL_PRIVATE_CHANNEL:
|
||||
/* This is a reply, so never gets through to here. */
|
||||
case WIRE_GOSSIPD_INIT_REPLY:
|
||||
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:
|
||||
@@ -278,6 +282,85 @@ void gossipd_notify_spend(struct lightningd *ld,
|
||||
subd_send_msg(ld->gossip, msg);
|
||||
}
|
||||
|
||||
/* We unwrap, add the peer id, and send to gossipd. */
|
||||
void tell_gossipd_local_channel_update(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
const u8 *msg)
|
||||
{
|
||||
struct short_channel_id scid;
|
||||
bool disable;
|
||||
u16 cltv_expiry_delta;
|
||||
struct amount_msat htlc_minimum_msat;
|
||||
u32 fee_base_msat, fee_proportional_millionths;
|
||||
struct amount_msat htlc_maximum_msat;
|
||||
|
||||
if (!fromwire_channeld_local_channel_update(msg, &scid, &disable,
|
||||
&cltv_expiry_delta,
|
||||
&htlc_minimum_msat,
|
||||
&fee_base_msat,
|
||||
&fee_proportional_millionths,
|
||||
&htlc_maximum_msat)) {
|
||||
channel_internal_error(channel,
|
||||
"bad channeld_local_channel_update %s",
|
||||
tal_hex(channel, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
/* As we're shutting down, ignore */
|
||||
if (!ld->gossip)
|
||||
return;
|
||||
|
||||
subd_send_msg(ld->gossip,
|
||||
take(towire_gossipd_local_channel_update
|
||||
(NULL,
|
||||
&channel->peer->id,
|
||||
&scid,
|
||||
disable,
|
||||
cltv_expiry_delta,
|
||||
htlc_minimum_msat,
|
||||
fee_base_msat,
|
||||
fee_proportional_millionths, htlc_maximum_msat)));
|
||||
}
|
||||
|
||||
void tell_gossipd_local_channel_announce(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
const u8 *msg)
|
||||
{
|
||||
u8 *ann;
|
||||
if (!fromwire_channeld_local_channel_announcement(msg, msg, &ann)) {
|
||||
channel_internal_error(channel,
|
||||
"bad channeld_local_channel_announcement"
|
||||
" %s",
|
||||
tal_hex(channel, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
/* As we're shutting down, ignore */
|
||||
if (!ld->gossip)
|
||||
return;
|
||||
|
||||
subd_send_msg(ld->gossip,
|
||||
take(towire_gossipd_local_channel_announcement
|
||||
(NULL, &channel->peer->id, ann)));
|
||||
}
|
||||
|
||||
void tell_gossipd_local_private_channel(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
struct amount_sat capacity,
|
||||
const u8 *features)
|
||||
{
|
||||
/* As we're shutting down, ignore */
|
||||
if (!ld->gossip)
|
||||
return;
|
||||
|
||||
subd_send_msg(ld->gossip,
|
||||
take(towire_gossipd_local_private_channel
|
||||
(NULL, &channel->peer->id,
|
||||
capacity,
|
||||
channel->scid,
|
||||
features)));
|
||||
}
|
||||
|
||||
static struct command_result *json_setleaserates(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct channel;
|
||||
struct lightningd;
|
||||
|
||||
void gossip_init(struct lightningd *ld, int connectd_fd);
|
||||
@@ -14,4 +15,16 @@ void gossipd_notify_spend(struct lightningd *ld,
|
||||
|
||||
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight);
|
||||
|
||||
/* channeld tells us stuff, we tell gossipd. */
|
||||
void tell_gossipd_local_channel_update(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
const u8 *msg);
|
||||
void tell_gossipd_local_channel_announce(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
const u8 *msg);
|
||||
void tell_gossipd_local_private_channel(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
struct amount_sat capacity,
|
||||
const u8 *features);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_CONTROL_H */
|
||||
|
||||
Reference in New Issue
Block a user