diff --git a/common/gossmap.c b/common/gossmap.c index 0d9e2ac58..4a35ac34c 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -86,19 +87,12 @@ struct gossmap { /* local channel_update messages, if any. */ u8 *local_updates; - /* Callbacks for different events: return false to fail. */ - void (*cupdate_fail)(struct gossmap *map, - const struct short_channel_id_dir *scidd, - u16 cltv_expiry_delta, - u32 fee_base_msat, - u32 fee_proportional_millionths, - void *cb_arg); - bool (*unknown_record)(struct gossmap *map, - int type, - u64 off, - size_t msglen, - void *cb_arg); - void *cb_arg; + /* Optional logging callback */ + void (*logcb)(void *cbarg, + enum log_level level, + const char *fmt, + ...); + void *cbarg; }; /* Accessors for the gossmap */ @@ -183,18 +177,6 @@ static int map_feature_test(const struct gossmap *map, return -1; } -/* Helper callback which simply increments counter */ -static void cupdate_fail_inc_ctr(struct gossmap *map, - const struct short_channel_id_dir *scidd, - u16 cltv_expiry_delta, - u32 fee_base_msat, - u32 fee_proportional_millionths, - void *cb_arg) -{ - size_t *num = cb_arg; - (*num)++; -} - /* These values can change across calls to gossmap_check. */ u32 gossmap_max_node_idx(const struct gossmap *map) { @@ -476,10 +458,10 @@ static struct gossmap_chan *add_channel(struct gossmap *map, scid.u64 = map_be64(map, cannounce_off + plus_scid_off); chan = gossmap_find_chan(map, &scid); if (chan) { - /* FIXME: Report this better! */ - warnx("gossmap: redundant channel_announce for %s, offsets %"PRIu64" and %"PRIu64"!", - fmt_short_channel_id(tmpctx, scid), - chan->cann_off, cannounce_off); + map->logcb(map->cbarg, LOG_BROKEN, + "gossmap: redundant channel_announce for %s, offsets %"PRIu64" and %"PRIu64"!", + fmt_short_channel_id(tmpctx, scid), + chan->cann_off, cannounce_off); return NULL; } @@ -521,13 +503,11 @@ static void fill_from_update(struct gossmap *map, struct short_channel_id_dir *scidd, struct half_chan *hc, u64 cupdate_off, - void (*cupdate_fail)(struct gossmap *map, - const struct short_channel_id_dir *scidd, - u16 cltv_expiry_delta, - u32 fee_base_msat, - u32 fee_proportional_millionths, - void *cb_arg), - void *cb_arg) + void (*logcb)(void *cbarg, + enum log_level level, + const char *fmt, + ...), + void *cbarg) { /* Note that first two bytes are message type */ const u64 scid_off = cupdate_off + 2 + (64 + 32); @@ -558,16 +538,16 @@ static void fill_from_update(struct gossmap *map, hc->proportional_fee = proportional_fee; hc->delay = delay; - /* Check they fit: we turn off if not, call optional callback. */ + /* Check they fit: we turn off if not, log (at debug, it happens!). */ if (hc->base_fee != base_fee || hc->proportional_fee != proportional_fee || hc->delay != delay) { hc->htlc_max = 0; hc->enabled = false; - if (cupdate_fail) - cupdate_fail(map, scidd, - delay, base_fee, proportional_fee, - cb_arg); + logcb(cbarg, LOG_DBG, + "Bad cupdate for %s, ignoring (delta=%u, fee=%u/%u)", + fmt_short_channel_id_dir(tmpctx, scidd), + delay, base_fee, proportional_fee); } } @@ -593,7 +573,7 @@ static void update_channel(struct gossmap *map, u64 cupdate_off) struct half_chan hc; fill_from_update(map, &scidd, &hc, cupdate_off, - map->cupdate_fail, map->cb_arg); + map->logcb, map->cbarg); chan = gossmap_find_chan(map, &scidd.scid); /* This can happen if channel gets deleted! */ if (!chan) @@ -670,16 +650,15 @@ static bool reopen_store(struct gossmap *map, u64 ended_off) close(map->fd); map->fd = fd; map->generation++; - return gossmap_refresh_mayfail(map, NULL); + return gossmap_refresh(map); } /* Returns false only if unknown_cb returns false */ -static bool map_catchup(struct gossmap *map, bool *changed) +static bool map_catchup(struct gossmap *map) { size_t reclen; + bool changed = false; - if (changed) - *changed = false; for (; map->map_end + sizeof(struct gossip_hdr) < map->map_size; map->map_end += reclen) { struct gossip_hdr ghdr; @@ -715,23 +694,24 @@ static bool map_catchup(struct gossmap *map, bool *changed) node_announcement(map, off); else if (type == WIRE_GOSSIP_STORE_ENDED) { /* This can recurse! */ - if (!reopen_store(map, off)) - return false; + return reopen_store(map, off) || changed; + } else if (type == WIRE_GOSSIP_STORE_CHANNEL_AMOUNT) { + /* We absorbed this in add_channel; ignore */ + continue; + } else if (type == WIRE_GOSSIP_STORE_CHAN_DYING) { + /* We don't really care until it's deleted */ + continue; } else { - if (map->unknown_record - && !map->unknown_record(map, type, off, - reclen - sizeof(ghdr), - map->cb_arg)) { - return false; - } + map->logcb(map->cbarg, LOG_BROKEN, + "Unknown record %u@%u (size %zu) in gossmap: ignoring", + type, off, reclen - sizeof(ghdr)); continue; } - if (changed) - *changed = true; + changed = true; } - return true; + return changed; } static bool load_gossip_store(struct gossmap *map) @@ -772,7 +752,7 @@ static bool load_gossip_store(struct gossmap *map) map->freed_nodes = init_node_arr(map->node_arr, 0); map->map_end = 1; - map_catchup(map, NULL); + map_catchup(map); return true; } @@ -1163,7 +1143,7 @@ void gossmap_remove_localmods(struct gossmap *map, map->local_updates = tal_free(map->local_updates); } -bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated) +bool gossmap_refresh(struct gossmap *map) { off_t len; @@ -1172,11 +1152,8 @@ bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated) /* If file has gotten larger, try rereading */ len = lseek(map->fd, 0, SEEK_END); - if (len == map->map_size) { - if (updated) - *updated = false; - return true; - } + if (len == map->map_size) + return false; if (map->mmap) munmap(map->mmap, map->map_size); @@ -1188,55 +1165,48 @@ bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated) #endif /* __OpenBSD__ */ map->mmap = NULL; - return map_catchup(map, updated); + return map_catchup(map); } -bool gossmap_refresh(struct gossmap *map, size_t *num_rejected) +static void log_stderr(void *cb_arg, + enum log_level level, + const char *fmt, + ...) { - bool updated; - void (*old_cupdate_fail)(struct gossmap *map, - const struct short_channel_id_dir *scidd, - u16 cltv_expiry_delta, - u32 fee_base_msat, - u32 fee_proportional_millionths, - void *cb_arg); + va_list ap; - /* If they asked for counter, temporarily override cb */ - old_cupdate_fail = map->cupdate_fail; - if (num_rejected) { - map->cupdate_fail = cupdate_fail_inc_ctr; - map->cb_arg = num_rejected; - } + /* Don't spam stderr */ + if (level < LOG_UNUSUAL) + return; - /* This can only fail if you set unknown_cb, and it failed. So wrong API! */ - if (!gossmap_refresh_mayfail(map, &updated)) - abort(); - - map->cupdate_fail = old_cupdate_fail; - return updated; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); } -struct gossmap *gossmap_load(const tal_t *ctx, const char *filename, - size_t *num_channel_updates_rejected) +struct gossmap *gossmap_load_(const tal_t *ctx, + const char *filename, + void (*logcb)(void *cb_arg, + enum log_level level, + const char *fmt, + ...), + void *cbarg) { map = tal(ctx, struct gossmap); map->generation = 0; map->fname = tal_strdup(map, filename); map->fd = open(map->fname, O_RDONLY); - if (map->fd < 0) + if (map->fd < 0) return tal_free(map); + if (logcb) + map->logcb = logcb; + else + map->logcb = log_stderr; + map->cbarg = cbarg; tal_add_destructor(map, destroy_map); - if (num_channel_updates_rejected) { - *num_channel_updates_rejected = 0; - map->cupdate_fail = cupdate_fail_inc_ctr; - map->cb_arg = num_channel_updates_rejected; - } else - map->cupdate_fail = NULL; - map->unknown_record = NULL; if (!load_gossip_store(map)) return tal_free(map); - map->cupdate_fail = NULL; return map; } diff --git a/common/gossmap.h b/common/gossmap.h index ad6d8630e..5b5d46925 100644 --- a/common/gossmap.h +++ b/common/gossmap.h @@ -6,6 +6,7 @@ #include #include #include +#include struct node_id; struct sciddir_or_pubkey; @@ -42,15 +43,25 @@ struct gossmap_chan { /* If num_channel_updates_rejected is not NULL, indicates how many channels we * marked inactive because their values were too high to be represented. */ -struct gossmap *gossmap_load(const tal_t *ctx, const char *filename, - size_t *num_channel_updates_rejected); +#define gossmap_load(ctx, filename, logcb, cbarg) \ + gossmap_load_((ctx), (filename), \ + typesafe_cb_postargs(void, void *, (logcb), (cbarg), \ + enum log_level, \ + const char *fmt, \ + ...), \ + (cbarg)) + +struct gossmap *gossmap_load_(const tal_t *ctx, + const char *filename, + void (*logcb)(void *cb_arg, + enum log_level level, + const char *fmt, + ...), + void *cb_arg); /* Call this before using to ensure it's up-to-date. Returns true if something * was updated. Note: this can scramble node and chan indexes! */ -bool gossmap_refresh(struct gossmap *map, size_t *num_channel_updates_rejected); - -/* Call this if you have set unknown_cb, and thus this can fail! */ -bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated); +bool gossmap_refresh(struct gossmap *map); /* Local modifications. */ struct gossmap_localmods *gossmap_localmods_new(const tal_t *ctx); diff --git a/common/test/run-gossmap_canned.c b/common/test/run-gossmap_canned.c index eef6467cf..c373248d9 100644 --- a/common/test/run-gossmap_canned.c +++ b/common/test/run-gossmap_canned.c @@ -326,7 +326,7 @@ int main(int argc, char *argv[]) fd = tmpdir_mkstemp(tmpctx, "run-gossip_canned.XXXXXX", &gossfile); assert(write_all(fd, canned_map, sizeof(canned_map))); - map = gossmap_load(tmpctx, gossfile, NULL); + map = gossmap_load(tmpctx, gossfile, NULL, NULL); assert(map); /* There is a channel 1<->2 (103x1x0) */ diff --git a/common/test/run-gossmap_local.c b/common/test/run-gossmap_local.c index b9ad6808d..a2f226874 100644 --- a/common/test/run-gossmap_local.c +++ b/common/test/run-gossmap_local.c @@ -348,7 +348,7 @@ int main(int argc, char *argv[]) fd = tmpdir_mkstemp(tmpctx, "run-gossip_local.XXXXXX", &gossfile); assert(write_all(fd, canned_map, sizeof(canned_map))); - map = gossmap_load(tmpctx, gossfile, NULL); + map = gossmap_load(tmpctx, gossfile, NULL, NULL); assert(map); /* There is a public channel 2<->3 (103x1x0), and private @@ -599,6 +599,6 @@ int main(int argc, char *argv[]) /* Now we can refresh. */ assert(write(fd, "", 1) == 1); - gossmap_refresh(map, NULL); + gossmap_refresh(map); common_shutdown(); } diff --git a/common/test/run-route-infloop.c b/common/test/run-route-infloop.c index bec98e232..c2e532fe5 100644 --- a/common/test/run-route-infloop.c +++ b/common/test/run-route-infloop.c @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) amt = 8388607; else amt = atol(argv[1]); - gossmap = gossmap_load(tmpctx, "tests/data/routing_gossip_store", NULL); + gossmap = gossmap_load(tmpctx, "tests/data/routing_gossip_store", NULL, NULL); nodes = tal_arr(tmpctx, const struct gossmap_node *, 0); for (struct gossmap_node *n = gossmap_first_node(gossmap); diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index 77ffb8da4..4c2c5067a 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -215,7 +215,7 @@ int main(int argc, char *argv[]) assert(write(store_fd, &gossip_version, sizeof(gossip_version)) == sizeof(gossip_version)); - gossmap = gossmap_load(tmpctx, gossipfilename, NULL); + gossmap = gossmap_load(tmpctx, gossipfilename, NULL, NULL); /* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */ add_connection(store_fd, &c, &b, "6990x2x1", @@ -237,7 +237,7 @@ int main(int argc, char *argv[]) AMOUNT_MSAT(0), AMOUNT_MSAT(1000), 0, 10, 5, false); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); a_node = gossmap_find_node(gossmap, &a); b_node = gossmap_find_node(gossmap, &b); @@ -283,7 +283,7 @@ int main(int argc, char *argv[]) add_connection(store_fd, &a, &d, "6991x2x1", AMOUNT_MSAT(100), AMOUNT_MSAT(499968), /* exact repr in fp16! */ 0, 0, 5); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); a_node = gossmap_find_node(gossmap, &a); b_node = gossmap_find_node(gossmap, &b); diff --git a/common/test/run-route.c b/common/test/run-route.c index 638c688af..70e367576 100644 --- a/common/test/run-route.c +++ b/common/test/run-route.c @@ -195,18 +195,18 @@ int main(int argc, char *argv[]) store_fd = tmpdir_mkstemp(tmpctx, "run-route-gossipstore.XXXXXX", &gossipfilename); assert(write(store_fd, &gossip_version, sizeof(gossip_version)) == sizeof(gossip_version)); - gossmap = gossmap_load(tmpctx, gossipfilename, NULL); + gossmap = gossmap_load(tmpctx, gossipfilename, NULL, NULL); memset(&tmp, 'a', sizeof(tmp)); node_id_from_privkey(&tmp, &a); memset(&tmp, 'b', sizeof(tmp)); node_id_from_privkey(&tmp, &b); - assert(!gossmap_refresh(gossmap, NULL)); + assert(!gossmap_refresh(gossmap)); /* A<->B */ add_connection(store_fd, &a, &b, 1, 1, 1); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); a_node = gossmap_find_node(gossmap, &a); b_node = gossmap_find_node(gossmap, &b); @@ -224,7 +224,7 @@ int main(int argc, char *argv[]) memset(&tmp, 'c', sizeof(tmp)); node_id_from_privkey(&tmp, &c); add_connection(store_fd, &b, &c, 1, 1, 1); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); /* These can theoretically change after refresh! */ a_node = gossmap_find_node(gossmap, &a); @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) add_connection(store_fd, &a, &d, 0, 2, 1); add_connection(store_fd, &d, &c, 0, 2, 1); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); /* These can theoretically change after refresh! */ a_node = gossmap_find_node(gossmap, &a); @@ -289,7 +289,7 @@ int main(int argc, char *argv[]) /* Make B->C inactive, force it back via D */ update_connection(store_fd, &b, &c, 1, 1, 1, true); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); /* These can theoretically change after refresh! */ a_node = gossmap_find_node(gossmap, &a); diff --git a/connectd/connectd.c b/connectd/connectd.c index 881db38fe..2cd055a6b 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -2287,11 +2287,24 @@ void update_recent_timestamp(struct daemon *daemon, struct gossmap *gossmap) recent); } +static void connectd_logcb(struct daemon *daemon, + enum log_level level, + const char *fmt, + ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vfmt(level, NULL, fmt, ap); + va_end(ap); +} + /* This is called once we need it: otherwise, the gossip_store may not exist, * since we start at the same time as gossipd itself. */ static void setup_gossip_store(struct daemon *daemon) { - daemon->gossmap_raw = gossmap_load(daemon, GOSSIP_STORE_FILENAME, NULL); + daemon->gossmap_raw = gossmap_load(daemon, GOSSIP_STORE_FILENAME, + connectd_logcb, daemon); if (!daemon->gossmap_raw) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Loading gossip_store %s: %s", @@ -2307,7 +2320,7 @@ struct gossmap *get_gossmap(struct daemon *daemon) if (!daemon->gossmap_raw) setup_gossip_store(daemon); else - gossmap_refresh(daemon->gossmap_raw, NULL); + gossmap_refresh(daemon->gossmap_raw); return daemon->gossmap_raw; } diff --git a/devtools/gossmap-compress.c b/devtools/gossmap-compress.c index 3f45e01ff..0847fc1bf 100644 --- a/devtools/gossmap-compress.c +++ b/devtools/gossmap-compress.c @@ -554,7 +554,7 @@ int main(int argc, char *argv[]) bool *dirs; gzFile outf = gzdopen(outfd, "wb9"); - struct gossmap *gossmap = gossmap_load(tmpctx, argv[2], NULL); + struct gossmap *gossmap = gossmap_load(tmpctx, argv[2], NULL, NULL); if (!gossmap) opt_usage_exit_fail(tal_fmt(tmpctx, "Cannot open %s for reading: %s", argv[2], strerror(errno))); diff --git a/devtools/route.c b/devtools/route.c index 8fe64a4d7..684d04cb7 100644 --- a/devtools/route.c +++ b/devtools/route.c @@ -68,7 +68,6 @@ int main(int argc, char *argv[]) struct gossmap *map; struct node_id dstid; bool clean_topology = false; - size_t num_channel_updates_rejected; common_setup(argv[0]); @@ -83,14 +82,13 @@ int main(int argc, char *argv[]) opt_usage_exit_fail("Expect 3 arguments"); tstart = time_mono(); - map = gossmap_load(NULL, argv[1], &num_channel_updates_rejected); + map = gossmap_load(NULL, argv[1], NULL, NULL); if (!map) err(1, "Loading gossip store %s", argv[1]); tstop = time_mono(); - printf("# Time to load: %"PRIu64" msec (%zu ignored)\n", - time_to_msec(timemono_between(tstop, tstart)), - num_channel_updates_rejected); + printf("# Time to load: %"PRIu64" msec\n", + time_to_msec(timemono_between(tstop, tstart))); if (clean_topology) clean_topo(map, false); diff --git a/devtools/topology.c b/devtools/topology.c index ccb86d3c1..649e66953 100644 --- a/devtools/topology.c +++ b/devtools/topology.c @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) opt_usage_exit_fail("Expect 3 arguments"); tstart = time_mono(); - map = gossmap_load(NULL, argv[1], NULL); + map = gossmap_load(NULL, argv[1], NULL, NULL); if (!map) err(1, "Loading gossip store %s", argv[1]); tstop = time_mono(); diff --git a/gossipd/gossmap_manage.c b/gossipd/gossmap_manage.c index 4e71a9902..19ce40c80 100644 --- a/gossipd/gossmap_manage.c +++ b/gossipd/gossmap_manage.c @@ -407,13 +407,26 @@ static void start_prune_timer(struct gossmap_manage *gm) static void reprocess_queued_msgs(struct gossmap_manage *gm); +static void gossmap_logcb(struct daemon *daemon, + enum log_level level, + const char *fmt, + ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vfmt(level, NULL, fmt, ap); + va_end(ap); +} + struct gossmap_manage *gossmap_manage_new(const tal_t *ctx, struct daemon *daemon, struct chan_dying *dying_channels TAKES) { struct gossmap_manage *gm = tal(ctx, struct gossmap_manage); - gm->raw_gossmap = gossmap_load(gm, GOSSIP_STORE_FILENAME, NULL); + gm->raw_gossmap = gossmap_load(gm, GOSSIP_STORE_FILENAME, + gossmap_logcb, daemon); assert(gm->raw_gossmap); gm->daemon = daemon; @@ -1309,7 +1322,7 @@ void gossmap_manage_channel_spent(struct gossmap_manage *gm, struct gossmap *gossmap_manage_get_gossmap(struct gossmap_manage *gm) { - gossmap_refresh(gm->raw_gossmap, NULL); + gossmap_refresh(gm->raw_gossmap); return gm->raw_gossmap; } diff --git a/plugins/askrene/askrene.c b/plugins/askrene/askrene.c index d8c82883f..57631bb5a 100644 --- a/plugins/askrene/askrene.c +++ b/plugins/askrene/askrene.c @@ -334,7 +334,7 @@ static const char *get_routes(const tal_t *ctx, u32 mu; const char *ret; - if (gossmap_refresh(askrene->gossmap, NULL)) { + if (gossmap_refresh(askrene->gossmap)) { /* FIXME: gossmap_refresh callbacks to we can update in place */ tal_free(askrene->capacities); askrene->capacities = get_capacities(askrene, askrene->plugin, askrene->gossmap); @@ -1245,7 +1245,8 @@ static const char *init(struct command *init_cmd, askrene->plugin = plugin; list_head_init(&askrene->layers); askrene->reserved = new_reserve_htable(askrene); - askrene->gossmap = gossmap_load(askrene, GOSSIP_STORE_FILENAME, NULL); + askrene->gossmap = gossmap_load(askrene, GOSSIP_STORE_FILENAME, + plugin_gossmap_logcb, plugin); if (!askrene->gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 19ba39e42..0fe5472a5 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -24,18 +24,14 @@ static bool got_gossmap; static void init_gossmap(struct plugin *plugin) { - size_t num_channel_updates_rejected; global_gossmap = notleak_with_children(gossmap_load(NULL, GOSSIP_STORE_FILENAME, - &num_channel_updates_rejected)); + plugin_gossmap_logcb, + plugin)); if (!global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); - if (num_channel_updates_rejected) - plugin_log(plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_channel_updates_rejected); } struct gossmap *get_raw_gossmap(struct payment *payment) @@ -44,7 +40,7 @@ struct gossmap *get_raw_gossmap(struct payment *payment) if (!global_gossmap) init_gossmap(payment->plugin); else - gossmap_refresh(global_gossmap, NULL); + gossmap_refresh(global_gossmap); return global_gossmap; } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index abec61038..51936be1c 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -1840,6 +1840,18 @@ void plugin_logv(struct plugin *p, enum log_level l, jsonrpc_finish_and_send(p, js); } +void plugin_gossmap_logcb(struct plugin *plugin, + enum log_level level, + const char *fmt, + ...) +{ + va_list ap; + + va_start(ap, fmt); + plugin_logv(plugin, level, fmt, ap); + va_end(ap); +} + struct json_stream *plugin_notification_start(struct plugin *plugin, const char *method) { diff --git a/plugins/libplugin.h b/plugins/libplugin.h index b7c2fc44e..09a29a97f 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -522,6 +522,12 @@ struct plugin_timer *command_timer_(struct command *cmd, void plugin_log(struct plugin *p, enum log_level l, const char *fmt, ...) PRINTF_FMT(3, 4); void plugin_logv(struct plugin *p, enum log_level l, const char *fmt, va_list ap); +/* plogin_logv wrapper for gossmap */ +void plugin_gossmap_logcb(struct plugin *plugin, + enum log_level level, + const char *fmt, + ...); + /* Notify the caller of something. */ struct json_stream *plugin_notify_start(struct command *cmd, const char *method); void plugin_notify_end(struct command *cmd, struct json_stream *js); diff --git a/plugins/offers.c b/plugins/offers.c index 47c40dcf0..c1325e3e5 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -43,18 +43,14 @@ static struct gossmap *global_gossmap; static void init_gossmap(struct plugin *plugin) { - size_t num_cupdates_rejected; global_gossmap = notleak_with_children(gossmap_load(plugin, GOSSIP_STORE_FILENAME, - &num_cupdates_rejected)); + plugin_gossmap_logcb, + plugin)); if (!global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); - if (num_cupdates_rejected) - plugin_log(plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_cupdates_rejected); } struct gossmap *get_gossmap(struct plugin *plugin) @@ -62,7 +58,7 @@ struct gossmap *get_gossmap(struct plugin *plugin) if (!global_gossmap) init_gossmap(plugin); else - gossmap_refresh(global_gossmap, NULL); + gossmap_refresh(global_gossmap); return global_gossmap; } diff --git a/plugins/recover.c b/plugins/recover.c index 6ceee127a..fcc7b74f8 100644 --- a/plugins/recover.c +++ b/plugins/recover.c @@ -116,7 +116,7 @@ static struct command_result *do_check_gossip(struct command *cmd, void *unused) { find_exes_timer = NULL; - gossmap_refresh(global_gossmap, NULL); + gossmap_refresh(global_gossmap); plugin_log(plugin, LOG_DBG, "Finding our node in gossip"); @@ -257,7 +257,6 @@ static const char *init(struct command *init_cmd, lost_state_timer = global_timer(plugin, time_from_sec(STARTUP_TIME), do_check_lost_peer, NULL); u32 num_peers; - size_t num_cupdates_rejected; /* Find number of peers */ rpc_scan(init_cmd, "getinfo", @@ -268,17 +267,13 @@ static const char *init(struct command *init_cmd, global_gossmap = notleak_with_children(gossmap_load(NULL, GOSSIP_STORE_FILENAME, - &num_cupdates_rejected)); + plugin_gossmap_logcb, + plugin)); if (!global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); - if (num_cupdates_rejected) - plugin_log(plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_cupdates_rejected); - plugin_log(plugin, LOG_DBG, "Gossmap loaded!"); already_has_peers = num_peers > 1 ? 1: 0; diff --git a/plugins/renepay/main.c b/plugins/renepay/main.c index 6b0be1c28..c9b6e65bd 100644 --- a/plugins/renepay/main.c +++ b/plugins/renepay/main.c @@ -72,7 +72,8 @@ static const char *init(struct command *init_cmd, pay_plugin->gossmap = gossmap_load(pay_plugin, GOSSIP_STORE_FILENAME, - &num_channel_updates_rejected); + plugin_gossmap_logcb, + p); if (!pay_plugin->gossmap) plugin_err(p, "Could not load gossmap %s: %s", diff --git a/plugins/renepay/mods.c b/plugins/renepay/mods.c index dd601f23b..aa43fa131 100644 --- a/plugins/renepay/mods.c +++ b/plugins/renepay/mods.c @@ -476,14 +476,7 @@ static struct command_result *refreshgossmap_cb(struct payment *payment) assert(payment); assert(payment->local_gossmods); - size_t num_channel_updates_rejected = 0; - bool gossmap_changed = - gossmap_refresh(pay_plugin->gossmap, &num_channel_updates_rejected); - - if (gossmap_changed && num_channel_updates_rejected) - plugin_log(pay_plugin->plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_channel_updates_rejected); + bool gossmap_changed = gossmap_refresh(pay_plugin->gossmap); if (gossmap_changed) { gossmap_apply_localmods(pay_plugin->gossmap, diff --git a/plugins/renepay/test/run-bottleneck.c b/plugins/renepay/test/run-bottleneck.c index 2173ebd54..9aa62115a 100644 --- a/plugins/renepay/test/run-bottleneck.c +++ b/plugins/renepay/test/run-bottleneck.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) tal_add_destructor(gossfile, remove_file); assert(write(fd, empty_map, sizeof(empty_map)) == sizeof(empty_map)); - gossmap = gossmap_load(tmpctx, gossfile, NULL); + gossmap = gossmap_load(tmpctx, gossfile, NULL, NULL); assert(gossmap); for (size_t i = 0; i < NUM_NODES; i++) { @@ -174,7 +174,7 @@ int main(int argc, char *argv[]) 0, 0, 5, AMOUNT_SAT(1000 * 1000)); - assert(gossmap_refresh(gossmap, NULL)); + assert(gossmap_refresh(gossmap)); struct uncertainty *uncertainty = uncertainty_new(tmpctx); int skipped_count = uncertainty_update(uncertainty, gossmap); diff --git a/plugins/renepay/test/run-mcf-diamond.c b/plugins/renepay/test/run-mcf-diamond.c index 2db20d6e8..59eb99790 100644 --- a/plugins/renepay/test/run-mcf-diamond.c +++ b/plugins/renepay/test/run-mcf-diamond.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) tal_add_destructor(gossfile, remove_file); assert(write_all(fd, empty_map, sizeof(empty_map))); - gossmap = gossmap_load(tmpctx, gossfile, NULL); + gossmap = gossmap_load(tmpctx, gossfile, NULL, NULL); assert(gossmap); /* These are in ascending order, for easy direction setting */ diff --git a/plugins/renepay/test/run-mcf.c b/plugins/renepay/test/run-mcf.c index 487304918..1a95dff44 100644 --- a/plugins/renepay/test/run-mcf.c +++ b/plugins/renepay/test/run-mcf.c @@ -371,7 +371,7 @@ int main(int argc, char *argv[]) tal_add_destructor(gossfile, remove_file); assert(write_all(fd, canned_map, sizeof(canned_map))); - gossmap = gossmap_load(tmpctx, gossfile, NULL); + gossmap = gossmap_load(tmpctx, gossfile, NULL, NULL); assert(gossmap); /* There is a public channel 2<->3 (103x1x0), and 1<->2 (110x1x1). */ diff --git a/plugins/renepay/test/run-testflow.c b/plugins/renepay/test/run-testflow.c index a570fd9eb..ffed14f7e 100644 --- a/plugins/renepay/test/run-testflow.c +++ b/plugins/renepay/test/run-testflow.c @@ -534,7 +534,7 @@ static void test_flow_to_route(void) tal_add_destructor(gossfile, remove_file); assert(write_all(fd,canned_map,sizeof(canned_map))); - struct gossmap *gossmap = gossmap_load(this_ctx,gossfile,NULL); + struct gossmap *gossmap = gossmap_load(this_ctx,gossfile,NULL,NULL); assert(gossmap); // for(struct gossmap_node *node = gossmap_first_node(gossmap); @@ -764,7 +764,7 @@ static void test_channel_maximum_forward(void) tal_add_destructor(gossfile, remove_file); assert(write_all(fd, canned_map, sizeof(canned_map))); - struct gossmap *gossmap = gossmap_load(this_ctx, gossfile, NULL); + struct gossmap *gossmap = gossmap_load(this_ctx, gossfile, NULL, NULL); assert(gossmap); struct short_channel_id scid12; diff --git a/plugins/test/run-route-calc.c b/plugins/test/run-route-calc.c index 98c3e61f3..ab1a6f4e6 100644 --- a/plugins/test/run-route-calc.c +++ b/plugins/test/run-route-calc.c @@ -285,6 +285,12 @@ void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED) /* Generated stub for plugin_err */ void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "plugin_err called!\n"); abort(); } +/* Generated stub for plugin_gossmap_logcb */ +void plugin_gossmap_logcb(struct plugin *plugin UNNEEDED, + enum log_level level UNNEEDED, + const char *fmt UNNEEDED, + ...) +{ fprintf(stderr, "plugin_gossmap_logcb called!\n"); abort(); } /* Generated stub for plugin_log */ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "plugin_log called!\n"); abort(); } @@ -525,7 +531,7 @@ int main(int argc, char *argv[]) amount_sat(100 + 100000000 * !i)); path[3] = scids[!i]; - gossmap = gossmap_load(tmpctx, gossipfilename, NULL); + gossmap = gossmap_load(tmpctx, gossipfilename, NULL, NULL); global_gossmap = gossmap; node_id('A', &src); diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 5fc606f5e..6bec011b3 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -282,6 +282,12 @@ void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED) /* Generated stub for plugin_err */ void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "plugin_err called!\n"); abort(); } +/* Generated stub for plugin_gossmap_logcb */ +void plugin_gossmap_logcb(struct plugin *plugin UNNEEDED, + enum log_level level UNNEEDED, + const char *fmt UNNEEDED, + ...) +{ fprintf(stderr, "plugin_gossmap_logcb called!\n"); abort(); } /* Generated stub for plugin_log */ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "plugin_log called!\n"); abort(); } @@ -449,7 +455,7 @@ int main(int argc, char *argv[]) assert(write(store_fd, &gossip_version, sizeof(gossip_version)) == sizeof(gossip_version)); - global_gossmap = gossmap_load(tmpctx, gossipfilename, NULL); + global_gossmap = gossmap_load(tmpctx, gossipfilename, NULL, NULL); for (size_t i = 0; i < NUM_NODES; i++) { struct privkey tmp; @@ -488,7 +494,7 @@ int main(int argc, char *argv[]) 1 << i); } - assert(gossmap_refresh(global_gossmap, NULL)); + assert(gossmap_refresh(global_gossmap)); for (size_t i = ROUTING_MAX_HOPS; i > 2; i--) { struct gossmap_node *dst, *src; struct route_hop *r; diff --git a/plugins/topology.c b/plugins/topology.c index b02e5df55..dcb62325e 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -24,7 +24,7 @@ static struct plugin *plugin; /* We load this on demand, since we can start before gossipd. */ static struct gossmap *get_gossmap(void) { - gossmap_refresh(global_gossmap, NULL); + gossmap_refresh(global_gossmap); return global_gossmap; } @@ -702,8 +702,6 @@ static void memleak_mark(struct plugin *p, struct htable *memtable) static const char *init(struct command *init_cmd, const char *buf UNUSED, const jsmntok_t *config UNUSED) { - size_t num_cupdates_rejected; - plugin = init_cmd->plugin; rpc_scan(init_cmd, "getinfo", take(json_out_obj(NULL, NULL, NULL)), @@ -711,15 +709,11 @@ static const char *init(struct command *init_cmd, global_gossmap = gossmap_load(NULL, GOSSIP_STORE_FILENAME, - &num_cupdates_rejected); + plugin_gossmap_logcb, plugin); if (!global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); - if (num_cupdates_rejected) - plugin_log(plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_cupdates_rejected); plugin_set_memleak_handler(plugin, memleak_mark); return NULL; } diff --git a/plugins/xpay/xpay.c b/plugins/xpay/xpay.c index 20d42e9c5..1eb1b51c6 100644 --- a/plugins/xpay/xpay.c +++ b/plugins/xpay/xpay.c @@ -46,7 +46,7 @@ static struct xpay *xpay_of(struct plugin *plugin) /* This refreshes the gossmap. */ static struct gossmap *get_gossmap(struct xpay *xpay) { - gossmap_refresh(xpay->global_gossmap, NULL); + gossmap_refresh(xpay->global_gossmap); return xpay->global_gossmap; } @@ -1733,21 +1733,15 @@ static const char *init(struct command *init_cmd, { struct plugin *plugin = init_cmd->plugin; struct xpay *xpay = xpay_of(plugin); - size_t num_cupdates_rejected; struct out_req *req; xpay->global_gossmap = gossmap_load(xpay, GOSSIP_STORE_FILENAME, - &num_cupdates_rejected); + plugin_gossmap_logcb, + plugin); if (!xpay->global_gossmap) plugin_err(plugin, "Could not load gossmap %s: %s", GOSSIP_STORE_FILENAME, strerror(errno)); - - if (num_cupdates_rejected) - plugin_log(plugin, LOG_DBG, - "gossmap ignored %zu channel updates", - num_cupdates_rejected); - xpay->counter = 0; if (!pubkey_from_hexstr("02" "0000000000000000000000000000000000000000000000000000000000000001", 66, &xpay->fakenode)) abort(); diff --git a/tests/plugins/channeld_fakenet.c b/tests/plugins/channeld_fakenet.c index 34396599e..2d848a5ab 100644 --- a/tests/plugins/channeld_fakenet.c +++ b/tests/plugins/channeld_fakenet.c @@ -1287,7 +1287,7 @@ int main(int argc, char *argv[]) status_setup_async(info->dc); - info->gossmap = gossmap_load(info, GOSSIP_STORE_FILENAME, NULL); + info->gossmap = gossmap_load(info, GOSSIP_STORE_FILENAME, NULL, NULL); if (!info->gossmap) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Loading gossmap %s", strerror(errno));