2018-01-04 12:40:58 +01:00
|
|
|
#include "bitcoind.h"
|
|
|
|
#include "chaintopology.h"
|
2017-01-10 06:08:33 +01:00
|
|
|
#include "gossip_control.h"
|
|
|
|
#include "lightningd.h"
|
|
|
|
#include "peer_control.h"
|
2017-03-10 11:50:43 +01:00
|
|
|
#include "subd.h"
|
2018-01-16 20:44:32 +01:00
|
|
|
#include <ccan/array_size/array_size.h>
|
2018-02-23 01:00:00 +01:00
|
|
|
#include <ccan/crypto/siphash24/siphash24.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <ccan/err/err.h>
|
2017-10-11 11:58:50 +02:00
|
|
|
#include <ccan/fdpass/fdpass.h>
|
2019-06-12 02:38:54 +02:00
|
|
|
#include <ccan/json_escape/json_escape.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <ccan/take/take.h>
|
2017-03-22 13:30:09 +01:00
|
|
|
#include <ccan/tal/str/str.h>
|
2019-02-21 03:39:21 +01:00
|
|
|
#include <common/amount.h>
|
2018-01-12 14:35:52 +01:00
|
|
|
#include <common/features.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>
|
2018-12-08 01:39:28 +01:00
|
|
|
#include <common/jsonrpc_errors.h>
|
|
|
|
#include <common/param.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/type_to_string.h>
|
|
|
|
#include <common/utils.h>
|
2017-10-11 11:58:50 +02:00
|
|
|
#include <errno.h>
|
2017-08-29 06:12:04 +02:00
|
|
|
#include <gossipd/gen_gossip_wire.h>
|
2017-11-28 17:14:52 +01:00
|
|
|
#include <hsmd/capabilities.h>
|
2018-09-20 05:06:42 +02:00
|
|
|
#include <hsmd/gen_hsm_wire.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <inttypes.h>
|
2018-02-20 21:59:09 +01:00
|
|
|
#include <lightningd/connect_control.h>
|
2017-03-12 13:39:23 +01:00
|
|
|
#include <lightningd/gossip_msg.h>
|
2017-10-11 11:58:50 +02:00
|
|
|
#include <lightningd/hsm_control.h>
|
2018-03-16 04:45:08 +01:00
|
|
|
#include <lightningd/json.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <lightningd/jsonrpc.h>
|
|
|
|
#include <lightningd/log.h>
|
2018-09-20 02:59:46 +02:00
|
|
|
#include <lightningd/options.h>
|
2018-09-11 21:57:11 +02:00
|
|
|
#include <lightningd/ping.h>
|
2018-02-15 14:37:04 +01:00
|
|
|
#include <sodium/randombytes.h>
|
|
|
|
#include <string.h>
|
2017-02-24 06:52:56 +01:00
|
|
|
#include <wire/gen_peer_wire.h>
|
2017-10-11 11:58:50 +02:00
|
|
|
#include <wire/wire_sync.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,
|
2019-02-21 04:45:55 +01:00
|
|
|
towire_gossip_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];
|
|
|
|
if (o->txindex == txindex && o->outnum == outnum) {
|
|
|
|
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
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
if (!fromwire_gossip_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,
|
|
|
|
towire_gossip_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. */
|
|
|
|
subd_send_msg(gossip, take(towire_gossip_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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-03-10 11:50:43 +01:00
|
|
|
enum gossip_wire_type 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. */
|
2017-04-24 14:31:26 +02:00
|
|
|
case WIRE_GOSSIPCTL_INIT:
|
2017-03-12 13:39:23 +01:00
|
|
|
case WIRE_GOSSIP_GETNODES_REQUEST:
|
2017-03-15 11:36:52 +01:00
|
|
|
case WIRE_GOSSIP_GETROUTE_REQUEST:
|
2017-03-22 13:30:09 +01:00
|
|
|
case WIRE_GOSSIP_GETCHANNELS_REQUEST:
|
2017-04-12 20:20:48 +02:00
|
|
|
case WIRE_GOSSIP_PING:
|
2018-10-15 06:57:22 +02:00
|
|
|
case WIRE_GOSSIP_GET_CHANNEL_PEER:
|
2018-01-04 12:40:58 +01:00
|
|
|
case WIRE_GOSSIP_GET_TXOUT_REPLY:
|
2018-03-26 20:10:03 +02:00
|
|
|
case WIRE_GOSSIP_OUTPOINT_SPENT:
|
2019-01-17 16:24:32 +01:00
|
|
|
case WIRE_GOSSIP_PAYMENT_FAILURE:
|
2018-06-04 06:22:25 +02:00
|
|
|
case WIRE_GOSSIP_QUERY_SCIDS:
|
2018-06-04 06:28:02 +02:00
|
|
|
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE:
|
2018-06-04 06:28:02 +02:00
|
|
|
case WIRE_GOSSIP_SEND_TIMESTAMP_FILTER:
|
2018-09-27 07:29:17 +02:00
|
|
|
case WIRE_GOSSIP_GET_INCOMING_CHANNELS:
|
2018-06-04 06:28:02 +02:00
|
|
|
case WIRE_GOSSIP_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
|
2018-07-26 23:27:37 +02:00
|
|
|
case WIRE_GOSSIP_DEV_SUPPRESS:
|
2018-11-13 05:03:51 +01:00
|
|
|
case WIRE_GOSSIP_LOCAL_CHANNEL_CLOSE:
|
2018-11-21 23:41:49 +01:00
|
|
|
case WIRE_GOSSIP_DEV_MEMLEAK:
|
2019-04-08 01:52:19 +02:00
|
|
|
case WIRE_GOSSIP_DEV_COMPACT_STORE:
|
2017-03-10 11:50:43 +01:00
|
|
|
/* This is a reply, so never gets through to here. */
|
2017-03-12 13:39:23 +01:00
|
|
|
case WIRE_GOSSIP_GETNODES_REPLY:
|
2017-03-15 11:36:52 +01:00
|
|
|
case WIRE_GOSSIP_GETROUTE_REPLY:
|
2017-03-22 13:30:09 +01:00
|
|
|
case WIRE_GOSSIP_GETCHANNELS_REPLY:
|
2018-06-04 06:22:25 +02:00
|
|
|
case WIRE_GOSSIP_SCIDS_REPLY:
|
2018-06-04 06:28:02 +02:00
|
|
|
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE_REPLY:
|
2018-10-15 06:57:22 +02:00
|
|
|
case WIRE_GOSSIP_GET_CHANNEL_PEER_REPLY:
|
2018-09-27 07:29:17 +02:00
|
|
|
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
|
2018-11-21 23:41:49 +01:00
|
|
|
case WIRE_GOSSIP_DEV_MEMLEAK_REPLY:
|
2019-04-08 01:52:19 +02:00
|
|
|
case WIRE_GOSSIP_DEV_COMPACT_STORE_REPLY:
|
2017-12-15 15:16:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-09-11 21:57:11 +02:00
|
|
|
case WIRE_GOSSIP_PING_REPLY:
|
|
|
|
ping_reply(gossip, msg);
|
|
|
|
break;
|
|
|
|
|
2018-01-04 12:40:58 +01:00
|
|
|
case WIRE_GOSSIP_GET_TXOUT:
|
|
|
|
get_txout(gossip, 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
|
|
|
}
|
|
|
|
|
2017-04-24 14:31:26 +02:00
|
|
|
/* Create the `gossipd` subdaemon and send the initialization
|
|
|
|
* message */
|
2018-07-24 08:18:58 +02:00
|
|
|
void gossip_init(struct lightningd *ld, int connectd_fd)
|
2017-01-10 06:08:33 +01:00
|
|
|
{
|
2017-10-11 11:58:50 +02:00
|
|
|
u8 *msg;
|
|
|
|
int hsmfd;
|
|
|
|
|
2018-09-20 05:07:41 +02:00
|
|
|
hsmfd = hsm_get_global_fd(ld, 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",
|
|
|
|
gossip_wire_type_name, gossip_msg,
|
2018-07-24 08:18:58 +02: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
|
|
|
|
2018-01-09 15:52:21 +01:00
|
|
|
msg = towire_gossipctl_init(
|
2019-06-03 20:15:25 +02:00
|
|
|
tmpctx,
|
2018-04-30 04:08:15 +02:00
|
|
|
&get_chainparams(ld)->genesis_blockhash, &ld->id,
|
2018-09-28 05:24:24 +02:00
|
|
|
get_offered_globalfeatures(tmpctx),
|
2018-07-24 08:18:58 +02:00
|
|
|
ld->rgb,
|
|
|
|
ld->alias, ld->config.channel_update_interval,
|
2019-04-08 01:51:30 +02:00
|
|
|
ld->announcable,
|
|
|
|
#if DEVELOPER
|
2019-05-16 21:56:17 +02:00
|
|
|
ld->dev_gossip_time ? &ld->dev_gossip_time: NULL
|
2019-04-08 01:51:30 +02:00
|
|
|
#else
|
|
|
|
NULL
|
|
|
|
#endif
|
|
|
|
);
|
2018-04-30 04:08:15 +02:00
|
|
|
subd_send_msg(ld->gossip, msg);
|
|
|
|
}
|
|
|
|
|
2018-03-28 12:03:40 +02:00
|
|
|
void gossipd_notify_spend(struct lightningd *ld,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
u8 *msg = towire_gossip_outpoint_spent(tmpctx, scid);
|
|
|
|
subd_send_msg(ld->gossip, msg);
|
|
|
|
}
|
|
|
|
|
2018-02-21 16:06:07 +01:00
|
|
|
static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
|
|
|
const int *fds UNUSED,
|
2017-03-12 13:39:23 +01:00
|
|
|
struct command *cmd)
|
|
|
|
{
|
2018-02-08 02:24:46 +01:00
|
|
|
struct gossip_getnodes_entry **nodes;
|
2018-10-19 03:17:49 +02:00
|
|
|
struct json_stream *response;
|
2017-05-08 23:22:59 +02:00
|
|
|
size_t i, j;
|
2017-03-16 05:05:26 +01:00
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
if (!fromwire_gossip_getnodes_reply(reply, reply, &nodes)) {
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Malformed gossip_getnodes response"));
|
2017-10-12 08:35:04 +02:00
|
|
|
return;
|
2017-03-16 05:05:26 +01:00
|
|
|
}
|
|
|
|
|
2018-10-19 03:17:48 +02:00
|
|
|
response = json_stream_success(cmd);
|
2017-03-12 13:39:23 +01:00
|
|
|
json_array_start(response, "nodes");
|
|
|
|
|
2017-03-16 05:05:26 +01:00
|
|
|
for (i = 0; i < tal_count(nodes); i++) {
|
2019-06-12 02:38:54 +02:00
|
|
|
struct json_escape *esc;
|
2018-03-26 02:08:17 +02:00
|
|
|
|
2017-03-12 13:39:23 +01:00
|
|
|
json_object_start(response, NULL);
|
2019-04-08 11:58:32 +02:00
|
|
|
json_add_node_id(response, "nodeid", &nodes[i]->nodeid);
|
2018-02-08 02:24:46 +01:00
|
|
|
if (nodes[i]->last_timestamp < 0) {
|
2018-01-16 20:44:32 +01:00
|
|
|
json_object_end(response);
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-24 03:41:39 +02:00
|
|
|
esc = json_escape(NULL,
|
|
|
|
take(tal_strndup(NULL,
|
|
|
|
(const char *)nodes[i]->alias,
|
|
|
|
ARRAY_SIZE(nodes[i]->alias))));
|
2018-03-26 02:08:17 +02:00
|
|
|
json_add_escaped_string(response, "alias", take(esc));
|
2018-01-16 20:44:32 +01:00
|
|
|
json_add_hex(response, "color",
|
2018-02-08 02:24:46 +01:00
|
|
|
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
|
2018-01-16 20:44:32 +01:00
|
|
|
json_add_u64(response, "last_timestamp",
|
2018-02-08 02:24:46 +01:00
|
|
|
nodes[i]->last_timestamp);
|
2018-09-28 05:24:25 +02:00
|
|
|
json_add_hex_talarr(response, "globalfeatures",
|
2018-09-28 05:24:24 +02:00
|
|
|
nodes[i]->globalfeatures);
|
2017-05-08 23:22:59 +02:00
|
|
|
json_array_start(response, "addresses");
|
2018-02-08 02:24:46 +01:00
|
|
|
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
|
|
|
|
json_add_address(response, NULL, &nodes[i]->addresses[j]);
|
2017-03-12 13:39:23 +01:00
|
|
|
}
|
2017-05-08 23:22:59 +02:00
|
|
|
json_array_end(response);
|
2017-03-12 13:39:23 +01:00
|
|
|
json_object_end(response);
|
|
|
|
}
|
|
|
|
json_array_end(response);
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_success(cmd, response));
|
2017-03-12 13:39:23 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_listnodes(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2017-03-12 13:39:23 +01:00
|
|
|
{
|
2018-01-16 20:44:32 +01:00
|
|
|
u8 *req;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *id;
|
2018-01-16 20:44:32 +01:00
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-04-08 11:58:32 +02:00
|
|
|
p_opt("id", param_node_id, &id),
|
2018-07-16 22:48:38 +02:00
|
|
|
NULL))
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_param_failed();
|
2018-01-16 20:44:32 +01:00
|
|
|
|
|
|
|
req = towire_gossip_getnodes_request(cmd, id);
|
2017-08-28 18:09:01 +02:00
|
|
|
subd_req(cmd, cmd->ld->gossip, req, -1, 0, json_getnodes_reply, cmd);
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_still_pending(cmd);
|
2017-03-12 13:39:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 20:44:32 +01:00
|
|
|
static const struct json_command listnodes_command = {
|
2018-01-22 09:55:07 +01:00
|
|
|
"listnodes",
|
2019-05-22 16:08:16 +02:00
|
|
|
"network",
|
2018-01-22 09:55:07 +01:00
|
|
|
json_listnodes,
|
2018-03-10 19:54:19 +01:00
|
|
|
"Show node {id} (or all, if no {id}), in our local network view"
|
2018-01-22 09:55:07 +01:00
|
|
|
};
|
2018-01-16 20:44:32 +01:00
|
|
|
AUTODATA(json_command, &listnodes_command);
|
2017-03-15 11:36:52 +01:00
|
|
|
|
2018-02-21 16:06:07 +01:00
|
|
|
static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, const int *fds UNUSED,
|
2017-03-15 13:46:29 +01:00
|
|
|
struct command *cmd)
|
|
|
|
{
|
2018-10-19 03:17:49 +02:00
|
|
|
struct json_stream *response;
|
2017-03-15 13:46:29 +01:00
|
|
|
struct route_hop *hops;
|
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
fromwire_gossip_getroute_reply(reply, reply, &hops);
|
2017-03-15 13:46:29 +01:00
|
|
|
|
|
|
|
if (tal_count(hops) == 0) {
|
2019-01-15 05:08:27 +01:00
|
|
|
was_pending(command_fail(cmd, PAY_ROUTE_NOT_FOUND,
|
2018-12-16 05:53:06 +01:00
|
|
|
"Could not find a route"));
|
2017-10-12 08:35:04 +02:00
|
|
|
return;
|
2017-03-15 13:46:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-19 03:17:48 +02:00
|
|
|
response = json_stream_success(cmd);
|
2018-03-16 04:45:08 +01:00
|
|
|
json_add_route(response, "route", hops, tal_count(hops));
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_success(cmd, response));
|
2017-03-15 13:46:29 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_getroute(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2017-03-15 11:36:52 +01:00
|
|
|
{
|
2018-02-10 21:38:26 +01:00
|
|
|
struct lightningd *ld = cmd->ld;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *destination;
|
|
|
|
struct node_id *source;
|
2019-01-15 05:05:27 +01:00
|
|
|
const jsmntok_t *excludetok;
|
2019-02-21 03:39:21 +01:00
|
|
|
struct amount_msat *msat;
|
2018-08-10 22:16:22 +02:00
|
|
|
unsigned *cltv;
|
2018-08-13 18:42:11 +02:00
|
|
|
double *riskfactor;
|
2019-01-15 05:11:27 +01:00
|
|
|
struct short_channel_id_dir *excluded;
|
2019-01-15 05:06:27 +01:00
|
|
|
u32 *max_hops;
|
2019-01-15 05:05:27 +01:00
|
|
|
|
2018-02-24 02:19:21 +01:00
|
|
|
/* Higher fuzz means that some high-fee paths can be discounted
|
|
|
|
* for an even larger value, increasing the scope for route
|
|
|
|
* randomization (the higher-fee paths become more likely to
|
|
|
|
* be selected) at the cost of increasing the probability of
|
|
|
|
* selecting the higher-fee paths. */
|
2018-08-13 18:42:11 +02:00
|
|
|
double *fuzz;
|
2017-08-28 18:09:01 +02:00
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-04-08 11:58:32 +02:00
|
|
|
p_req("id", param_node_id, &destination),
|
2019-02-21 03:39:21 +01:00
|
|
|
p_req("msatoshi", param_msat, &msat),
|
2018-12-16 05:50:06 +01:00
|
|
|
p_req("riskfactor", param_double, &riskfactor),
|
|
|
|
p_opt_def("cltv", param_number, &cltv, 9),
|
2019-05-31 09:30:33 +02:00
|
|
|
p_opt("fromid", param_node_id, &source),
|
2019-01-15 04:55:27 +01:00
|
|
|
p_opt_def("fuzzpercent", param_percent, &fuzz, 5.0),
|
2019-01-15 05:05:27 +01:00
|
|
|
p_opt("exclude", param_array, &excludetok),
|
2019-01-15 05:06:27 +01:00
|
|
|
p_opt_def("maxhops", param_number, &max_hops,
|
|
|
|
ROUTING_MAX_HOPS),
|
2018-07-16 22:48:38 +02:00
|
|
|
NULL))
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_param_failed();
|
2017-03-15 13:46:29 +01:00
|
|
|
|
2018-02-15 10:18:29 +01:00
|
|
|
/* Convert from percentage */
|
2018-08-13 18:42:11 +02:00
|
|
|
*fuzz = *fuzz / 100.0;
|
2018-02-15 10:18:29 +01:00
|
|
|
|
2019-01-15 05:05:27 +01:00
|
|
|
if (excludetok) {
|
2019-01-17 03:12:13 +01:00
|
|
|
const jsmntok_t *t;
|
2019-01-15 05:05:27 +01:00
|
|
|
size_t i;
|
|
|
|
|
2019-01-15 05:11:27 +01:00
|
|
|
excluded = tal_arr(cmd, struct short_channel_id_dir,
|
2019-01-15 05:05:27 +01:00
|
|
|
excludetok->size);
|
|
|
|
|
2019-01-17 03:12:13 +01:00
|
|
|
json_for_each_arr(i, t, excludetok) {
|
2019-01-15 05:11:27 +01:00
|
|
|
if (!short_channel_id_dir_from_str(buffer + t->start,
|
|
|
|
t->end - t->start,
|
2019-09-06 08:41:41 +02:00
|
|
|
&excluded[i])) {
|
2019-01-15 05:05:27 +01:00
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"%.*s is not a valid"
|
2019-01-15 05:10:27 +01:00
|
|
|
" short_channel_id/direction",
|
2019-01-15 05:05:27 +01:00
|
|
|
t->end - t->start,
|
|
|
|
buffer + t->start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
excluded = NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-14 23:19:31 +02:00
|
|
|
u8 *req = towire_gossip_getroute_request(cmd, source, destination,
|
2019-02-21 04:45:55 +01:00
|
|
|
*msat,
|
2019-02-01 06:53:38 +01:00
|
|
|
*riskfactor * 1000000.0,
|
2019-01-15 05:04:27 +01:00
|
|
|
*cltv, fuzz,
|
2019-01-15 05:11:27 +01:00
|
|
|
excluded,
|
2019-01-15 05:06:27 +01:00
|
|
|
*max_hops);
|
2017-04-01 12:58:30 +02:00
|
|
|
subd_req(ld->gossip, ld->gossip, req, -1, 0, json_getroute_reply, cmd);
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_still_pending(cmd);
|
2017-03-15 11:36:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command getroute_command = {
|
2018-01-22 09:55:07 +01:00
|
|
|
"getroute",
|
2019-05-22 16:08:16 +02:00
|
|
|
"channels",
|
2018-01-22 09:55:07 +01:00
|
|
|
json_getroute,
|
2018-02-15 10:18:29 +01:00
|
|
|
"Show route to {id} for {msatoshi}, using {riskfactor} and optional {cltv} (default 9). "
|
|
|
|
"If specified search from {fromid} otherwise use this node as source. "
|
2019-03-31 23:57:32 +02:00
|
|
|
"Randomize the route with up to {fuzzpercent} (default 5.0). "
|
|
|
|
"{exclude} an array of short-channel-id/direction (e.g. [ '564334x877x1/0', '564195x1292x0/1' ]) "
|
|
|
|
"from consideration. "
|
|
|
|
"Set the {maxhops} the route can take (default 20)."
|
2017-03-15 11:36:52 +01:00
|
|
|
};
|
|
|
|
AUTODATA(json_command, &getroute_command);
|
2017-03-22 13:30:09 +01:00
|
|
|
|
2019-04-08 11:58:44 +02:00
|
|
|
static void json_add_halfchan(struct json_stream *response,
|
|
|
|
const struct gossip_getchannels_entry *e,
|
|
|
|
int idx)
|
|
|
|
{
|
|
|
|
const struct gossip_halfchannel_entry *he = e->e[idx];
|
|
|
|
if (!he)
|
|
|
|
return;
|
|
|
|
|
|
|
|
json_object_start(response, NULL);
|
|
|
|
json_add_node_id(response, "source", &e->node[idx]);
|
|
|
|
json_add_node_id(response, "destination", &e->node[!idx]);
|
|
|
|
json_add_short_channel_id(response, "short_channel_id",
|
|
|
|
&e->short_channel_id);
|
|
|
|
json_add_bool(response, "public", e->public);
|
2019-05-20 07:07:40 +02:00
|
|
|
json_add_amount_sat_compat(response, e->sat,
|
|
|
|
"satoshis", "amount_msat");
|
2019-04-08 11:58:44 +02:00
|
|
|
json_add_num(response, "message_flags", he->message_flags);
|
|
|
|
json_add_num(response, "channel_flags", he->channel_flags);
|
|
|
|
json_add_bool(response, "active",
|
|
|
|
!(he->channel_flags & ROUTING_FLAGS_DISABLED)
|
|
|
|
&& !e->local_disabled);
|
|
|
|
json_add_num(response, "last_update", he->last_update_timestamp);
|
|
|
|
json_add_num(response, "base_fee_millisatoshi", he->base_fee_msat);
|
|
|
|
json_add_num(response, "fee_per_millionth", he->fee_per_millionth);
|
|
|
|
json_add_num(response, "delay", he->delay);
|
2019-05-31 09:28:06 +02:00
|
|
|
json_add_amount_msat_only(response, "htlc_minimum_msat", he->min);
|
|
|
|
json_add_amount_msat_only(response, "htlc_maximum_msat", he->max);
|
2019-04-08 11:58:44 +02:00
|
|
|
json_object_end(response);
|
|
|
|
}
|
|
|
|
|
2019-05-21 09:13:26 +02:00
|
|
|
struct listchannels_info {
|
|
|
|
struct command *cmd;
|
|
|
|
struct json_stream *response;
|
|
|
|
struct short_channel_id *id;
|
|
|
|
struct node_id *source;
|
|
|
|
};
|
|
|
|
|
2017-03-22 13:30:09 +01:00
|
|
|
/* Called upon receiving a getchannels_reply from `gossipd` */
|
2018-02-21 16:06:07 +01:00
|
|
|
static void json_listchannels_reply(struct subd *gossip UNUSED, const u8 *reply,
|
2019-05-21 09:13:26 +02:00
|
|
|
const int *fds UNUSED,
|
|
|
|
struct listchannels_info *linfo)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
|
|
|
size_t i;
|
2019-04-08 11:58:44 +02:00
|
|
|
struct gossip_getchannels_entry **entries;
|
2019-05-21 09:13:26 +02:00
|
|
|
bool complete;
|
2017-03-22 13:30:09 +01:00
|
|
|
|
2019-05-21 09:13:26 +02:00
|
|
|
if (!fromwire_gossip_getchannels_reply(reply, reply,
|
|
|
|
&complete, &entries)) {
|
|
|
|
/* Shouldn't happen: just end json stream. */
|
|
|
|
log_broken(linfo->cmd->ld->log, "Invalid reply from gossipd");
|
|
|
|
was_pending(command_raw_complete(linfo->cmd, linfo->response));
|
2017-10-12 08:35:04 +02:00
|
|
|
return;
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < tal_count(entries); i++) {
|
2019-05-21 09:13:26 +02:00
|
|
|
json_add_halfchan(linfo->response, entries[i], 0);
|
|
|
|
json_add_halfchan(linfo->response, entries[i], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* More coming? Ask from this point on.. */
|
|
|
|
if (!complete) {
|
|
|
|
u8 *req;
|
|
|
|
assert(tal_count(entries) != 0);
|
|
|
|
req = towire_gossip_getchannels_request(linfo->cmd,
|
|
|
|
linfo->id,
|
|
|
|
linfo->source,
|
|
|
|
&entries[i-1]
|
|
|
|
->short_channel_id);
|
|
|
|
subd_req(linfo->cmd->ld->gossip, linfo->cmd->ld->gossip,
|
|
|
|
req, -1, 0, json_listchannels_reply, linfo);
|
|
|
|
} else {
|
|
|
|
json_array_end(linfo->response);
|
|
|
|
was_pending(command_success(linfo->cmd, linfo->response));
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_listchannels(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
2018-01-16 20:44:32 +01:00
|
|
|
u8 *req;
|
2019-05-21 09:13:26 +02:00
|
|
|
struct listchannels_info *linfo = tal(cmd, struct listchannels_info);
|
2019-01-15 05:09:27 +01:00
|
|
|
|
2019-05-21 09:13:26 +02:00
|
|
|
linfo->cmd = cmd;
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-05-21 09:13:26 +02:00
|
|
|
p_opt("short_channel_id", param_short_channel_id, &linfo->id),
|
|
|
|
p_opt("source", param_node_id, &linfo->source),
|
2018-07-16 22:48:38 +02:00
|
|
|
NULL))
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_param_failed();
|
2018-01-16 20:44:32 +01:00
|
|
|
|
2019-05-21 09:13:26 +02:00
|
|
|
if (linfo->id && linfo->source)
|
2019-01-15 05:09:27 +01:00
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"Cannot specify both source and short_channel_id");
|
2019-05-21 09:13:26 +02:00
|
|
|
|
|
|
|
/* Start JSON response, then we stream. */
|
|
|
|
linfo->response = json_stream_success(cmd);
|
|
|
|
json_array_start(linfo->response, "channels");
|
|
|
|
|
|
|
|
req = towire_gossip_getchannels_request(cmd, linfo->id, linfo->source,
|
|
|
|
NULL);
|
2017-08-28 18:09:01 +02:00
|
|
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
2019-05-21 09:13:26 +02:00
|
|
|
req, -1, 0, json_listchannels_reply, linfo);
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_still_pending(cmd);
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 20:44:32 +01:00
|
|
|
static const struct json_command listchannels_command = {
|
2018-01-22 09:55:07 +01:00
|
|
|
"listchannels",
|
2019-05-22 16:08:16 +02:00
|
|
|
"channels",
|
2018-01-22 09:55:07 +01:00
|
|
|
json_listchannels,
|
2019-01-15 05:09:27 +01:00
|
|
|
"Show channel {short_channel_id} or {source} (or all known channels, if not specified)"
|
2018-01-22 09:55:07 +01:00
|
|
|
};
|
2018-01-16 20:44:32 +01:00
|
|
|
AUTODATA(json_command, &listchannels_command);
|
2018-06-04 06:23:25 +02:00
|
|
|
|
|
|
|
#if DEVELOPER
|
|
|
|
static void json_scids_reply(struct subd *gossip UNUSED, const u8 *reply,
|
|
|
|
const int *fds UNUSED, struct command *cmd)
|
|
|
|
{
|
|
|
|
bool ok, complete;
|
2018-10-19 03:17:49 +02:00
|
|
|
struct json_stream *response;
|
2018-06-04 06:23:25 +02:00
|
|
|
|
|
|
|
if (!fromwire_gossip_scids_reply(reply, &ok, &complete)) {
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Gossip gave bad gossip_scids_reply"));
|
2018-06-04 06:23:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Gossip refused to query peer"));
|
2018-06-04 06:23:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-19 03:17:48 +02:00
|
|
|
response = json_stream_success(cmd);
|
2018-06-04 06:23:25 +02:00
|
|
|
json_add_bool(response, "complete", complete);
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_success(cmd, response));
|
2018-06-04 06:23:25 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_dev_query_scids(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2018-06-04 06:23:25 +02:00
|
|
|
{
|
|
|
|
u8 *msg;
|
2018-07-16 22:48:38 +02:00
|
|
|
const jsmntok_t *scidstok;
|
2019-01-17 03:12:13 +01:00
|
|
|
const jsmntok_t *t;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *id;
|
2018-06-04 06:23:25 +02:00
|
|
|
struct short_channel_id *scids;
|
|
|
|
size_t i;
|
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-04-08 11:58:32 +02:00
|
|
|
p_req("id", param_node_id, &id),
|
2018-12-16 05:50:06 +01:00
|
|
|
p_req("scids", param_array, &scidstok),
|
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:23:25 +02:00
|
|
|
|
|
|
|
scids = tal_arr(cmd, struct short_channel_id, scidstok->size);
|
2019-01-17 03:12:13 +01:00
|
|
|
json_for_each_arr(i, t, scidstok) {
|
2019-09-06 08:41:41 +02:00
|
|
|
if (!json_to_short_channel_id(buffer, t, &scids[i])) {
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"scid %zu '%.*s' is not an scid",
|
|
|
|
i, json_tok_full_len(t),
|
|
|
|
json_tok_full(buffer, t));
|
2018-06-04 06:23:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell gossipd, since this is a gossip query. */
|
2018-08-14 23:19:31 +02:00
|
|
|
msg = towire_gossip_query_scids(cmd, id, scids);
|
2018-06-04 06:23:25 +02:00
|
|
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
|
|
|
take(msg), -1, 0, json_scids_reply, cmd);
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_still_pending(cmd);
|
2018-06-04 06:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_query_scids_command = {
|
|
|
|
"dev-query-scids",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2018-06-04 06:23:25 +02:00
|
|
|
json_dev_query_scids,
|
2018-09-11 22:54:29 +02:00
|
|
|
"Query peer {id} for [scids]"
|
2018-06-04 06:23:25 +02:00
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_query_scids_command);
|
2018-06-04 06:28:02 +02:00
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *
|
|
|
|
json_dev_send_timestamp_filter(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;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *id;
|
2018-08-10 22:16:22 +02:00
|
|
|
u32 *first, *range;
|
2018-06-04 06:28:02 +02:00
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-04-08 11:58:32 +02:00
|
|
|
p_req("id", param_node_id, &id),
|
2018-12-16 05:50:06 +01:00
|
|
|
p_req("first", param_number, &first),
|
|
|
|
p_req("range", param_number, &range),
|
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
|
|
|
|
2018-08-10 22:16:22 +02:00
|
|
|
log_debug(cmd->ld->log, "Setting timestamp range %u+%u", *first, *range);
|
2018-06-04 06:28:02 +02:00
|
|
|
/* Tell gossipd, since this is a gossip query. */
|
2018-08-14 23:19:31 +02:00
|
|
|
msg = towire_gossip_send_timestamp_filter(NULL, id, *first, *range);
|
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_send_timestamp_filter = {
|
|
|
|
"dev-send-timestamp-filter",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2018-06-04 06:28:02 +02:00
|
|
|
json_dev_send_timestamp_filter,
|
2018-09-11 22:54:29 +02:00
|
|
|
"Send peer {id} the timestamp filter {first} {range}"
|
2018-06-04 06:28:02 +02:00
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_send_timestamp_filter);
|
2018-06-04 06:28:02 +02:00
|
|
|
|
|
|
|
static void json_channel_range_reply(struct subd *gossip UNUSED, const u8 *reply,
|
|
|
|
const int *fds UNUSED, struct command *cmd)
|
|
|
|
{
|
2018-10-19 03:17:49 +02:00
|
|
|
struct json_stream *response;
|
2018-06-04 06:28:02 +02:00
|
|
|
u32 final_first_block, final_num_blocks;
|
|
|
|
bool final_complete;
|
|
|
|
struct short_channel_id *scids;
|
|
|
|
|
|
|
|
if (!fromwire_gossip_query_channel_range_reply(tmpctx, reply,
|
|
|
|
&final_first_block,
|
|
|
|
&final_num_blocks,
|
|
|
|
&final_complete,
|
|
|
|
&scids)) {
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Gossip gave bad gossip_query_channel_range_reply"));
|
2018-06-04 06:28:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (final_num_blocks == 0 && final_num_blocks == 0 && !final_complete) {
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_fail(cmd, LIGHTNINGD,
|
|
|
|
"Gossip refused to query peer"));
|
2018-06-04 06:28:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-19 03:17:48 +02:00
|
|
|
response = json_stream_success(cmd);
|
2018-06-04 06:38:42 +02:00
|
|
|
/* As this is a dev interface, we don't bother saving and
|
|
|
|
* returning all the replies, just the final one. */
|
2018-06-04 06:28:02 +02:00
|
|
|
json_add_num(response, "final_first_block", final_first_block);
|
|
|
|
json_add_num(response, "final_num_blocks", final_num_blocks);
|
|
|
|
json_add_bool(response, "final_complete", final_complete);
|
|
|
|
json_array_start(response, "short_channel_ids");
|
|
|
|
for (size_t i = 0; i < tal_count(scids); i++)
|
|
|
|
json_add_short_channel_id(response, NULL, &scids[i]);
|
|
|
|
json_array_end(response);
|
2018-12-16 05:53:06 +01:00
|
|
|
was_pending(command_success(cmd, response));
|
2018-06-04 06:28:02 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_dev_query_channel_range(struct command *cmd,
|
2018-06-04 06:28:02 +02:00
|
|
|
const char *buffer,
|
2018-12-08 01:34:56 +01:00
|
|
|
const jsmntok_t *obj UNNEEDED,
|
2018-06-04 06:28:02 +02:00
|
|
|
const jsmntok_t *params)
|
|
|
|
{
|
|
|
|
u8 *msg;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *id;
|
2018-08-10 22:16:22 +02:00
|
|
|
u32 *first, *num;
|
2018-06-04 06:28:02 +02:00
|
|
|
|
2018-07-16 22:48:38 +02:00
|
|
|
if (!param(cmd, buffer, params,
|
2019-04-08 11:58:32 +02:00
|
|
|
p_req("id", param_node_id, &id),
|
2018-12-16 05:50:06 +01:00
|
|
|
p_req("first", param_number, &first),
|
|
|
|
p_req("num", param_number, &num),
|
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
|
|
|
|
|
|
|
/* Tell gossipd, since this is a gossip query. */
|
2018-08-14 23:19:31 +02:00
|
|
|
msg = towire_gossip_query_channel_range(cmd, id, *first, *num);
|
2018-06-04 06:28:02 +02:00
|
|
|
subd_req(cmd->ld->gossip, cmd->ld->gossip,
|
|
|
|
take(msg), -1, 0, json_channel_range_reply, cmd);
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_still_pending(cmd);
|
2018-06-04 06:28:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_query_channel_range_command = {
|
|
|
|
"dev-query-channel-range",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2018-06-04 06:28:02 +02:00
|
|
|
json_dev_query_channel_range,
|
2018-09-11 22:54:29 +02:00
|
|
|
"Query peer {id} for short_channel_ids for {first} block + {num} blocks"
|
2018-06-04 06:28:02 +02:00
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_query_channel_range_command);
|
2018-06-04 06:28:02 +02:00
|
|
|
|
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
|
|
|
|
2018-08-10 22:16:22 +02:00
|
|
|
msg = towire_gossip_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
|
|
|
|
2018-12-16 05:52:06 +01:00
|
|
|
static struct command_result *json_dev_suppress_gossip(struct command *cmd,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *obj UNNEEDED,
|
|
|
|
const jsmntok_t *params)
|
2018-07-26 23:27:37 +02:00
|
|
|
{
|
|
|
|
if (!param(cmd, buffer, params, NULL))
|
2018-12-16 05:52:06 +01:00
|
|
|
return command_param_failed();
|
2018-07-26 23:27:37 +02:00
|
|
|
|
|
|
|
subd_send_msg(cmd->ld->gossip, take(towire_gossip_dev_suppress(NULL)));
|
|
|
|
|
2019-06-12 02:38:54 +02:00
|
|
|
return command_success(cmd, json_stream_success(cmd));
|
2018-07-26 23:27:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct json_command dev_suppress_gossip = {
|
|
|
|
"dev-suppress-gossip",
|
2019-05-22 16:08:16 +02:00
|
|
|
"developer",
|
2018-07-26 23:27:37 +02:00
|
|
|
json_dev_suppress_gossip,
|
|
|
|
"Stop this node from sending any more gossip."
|
|
|
|
};
|
|
|
|
AUTODATA(json_command, &dev_suppress_gossip);
|
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;
|
|
|
|
|
|
|
|
if (!fromwire_gossip_dev_compact_store_reply(reply, &success)) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
msg = towire_gossip_dev_compact_store(NULL);
|
|
|
|
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);
|
2018-06-04 06:23:25 +02:00
|
|
|
#endif /* DEVELOPER */
|