Skip to content

Commit 006de33

Browse files
committed
libplugin: add spamlistcommand
This hammers lightingd with `listinvoices` commands. $ VALGRIND=0 TEST_DB_PROVIDER=postgres eatmydata uv run pytest -v tests/benchmark.py::test_spam_listcommands sqlite3: test_spam_listcommands 2.1193 2.4524 2.2343 0.1341 2.2229 0.1709 1;0 0.4476 5 1 PostgreSQL: test_spam_listcommands 6.5572 6.8440 6.7067 0.1032 6.6967 0.1063 2;0 0.1491 5 1 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 89d5b08 commit 006de33

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/benchmark.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,13 @@ def test_spam_commands(node_factory, bitcoind, benchmark):
218218
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
219219
l1 = get_bench_node(node_factory, extra_options={"plugin": plugin})
220220

221+
# This calls "batch" 1M times (which doesn't need a transaction)
221222
benchmark(l1.rpc.spamcommand, 1_000_000)
223+
224+
225+
def test_spam_listcommands(node_factory, bitcoind, benchmark):
226+
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
227+
l1 = get_bench_node(node_factory, extra_options={"plugin": plugin})
228+
229+
# This calls "listinvoice" 100,000 times (which doesn't need a transaction commit)
230+
benchmark(l1.rpc.spamlistcommand, 100_000)

tests/plugins/test_libplugin.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,26 @@ static struct command_result *json_spamcommand(struct command *cmd,
234234
return batch_done(cmd, batch);
235235
}
236236

237+
static struct command_result *json_spamlistcommand(struct command *cmd,
238+
const char *buf,
239+
const jsmntok_t *params)
240+
{
241+
u64 *iterations;
242+
struct request_batch *batch;
243+
244+
if (!param(cmd, buf, params,
245+
p_req("iterations", param_u64, &iterations),
246+
NULL))
247+
return command_param_failed();
248+
249+
batch = request_batch_new(cmd, NULL, spam_errcb, spam_done, NULL);
250+
for (size_t i = 0; i < *iterations; i++) {
251+
struct out_req *req = add_to_batch(cmd, batch, "listinvoices");
252+
send_outreq(req);
253+
}
254+
return batch_done(cmd, batch);
255+
}
256+
237257

238258
static char *set_dynamic(struct plugin *plugin,
239259
const char *arg,
@@ -312,6 +332,10 @@ static const struct plugin_command commands[] = { {
312332
"spamcommand",
313333
json_spamcommand,
314334
},
335+
{
336+
"spamlistcommand",
337+
json_spamlistcommand,
338+
},
315339
};
316340

317341
static const char *before[] = { "dummy", NULL };

0 commit comments

Comments
 (0)