Skip to content

Commit d996522

Browse files
rustyrussellmadelinevibes
authored andcommitted
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 d67092b commit d996522

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
@@ -86,7 +86,8 @@ static void
8686
parse_and_log_channel_move(struct command *cmd,
8787
const char *buf,
8888
const jsmntok_t *channelmove,
89-
struct refresh_info *rinfo);
89+
struct refresh_info *rinfo,
90+
bool log);
9091

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

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

125133
be_index = cpu_to_be64(bkpr->channelmoves_index);
126134
jsonrpc_set_datastore_binary(cmd, "bookkeeper/channelmoves_index",
@@ -1276,7 +1284,8 @@ static void
12761284
parse_and_log_channel_move(struct command *cmd,
12771285
const char *buf,
12781286
const jsmntok_t *channelmove,
1279-
struct refresh_info *rinfo)
1287+
struct refresh_info *rinfo,
1288+
bool log)
12801289
{
12811290
struct channel_event *e = tal(cmd, struct channel_event);
12821291
struct account *acct;
@@ -1323,11 +1332,12 @@ parse_and_log_channel_move(struct command *cmd,
13231332
err = tal_free(err);
13241333
}
13251334

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

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

0 commit comments

Comments
 (0)