mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-12 10:30:29 +01:00
devtools/gossmap-compress: allow setting the nodeid explicitly for generated nodes.
This lets us make gossip which contains "real" nodes. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
296b3ce20c
commit
61ccf18521
3 changed files with 44 additions and 16 deletions
|
@ -277,10 +277,16 @@ static u64 get_delay(struct gossmap *gossmap,
|
|||
return chan->half[dir].delay;
|
||||
}
|
||||
|
||||
static void pubkey_for_node(size_t nodeidx, struct pubkey *key)
|
||||
static void pubkey_for_node(size_t nodeidx, struct pubkey *key,
|
||||
const struct pubkey *node_ids)
|
||||
{
|
||||
struct secret seckey;
|
||||
|
||||
if (nodeidx < tal_count(node_ids)) {
|
||||
*key = node_ids[nodeidx];
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&seckey, 1, sizeof(seckey));
|
||||
memcpy(&seckey, &nodeidx, sizeof(nodeidx));
|
||||
if (!pubkey_from_secret(&seckey, key))
|
||||
|
@ -324,7 +330,8 @@ static void write_announce(int outfd,
|
|||
size_t node1,
|
||||
size_t node2,
|
||||
u64 capacity,
|
||||
size_t i)
|
||||
size_t i,
|
||||
const struct pubkey *node_ids)
|
||||
{
|
||||
struct {
|
||||
secp256k1_ecdsa_signature sig;
|
||||
|
@ -336,8 +343,8 @@ static void write_announce(int outfd,
|
|||
struct node_id nodeid1, nodeid2;
|
||||
|
||||
memset(&vals, 0, sizeof(vals));
|
||||
pubkey_for_node(node1, &id1);
|
||||
pubkey_for_node(node2, &id2);
|
||||
pubkey_for_node(node1, &id1, node_ids);
|
||||
pubkey_for_node(node2, &id2, node_ids);
|
||||
|
||||
/* Nodes in pubkey order */
|
||||
if (pubkey_cmp(&id1, &id2) < 0) {
|
||||
|
@ -385,7 +392,8 @@ static void write_update(int outfd,
|
|||
u64 htlc_min, u64 htlc_max,
|
||||
u64 basefee,
|
||||
u32 propfee,
|
||||
u16 delay)
|
||||
u16 delay,
|
||||
const struct pubkey *node_ids)
|
||||
{
|
||||
struct vals {
|
||||
secp256k1_ecdsa_signature sig;
|
||||
|
@ -404,8 +412,8 @@ static void write_update(int outfd,
|
|||
abort();
|
||||
|
||||
/* If node ids are backward, dir is reversed */
|
||||
pubkey_for_node(node1, &id1);
|
||||
pubkey_for_node(node2, &id2);
|
||||
pubkey_for_node(node1, &id1, node_ids);
|
||||
pubkey_for_node(node2, &id2, node_ids);
|
||||
if (pubkey_cmp(&id1, &id2) > 0)
|
||||
dir = !dir;
|
||||
|
||||
|
@ -467,14 +475,32 @@ static char *opt_add_one(unsigned int *val)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static char *opt_nodes(const char *optarg, struct pubkey **node_ids)
|
||||
{
|
||||
char **ids = tal_strsplit(tmpctx, optarg, ",", STR_EMPTY_OK);
|
||||
|
||||
for (size_t i = 0; ids[i]; i++) {
|
||||
struct pubkey n;
|
||||
if (!pubkey_from_hexstr(ids[i], strlen(ids[i]), &n))
|
||||
return tal_fmt(tmpctx, "Invalid node id '%s'", ids[i]);
|
||||
tal_arr_expand(node_ids, n);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int infd, outfd;
|
||||
struct pubkey *node_ids;
|
||||
|
||||
common_setup(argv[0]);
|
||||
setup_locale();
|
||||
|
||||
node_ids = tal_arr(tmpctx, struct pubkey, 0);
|
||||
opt_register_noarg("--verbose|-v", opt_add_one, &verbose,
|
||||
"Print details (each additional gives more!).");
|
||||
opt_register_arg("--nodes", opt_nodes, NULL, &node_ids,
|
||||
"Comma separated node ids to give first nodes.");
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"[decompress|compress] infile outfile"
|
||||
"Compress or decompress a gossmap file",
|
||||
|
@ -643,15 +669,15 @@ int main(int argc, char *argv[])
|
|||
/* Useful so they can map their ids back to node ids. */
|
||||
for (size_t i = 0; i < node_limit; i++) {
|
||||
struct pubkey node_id;
|
||||
pubkey_for_node(i, &node_id);
|
||||
pubkey_for_node(i, &node_id, node_ids);
|
||||
printf("%s\n", fmt_pubkey(tmpctx, &node_id));
|
||||
}
|
||||
|
||||
if (verbose >= 2) {
|
||||
for (size_t i = 0; i < channel_count; i++) {
|
||||
struct pubkey id1, id2;
|
||||
pubkey_for_node(chans[i].node1, &id1);
|
||||
pubkey_for_node(chans[i].node2, &id2);
|
||||
pubkey_for_node(chans[i].node1, &id1, node_ids);
|
||||
pubkey_for_node(chans[i].node2, &id2, node_ids);
|
||||
printf("Channel %zu: %s -> %s\n",
|
||||
i,
|
||||
fmt_pubkey(tmpctx, &id1),
|
||||
|
@ -715,7 +741,7 @@ int main(int argc, char *argv[])
|
|||
chans[i].node1,
|
||||
chans[i].node2,
|
||||
chans[i].capacity,
|
||||
i);
|
||||
i, node_ids);
|
||||
for (size_t dir = 0; dir < 2; dir++) {
|
||||
write_update(outfd,
|
||||
chans[i].node1, chans[i].node2, i, dir,
|
||||
|
@ -724,7 +750,8 @@ int main(int argc, char *argv[])
|
|||
chans[i].half[dir].htlc_max,
|
||||
chans[i].half[dir].basefee,
|
||||
chans[i].half[dir].propfee,
|
||||
chans[i].half[dir].delay);
|
||||
chans[i].half[dir].delay,
|
||||
node_ids);
|
||||
}
|
||||
}
|
||||
gzclose(inf);
|
||||
|
|
|
@ -178,7 +178,7 @@ static fp16_t *get_capacities(const tal_t *ctx,
|
|||
* channels. This wouldn't be right if we looped back through ourselves,
|
||||
* but we won't. */
|
||||
/* FIXME: We could cache this until gossmap changes... */
|
||||
static void add_free_source(struct command *cmd,
|
||||
static void add_free_source(struct plugin *plugin,
|
||||
struct gossmap *gossmap,
|
||||
struct gossmap_localmods *localmods,
|
||||
const struct node_id *source)
|
||||
|
@ -206,7 +206,7 @@ static void add_free_source(struct command *cmd,
|
|||
/* Keep enabled flag */
|
||||
c->half[dir].enabled,
|
||||
dir))
|
||||
plugin_err(cmd->plugin, "Could not zero fee on local %s",
|
||||
plugin_err(plugin, "Could not zero fee on local %s",
|
||||
fmt_short_channel_id(tmpctx, scid));
|
||||
}
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ static const char *get_routes(struct command *cmd,
|
|||
}
|
||||
|
||||
if (have_layer(layers, "auto.sourcefree"))
|
||||
add_free_source(cmd, askrene->gossmap, localmods, source);
|
||||
add_free_source(cmd->plugin, askrene->gossmap, localmods, source);
|
||||
|
||||
/* Clear scids with reservations, too, so we don't have to look up
|
||||
* all the time! */
|
||||
|
|
|
@ -460,7 +460,7 @@ class GenChannel(object):
|
|||
self.half = [forward, reverse]
|
||||
|
||||
|
||||
def generate_gossip_store(channels):
|
||||
def generate_gossip_store(channels, nodeids=[]):
|
||||
"""Returns a gossip store file with the given channels in it, and a map of node labels -> ids
|
||||
"""
|
||||
nodes = []
|
||||
|
@ -550,6 +550,7 @@ def generate_gossip_store(channels):
|
|||
|
||||
outfile = tempfile.NamedTemporaryFile(prefix='gossip-store-')
|
||||
nodeids = subprocess.check_output(['devtools/gossmap-compress',
|
||||
'--nodes={}'.format(','.join(nodeids)),
|
||||
'decompress',
|
||||
cfile.name,
|
||||
outfile.name]).decode('utf-8').splitlines()
|
||||
|
|
Loading…
Add table
Reference in a new issue