2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <ccan/err/err.h>
|
2022-01-08 14:21:29 +01:00
|
|
|
#include <ccan/ptrint/ptrint.h>
|
2022-01-24 21:03:52 +01:00
|
|
|
#include <channeld/channeld_wiregen.h>
|
2018-12-08 01:39:28 +01:00
|
|
|
#include <common/json_command.h>
|
2019-01-15 04:54:27 +01:00
|
|
|
#include <common/json_helpers.h>
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <common/json_tok.h>
|
2018-12-08 01:39:28 +01:00
|
|
|
#include <common/param.h>
|
2022-01-24 20:58:52 +01:00
|
|
|
#include <common/type_to_string.h>
|
2020-08-25 04:05:45 +02:00
|
|
|
#include <gossipd/gossipd_wiregen.h>
|
2017-11-28 17:14:52 +01:00
|
|
|
#include <hsmd/capabilities.h>
|
2021-12-04 12:23:56 +01:00
|
|
|
#include <lightningd/bitcoind.h>
|
|
|
|
#include <lightningd/chaintopology.h>
|
2022-01-24 20:58:52 +01:00
|
|
|
#include <lightningd/channel.h>
|
2022-01-24 21:02:52 +01:00
|
|
|
#include <lightningd/channel_control.h>
|
2021-12-04 12:23:56 +01:00
|
|
|
#include <lightningd/gossip_control.h>
|
2017-10-11 11:58:50 +02:00
|
|
|
#include <lightningd/hsm_control.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <lightningd/jsonrpc.h>
|
2021-12-04 12:23:56 +01:00
|
|
|
#include <lightningd/lightningd.h>
|
|
|
|
#include <lightningd/peer_control.h>
|
|
|
|
#include <lightningd/subd.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2018-01-04 12:40:58 +01:00
|
|
|
static void got_txout(struct bitcoind *bitcoind,
|
|
|
|
const struct bitcoin_tx_output *output,
|
|
|
|
struct short_channel_id *scid)
|
|
|
|
{
|
2018-01-15 02:34:34 +01:00
|
|
|
const u8 *script;
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat;
|
2018-01-15 02:34:34 +01:00
|
|
|
|
2018-01-04 12:40:58 +01:00
|
|
|
/* output will be NULL if it wasn't found */
|
2018-03-05 23:25:00 +01:00
|
|
|
if (output) {
|
2018-01-15 02:34:34 +01:00
|
|
|
script = output->script;
|
2019-02-21 04:45:55 +01:00
|
|
|
sat = output->amount;
|
2018-03-05 23:25:00 +01:00
|
|
|
} else {
|
2018-01-15 02:34:34 +01:00
|
|
|
script = NULL;
|
2019-02-21 04:45:55 +01:00
|
|
|
sat = AMOUNT_SAT(0);
|
2018-03-05 23:25:00 +01:00
|
|
|
}
|
2018-01-15 02:34:34 +01:00
|
|
|
|
2018-03-05 23:25:00 +01:00
|
|
|
subd_send_msg(
|
|
|
|
bitcoind->ld->gossip,
|
2020-08-25 04:05:45 +02:00
|
|
|
towire_gossipd_get_txout_reply(scid, scid, sat, script));
|
2018-01-04 12:40:58 +01:00
|
|
|
tal_free(scid);
|
|
|
|
}
|
|
|
|
|
2019-08-05 23:06:07 +02:00
|
|
|
static void got_filteredblock(struct bitcoind *bitcoind,
|
2019-08-08 06:24:33 +02:00
|
|
|
const struct filteredblock *fb,
|
|
|
|
struct short_channel_id *scid)
|
2019-08-05 23:06:07 +02:00
|
|
|
{
|
|
|
|
struct filteredblock_outpoint *fbo = NULL, *o;
|
|
|
|
struct bitcoin_tx_output txo;
|
|
|
|
|
2019-08-19 19:49:09 +02:00
|
|
|
/* If we failed to the filtered block we report the failure to
|
|
|
|
* got_txout. */
|
|
|
|
if (fb == NULL)
|
|
|
|
return got_txout(bitcoind, NULL, scid);
|
|
|
|
|
2019-08-06 20:39:02 +02:00
|
|
|
/* Only fill in blocks that we are not going to scan later. */
|
2019-08-19 18:53:40 +02:00
|
|
|
if (bitcoind->ld->topology->max_blockheight > fb->height)
|
2019-08-06 20:39:02 +02:00
|
|
|
wallet_filteredblock_add(bitcoind->ld->wallet, fb);
|
2019-08-05 23:06:07 +02:00
|
|
|
|
|
|
|
u32 outnum = short_channel_id_outnum(scid);
|
|
|
|
u32 txindex = short_channel_id_txnum(scid);
|
|
|
|
for (size_t i=0; i<tal_count(fb->outpoints); i++) {
|
|
|
|
o = fb->outpoints[i];
|
2021-10-13 05:45:36 +02:00
|
|
|
if (o->txindex == txindex && o->outpoint.n == outnum) {
|
2019-08-05 23:06:07 +02:00
|
|
|
fbo = o;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fbo) {
|
2019-08-07 04:02:21 +02:00
|
|
|
txo.amount = fbo->amount;
|
2019-08-05 23:06:07 +02:00
|
|
|
txo.script = (u8 *)fbo->scriptPubKey;
|
|
|
|
got_txout(bitcoind, &txo, scid);
|
|
|
|
} else
|
|
|
|
got_txout(bitcoind, NULL, scid);
|
|
|
|
}
|
|
|
|
|
2018-01-04 12:40:58 +01:00
|
|
|
static void get_txout(struct subd *gossip, const u8 *msg)
|
|
|
|
{
|
|
|
|
struct short_channel_id *scid = tal(gossip, struct short_channel_id);
|
2018-03-05 23:16:24 +01:00
|
|
|
struct outpoint *op;
|
2018-06-04 15:27:57 +02:00
|
|
|
u32 blockheight;
|
|
|
|
struct chain_topology *topo = gossip->ld->topology;
|
2018-01-04 12:40:58 +01:00
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
if (!fromwire_gossipd_get_txout(msg, scid))
|
2018-01-04 12:40:58 +01:00
|
|
|
fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s",
|
|
|
|
tal_hex(msg, msg));
|
|
|
|
|
|
|
|
/* FIXME: Block less than 6 deep? */
|
2018-06-04 15:27:57 +02:00
|
|
|
blockheight = short_channel_id_blocknum(scid);
|
2018-01-04 12:40:58 +01:00
|
|
|
|
2018-03-05 23:16:24 +01:00
|
|
|
op = wallet_outpoint_for_scid(gossip->ld->wallet, scid, scid);
|
|
|
|
|
|
|
|
if (op) {
|
2018-03-05 23:25:00 +01:00
|
|
|
subd_send_msg(gossip,
|
2020-08-25 04:05:45 +02:00
|
|
|
towire_gossipd_get_txout_reply(
|
2019-02-21 04:45:55 +01:00
|
|
|
scid, scid, op->sat, op->scriptpubkey));
|
2018-03-05 23:16:24 +01:00
|
|
|
tal_free(scid);
|
2019-08-05 23:06:07 +02:00
|
|
|
} else if (wallet_have_block(gossip->ld->wallet, blockheight)) {
|
|
|
|
/* We should have known about this outpoint since its header
|
|
|
|
* is in the DB. The fact that we don't means that this is
|
|
|
|
* either a spent outpoint or an invalid one. Return a
|
2018-06-04 15:27:57 +02:00
|
|
|
* failure. */
|
2020-08-25 04:05:45 +02:00
|
|
|
subd_send_msg(gossip, take(towire_gossipd_get_txout_reply(
|
2019-02-21 04:45:55 +01:00
|
|
|
NULL, scid, AMOUNT_SAT(0), NULL)));
|
2018-06-04 15:27:57 +02:00
|
|
|
tal_free(scid);
|
2018-03-05 23:16:24 +01:00
|
|
|
} else {
|
2019-08-05 23:06:07 +02:00
|
|
|
bitcoind_getfilteredblock(topo->bitcoind, short_channel_id_blocknum(scid), got_filteredblock, scid);
|
2018-03-05 23:16:24 +01:00
|
|
|
}
|
2018-01-04 12:40:58 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:58:52 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-24 21:02:52 +01:00
|
|
|
channel_replace_update(channel, take(update));
|
2022-01-24 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 21:00:52 +01:00
|
|
|
const u8 *get_channel_update(struct channel *channel)
|
|
|
|
{
|
|
|
|
/* Tell gossipd we're using it (if shutting down, might be NULL) */
|
|
|
|
if (channel->channel_update && channel->peer->ld->gossip) {
|
|
|
|
subd_send_msg(channel->peer->ld->gossip,
|
|
|
|
take(towire_gossipd_used_local_channel_update
|
|
|
|
(NULL, channel->scid)));
|
|
|
|
}
|
|
|
|
return channel->channel_update;
|
|
|
|
}
|
|
|
|
|
2018-07-24 08:18:58 +02:00
|
|
|
static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
|
2017-01-10 06:08:33 +01:00
|
|
|
{
|
2020-08-25 04:05:45 +02:00
|
|
|
enum gossipd_wire t = fromwire_peektype(msg);
|
2017-01-10 06:08:33 +01:00
|
|
|
|
|
|
|
switch (t) {
|
2017-03-10 11:50:43 +01:00
|
|
|
/* These are messages we send, not them. */
|
2020-08-25 04:05:45 +02:00
|
|
|
case WIRE_GOSSIPD_INIT:
|
|
|
|
case WIRE_GOSSIPD_GET_TXOUT_REPLY:
|
|
|
|
case WIRE_GOSSIPD_OUTPOINT_SPENT:
|
2021-05-28 18:39:52 +02:00
|
|
|
case WIRE_GOSSIPD_NEW_LEASE_RATES:
|
2020-08-25 04:05:45 +02:00
|
|
|
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
|
|
|
|
case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE:
|
|
|
|
case WIRE_GOSSIPD_DEV_MEMLEAK:
|
|
|
|
case WIRE_GOSSIPD_DEV_COMPACT_STORE:
|
|
|
|
case WIRE_GOSSIPD_DEV_SET_TIME:
|
|
|
|
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT:
|
2021-02-02 06:16:20 +01:00
|
|
|
case WIRE_GOSSIPD_ADDGOSSIP:
|
2022-01-11 02:15:48 +01:00
|
|
|
case WIRE_GOSSIPD_GET_ADDRS:
|
2022-01-24 21:00:52 +01:00
|
|
|
case WIRE_GOSSIPD_USED_LOCAL_CHANNEL_UPDATE:
|
2022-01-24 21:03:52 +01:00
|
|
|
case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE:
|
|
|
|
case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT:
|
|
|
|
case WIRE_GOSSIPD_LOCAL_PRIVATE_CHANNEL:
|
2017-03-10 11:50:43 +01:00
|
|
|
/* This is a reply, so never gets through to here. */
|
2021-06-14 23:07:39 +02:00
|
|
|
case WIRE_GOSSIPD_INIT_REPLY:
|
2020-08-25 04:05:45 +02:00
|
|
|
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:
|
|
|
|
case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY:
|
2021-02-02 06:16:20 +01:00
|
|
|
case WIRE_GOSSIPD_ADDGOSSIP_REPLY:
|
2022-01-08 14:21:29 +01:00
|
|
|
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
|
2022-01-11 02:15:48 +01:00
|
|
|
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
|
2022-02-23 19:11:03 +01:00
|
|
|
case WIRE_GOSSIPD_REMOTE_ADDR:
|
2017-12-15 15:16:42 +01:00
|
|
|
break;
|
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
case WIRE_GOSSIPD_GET_TXOUT:
|
2018-01-04 12:40:58 +01:00
|
|
|
get_txout(gossip, msg);
|
|
|
|
break;
|
2022-01-24 20:58:52 +01:00
|
|
|
case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE:
|
|
|
|
handle_local_channel_update(gossip->ld, msg);
|
|
|
|
break;
|
2017-01-10 06:08:33 +01:00
|
|
|
}
|
2017-03-19 21:31:35 +01:00
|
|
|
return 0;
|
2017-01-10 06:08:33 +01:00
|
|
|
}
|
|
|
|
|
2022-01-08 14:21:29 +01:00
|
|
|
static void gossipd_new_blockheight_reply(struct subd *gossipd,
|
|
|
|
const u8 *reply,
|
|
|
|
const int *fds UNUSED,
|
|
|
|
void *blockheight)
|
|
|
|
{
|
|
|
|
if (!fromwire_gossipd_new_blockheight_reply(reply)) {
|
|
|
|
/* Shouldn't happen! */
|
|
|
|
log_broken(gossipd->ld->log,
|
|
|
|
"Invalid new_blockheight_reply from gossipd: %s",
|
|
|
|
tal_hex(tmpctx, reply));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, finally update getinfo's blockheight */
|
|
|
|
gossipd->ld->blockheight = ptr2int(blockheight);
|
|
|
|
}
|
|
|
|
|
2019-09-22 04:06:43 +02:00
|
|
|
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
|
|
|
|
{
|
|
|
|
/* Only notify gossipd once we're synced. */
|
|
|
|
if (!topology_synced(ld->topology))
|
|
|
|
return;
|
|
|
|
|
2022-01-08 14:21:29 +01:00
|
|
|
subd_req(ld->gossip, ld->gossip,
|
|
|
|
take(towire_gossipd_new_blockheight(NULL, blockheight)),
|
|
|
|
-1, 0, gossipd_new_blockheight_reply, int2ptr(blockheight));
|
2019-09-22 04:06:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gossip_topology_synced(struct chain_topology *topo, void *unused)
|
|
|
|
{
|
|
|
|
/* Now we start telling gossipd about blocks. */
|
|
|
|
gossip_notify_new_block(topo->ld, get_block_height(topo));
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:07:39 +02:00
|
|
|
/* We make sure gossipd is started before plugins (which may want gossip_map) */
|
|
|
|
static void gossipd_init_done(struct subd *gossipd,
|
|
|
|
const u8 *msg,
|
|
|
|
const int *fds,
|
|
|
|
void *unused)
|
|
|
|
{
|
|
|
|
/* Break out of loop, so we can begin */
|
|
|
|
io_break(gossipd);
|
|
|
|
}
|
|
|
|
|
2017-04-24 14:31:26 +02:00
|
|
|
/* Create the `gossipd` subdaemon and send the initialization
|
|
|
|
* message */
|
2022-01-29 04:33:05 +01:00
|
|
|
void gossip_init(struct lightningd *ld, int connectd_fd)
|
2017-01-10 06:08:33 +01:00
|
|
|
{
|
2020-03-31 00:39:01 +02:00
|
|
|
u8 *msg;
|
2017-10-11 11:58:50 +02:00
|
|
|
int hsmfd;
|
|
|
|
|
2021-01-07 19:42:47 +01:00
|
|
|
hsmfd = hsm_get_global_fd(ld, HSM_CAP_ECDH|HSM_CAP_SIGN_GOSSIP);
|
2017-10-11 11:58:50 +02:00
|
|
|
|
2017-10-12 08:35:03 +02:00
|
|
|
ld->gossip = new_global_subd(ld, "lightning_gossipd",
|
2020-08-25 04:05:45 +02:00
|
|
|
gossipd_wire_name, gossip_msg,
|
2022-01-29 04:33:05 +01:00
|
|
|
take(&hsmfd), take(&connectd_fd), NULL);
|
2017-01-10 06:08:33 +01:00
|
|
|
if (!ld->gossip)
|
|
|
|
err(1, "Could not subdaemon gossip");
|
2017-04-24 14:31:26 +02:00
|
|
|
|
2019-09-22 04:06:43 +02:00
|
|
|
/* We haven't started topology yet, so tell us when we're synced. */
|
|
|
|
topology_add_sync_waiter(ld->gossip, ld->topology,
|
|
|
|
gossip_topology_synced, NULL);
|
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
msg = towire_gossipd_init(
|
2021-06-14 23:07:39 +02:00
|
|
|
NULL,
|
2019-09-25 22:38:45 +02:00
|
|
|
chainparams,
|
2020-04-03 02:03:59 +02:00
|
|
|
ld->our_features,
|
2019-09-25 22:38:45 +02:00
|
|
|
&ld->id,
|
2018-07-24 08:18:58 +02:00
|
|
|
ld->rgb,
|
2019-09-18 03:05:05 +02:00
|
|
|
ld->alias,
|
2022-02-23 17:58:41 +01:00
|
|
|
ld->announceable,
|
2019-09-18 03:05:05 +02:00
|
|
|
IFDEV(ld->dev_gossip_time ? &ld->dev_gossip_time: NULL, NULL),
|
2019-09-26 04:00:20 +02:00
|
|
|
IFDEV(ld->dev_fast_gossip, false),
|
|
|
|
IFDEV(ld->dev_fast_gossip_prune, false));
|
2021-06-14 23:07:39 +02:00
|
|
|
|
|
|
|
subd_req(ld->gossip, ld->gossip, take(msg), -1, 0,
|
|
|
|
gossipd_init_done, NULL);
|
|
|
|
|
|
|
|
/* Wait for gossipd_init_reply */
|
|
|
|
io_loop(NULL, NULL);
|
2018-04-30 04:08:15 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 12:03:40 +02:00
|
|
|
void gossipd_notify_spend(struct lightningd *ld,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
2020-08-25 04:05:45 +02:00
|
|
|
u8 *msg = towire_gossipd_outpoint_spent(tmpctx, scid);
|
2018-03-28 12:03:40 +02:00
|
|
|
subd_send_msg(ld->gossip, msg);
|
|
|
|
}
|
|
|
|
|
2022-01-24 21:03:52 +01:00
|
|
|
/* 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)));
|
|
|
|
}
|
|
|
|
|
2021-05-28 18:39:52 +02:00
|
|
|
static struct command_result *json_setleaserates(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
|
|
|
{
|
|
|
|
struct json_stream *res;
|
|
|
|
struct lease_rates *rates;
|
2022-06-20 12:22:10 +02:00
|
|
|
struct amount_msat *channel_fee_base_msat, *lease_base_msat;
|
2021-05-28 18:39:52 +02:00
|
|
|
u32 *lease_basis, *channel_fee_max_ppt, *funding_weight;
|
|
|
|
|
|
|
|
if (!param(cmd, buffer, params,
|
2022-06-20 12:22:10 +02:00
|
|
|
p_req("lease_fee_base_msat", param_msat, &lease_base_msat),
|
2021-05-28 18:39:52 +02:00
|
|
|
p_req("lease_fee_basis", param_number, &lease_basis),
|
|
|
|
p_req("funding_weight", param_number, &funding_weight),
|
|
|
|
p_req("channel_fee_max_base_msat", param_msat,
|
|
|
|
&channel_fee_base_msat),
|
|
|
|
p_req("channel_fee_max_proportional_thousandths",
|
|
|
|
param_number, &channel_fee_max_ppt),
|
|
|
|
NULL))
|
|
|
|
return command_param_failed();
|
|
|
|
|
|
|
|
rates = tal(tmpctx, struct lease_rates);
|
|
|
|
rates->lease_fee_basis = *lease_basis;
|
2022-06-20 12:22:10 +02:00
|
|
|
rates->lease_fee_base_sat = lease_base_msat->millisatoshis / 1000; /* Raw: conversion */
|
2021-05-28 18:39:52 +02:00
|
|
|
rates->channel_fee_max_base_msat = channel_fee_base_msat->millisatoshis; /* Raw: conversion */
|
|
|
|
|
|
|
|
rates->funding_weight = *funding_weight;
|
|
|
|
rates->channel_fee_max_proportional_thousandths
|
|
|
|
= *channel_fee_max_ppt;
|
|
|
|
|
|
|
|
/* Gotta check that we didn't overflow */
|
2022-06-20 12:22:10 +02:00
|
|
|
if (lease_base_msat->millisatoshis != rates->lease_fee_base_sat * (u64)1000) /* Raw: comparison */
|
2021-05-28 18:39:52 +02:00
|
|
|
return command_fail_badparam(cmd, "lease_fee_base_msat",
|
|
|
|
buffer, params, "Overflow");
|
|
|
|
|
|
|
|
if (channel_fee_base_msat->millisatoshis > rates->channel_fee_max_base_msat) /* Raw: comparison */
|
|
|
|
return command_fail_badparam(cmd, "channel_fee_max_base_msat",
|
|
|
|
buffer, params, "Overflow");
|
|
|
|
|
|
|
|
/* Call gossipd, let them know we've got new rates */
|
|
|
|
subd_send_msg(cmd->ld->gossip,
|
|
|
|
take(towire_gossipd_new_lease_rates(NULL, rates)));
|
|
|
|
|
|
|
|
res = json_stream_success(cmd);
|
2022-06-19 09:16:11 +02:00
|
|
|
json_add_amount_sat_msat(res, "lease_fee_base_msat",
|
2021-05-28 18:39:52 +02:00
|
|
|
amount_sat(rates->lease_fee_base_sat));
|
|
|
|
json_add_num(res, "lease_fee_basis", rates->lease_fee_basis);
|
|
|
|
json_add_num(res, "funding_weight", rates->funding_weight);
|
|
|
|
json_add_amount_msat_only(res, "channel_fee_max_base_msat",
|
|
|
|
amount_msat(rates->channel_fee_max_base_msat));
|
|
|
|
json_add_num(res, "channel_fee_max_proportional_thousandths",
|
|
|
|
rates->channel_fee_max_proportional_thousandths);
|
|
|
|
|
|
|
|
return command_success(cmd, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command setleaserates_command = {
|
|
|
|
"setleaserates",
|
|
|
|
"channels",
|
|
|
|
json_setleaserates,
|
|
|
|
"Called by plugin to set the node's present channel lease rates."
|
|
|
|
" Not to be set without having a plugin which can handle"
|
|
|
|
" `openchannel2` hooks.",
|
|
|
|
};
|
|
|
|
|
|
|
|
AUTODATA(json_command, &setleaserates_command);
|
|
|
|
|
2021-02-02 06:16:20 +01:00
|
|
|
/* Called upon receiving a addgossip_reply from `gossipd` */
|
|
|
|
static void json_addgossip_reply(struct subd *gossip UNUSED, const u8 *reply,
|
|
|
|
const int *fds UNUSED,
|
|
|
|
struct command *cmd)
|
|
|
|
{
|
|
|
|
char *err;
|
|
|
|
|
|
|
|
if (!fromwire_gossipd_addgossip_reply(reply, reply, &err)) {
|
|
|
|
/* Shouldn't happen: just end json stream. */
|
|
|
|
log_broken(cmd->ld->log,
|
|
|
|
"Invalid addgossip_reply from gossipd: %s",
|
|
|
|
tal_hex(tmpctx, reply));
|
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Invalid reply from gossipd"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(err))
|
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD, "%s", err));
|
|
|
|
else
|
|
|
|
was_pending(command_success(cmd, json_stream_success(cmd)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct command_result *json_addgossip(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
|
|
|
{
|
|
|
|
u8 *req, *gossip_msg;
|
|
|
|
if (!param(cmd, buffer, params,
|
|
|
|
p_req("message", param_bin_from_hex, &gossip_msg),
|
|
|
|
NULL))
|
|
|
|
return command_param_failed();
|
|
|
|
|
|
|
|
req = towire_gossipd_addgossip(cmd, gossip_msg);
|
|
|
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
|
|
|
req, -1, 0, json_addgossip_reply, cmd);
|
|
|
|
|
|
|
|
return command_still_pending(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command addgossip_command = {
|
|
|
|
"addgossip",
|
|
|
|
"utility",
|
|
|
|
json_addgossip,
|
|
|
|
"Inject gossip {message} into gossipd"
|
|
|
|
};
|
|
|
|
AUTODATA(json_command, &addgossip_command);
|
|
|
|
|
2018-06-04 06:23:25 +02:00
|
|
|
#if DEVELOPER
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *
|
|
|
|
json_dev_set_max_scids_encode_size(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2018-06-04 06:28:02 +02:00
|
|
|
{
|
|
|
|
u8 *msg;
|
2018-08-10 22:16:22 +02:00
|
|
|
u32 *max;
|
2018-06-04 06:28:02 +02:00
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2018-12-16 05:50:06 +01:00
|
|
|
p_req("max", param_number, &max),
|
2018-07-16 22:48:38 +02:00
|
|
|
NULL))
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_param_failed();
|
2018-06-04 06:28:02 +02:00
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
msg = towire_gossipd_dev_set_max_scids_encode_size(NULL, *max);
|
2018-06-04 06:28:02 +02:00
|
|
|
subd_send_msg(cmd->ld->gossip, take(msg));
|
|
|
|
|
2019-06-12 02:38:54 +02:00
|
|
|
return command_success(cmd, json_stream_success(cmd));
|
2018-06-04 06:28:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_set_max_scids_encode_size = {
|
|
|
|
"dev-set-max-scids-encode-size",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2018-06-04 06:28:02 +02:00
|
|
|
json_dev_set_max_scids_encode_size,
|
|
|
|
"Set {max} bytes of short_channel_ids per reply_channel_range"
|
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_set_max_scids_encode_size);
|
2018-07-26 23:27:37 +02:00
|
|
|
|
2019-04-08 01:52:19 +02:00
|
|
|
static void dev_compact_gossip_store_reply(struct subd *gossip UNUSED,
|
|
|
|
const u8 *reply,
|
|
|
|
const int *fds UNUSED,
|
|
|
|
struct command *cmd)
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
if (!fromwire_gossipd_dev_compact_store_reply(reply, &success)) {
|
2019-04-08 01:52:19 +02:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Gossip gave bad dev_gossip_compact_store_reply"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"gossip_compact_store failed"));
|
|
|
|
else
|
2019-06-12 02:38:54 +02:00
|
|
|
was_pending(command_success(cmd, json_stream_success(cmd)));
|
2019-04-08 01:52:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct command_result *json_dev_compact_gossip_store(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
|
|
|
{
|
|
|
|
u8 *msg;
|
|
|
|
if (!param(cmd, buffer, params, NULL))
|
|
|
|
return command_param_failed();
|
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
msg = towire_gossipd_dev_compact_store(NULL);
|
2019-04-08 01:52:19 +02:00
|
|
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
|
|
|
take(msg), -1, 0, dev_compact_gossip_store_reply, cmd);
|
|
|
|
return command_still_pending(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_compact_gossip_store = {
|
|
|
|
"dev-compact-gossip-store",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2019-04-08 01:52:19 +02:00
|
|
|
json_dev_compact_gossip_store,
|
|
|
|
"Ask gossipd to rewrite the gossip store."
|
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_compact_gossip_store);
|
2019-09-12 02:24:00 +02:00
|
|
|
|
|
|
|
static struct command_result *json_dev_gossip_set_time(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
|
|
|
{
|
|
|
|
u8 *msg;
|
|
|
|
u32 *time;
|
|
|
|
|
|
|
|
if (!param(cmd, buffer, params,
|
|
|
|
p_req("time", param_number, &time),
|
|
|
|
NULL))
|
|
|
|
return command_param_failed();
|
|
|
|
|
2020-08-25 04:05:45 +02:00
|
|
|
msg = towire_gossipd_dev_set_time(NULL, *time);
|
2019-09-12 02:24:00 +02:00
|
|
|
subd_send_msg(cmd->ld->gossip, take(msg));
|
|
|
|
|
|
|
|
return command_success(cmd, json_stream_success(cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_gossip_set_time = {
|
|
|
|
"dev-gossip-set-time",
|
|
|
|
"developer",
|
|
|
|
json_dev_gossip_set_time,
|
|
|
|
"Ask gossipd to update the current time."
|
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_gossip_set_time);
|
2018-06-04 06:23:25 +02:00
|
|
|
#endif /* DEVELOPER */
|