Skip to content

Commit 1dda0c0

Browse files
committed
bookkeeper: don't flood logs if we have many channelmoves all at once.
Since we're synchronous, these only reach lightningd after we're done: in the case of 1.6M channelmoves, that can give it major heartburn. In practice, this reduces the first bkpr command on a fresh upgrade from 349 to 235 seconds (but this was before other improvements we did this release). Signed-off-by: Rusty Russell <[email protected]> Changelog-Changed: Plugins: `bookkeeper` reduced logging for large imports to increase speed.
1 parent ac60568 commit 1dda0c0

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

plugins/bkpr/bookkeeper.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static void
8787
parse_and_log_channel_move(struct command *cmd,
8888
const char *buf,
8989
const jsmntok_t *channelmove,
90-
struct refresh_info *rinfo);
90+
struct refresh_info *rinfo,
91+
bool log);
9192

9293
static struct command_result *datastore_done(struct command *cmd,
9394
const char *method,
@@ -120,8 +121,15 @@ static struct command_result *listchannelmoves_done(struct command *cmd,
120121
be64 be_index;
121122

122123
moves = json_get_member(buf, result, "channelmoves");
124+
if (moves->size > 2) {
125+
plugin_log(cmd->plugin, LOG_DBG,
126+
"%u channelmoves, only logging first and last",
127+
moves->size);
128+
}
129+
123130
json_for_each_arr(i, t, moves)
124-
parse_and_log_channel_move(cmd, buf, t, rinfo);
131+
parse_and_log_channel_move(cmd, buf, t, rinfo,
132+
i == 0 || i == moves->size - 1);
125133

126134
be_index = cpu_to_be64(bkpr->channelmoves_index);
127135
jsonrpc_set_datastore_binary(cmd, "bookkeeper/channelmoves_index",
@@ -1277,7 +1285,8 @@ static void
12771285
parse_and_log_channel_move(struct command *cmd,
12781286
const char *buf,
12791287
const jsmntok_t *channelmove,
1280-
struct refresh_info *rinfo)
1288+
struct refresh_info *rinfo,
1289+
bool log)
12811290
{
12821291
struct channel_event *e = tal(cmd, struct channel_event);
12831292
struct account *acct;
@@ -1324,11 +1333,12 @@ parse_and_log_channel_move(struct command *cmd,
13241333
err = tal_free(err);
13251334
}
13261335

1327-
plugin_log(cmd->plugin, LOG_DBG, "coin_move 2 (%s) %s -%s %s %"PRIu64,
1328-
e->tag,
1329-
fmt_amount_msat(tmpctx, e->credit),
1330-
fmt_amount_msat(tmpctx, e->debit),
1331-
CHANNEL_MOVE, e->timestamp);
1336+
if (log)
1337+
plugin_log(cmd->plugin, LOG_DBG, "coin_move 2 (%s) %s -%s %s %"PRIu64,
1338+
e->tag,
1339+
fmt_amount_msat(tmpctx, e->credit),
1340+
fmt_amount_msat(tmpctx, e->debit),
1341+
CHANNEL_MOVE, e->timestamp);
13321342

13331343
/* Go find the account for this event */
13341344
acct = find_account(bkpr, acct_name);

0 commit comments

Comments
 (0)