mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
autoclean: allow dynamic changes to autoclean-cycle.
Slightly less trivial: reset timer unless it's currently running callback. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
f8f8045a06
commit
263625872e
@ -442,7 +442,7 @@ accepted, and ignored.
|
||||
|
||||
### Cleanup control options:
|
||||
|
||||
* **autoclean-cycle**=*SECONDS* [plugin `autoclean`]
|
||||
* **autoclean-cycle**=*SECONDS* [plugin `autoclean`, *dynamic*]
|
||||
|
||||
Perform search for things to clean every *SECONDS* seconds (default
|
||||
3600, or 1 hour, which is usually sufficient).
|
||||
|
@ -61,6 +61,7 @@ static u64 cycle_seconds = 3600;
|
||||
static struct clean_info timer_cinfo;
|
||||
static u64 total_cleaned[NUM_SUBSYSTEM];
|
||||
static struct plugin *plugin;
|
||||
/* This is NULL if it's running now. */
|
||||
static struct plugin_timer *cleantimer;
|
||||
|
||||
static void do_clean_timer(void *unused);
|
||||
@ -439,6 +440,7 @@ static struct command_result *do_clean(struct clean_info *cinfo)
|
||||
static void do_clean_timer(void *unused)
|
||||
{
|
||||
assert(timer_cinfo.cleanup_reqs_remaining == 0);
|
||||
cleantimer = NULL;
|
||||
do_clean(&timer_cinfo);
|
||||
}
|
||||
|
||||
@ -587,6 +589,22 @@ static const char *init(struct plugin *p,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *cycle_seconds_option(struct plugin *plugin, const char *arg,
|
||||
void *unused)
|
||||
{
|
||||
char *problem = u64_option(plugin, arg, &cycle_seconds);
|
||||
if (problem)
|
||||
return problem;
|
||||
|
||||
/* If timer is not running right now, reset it to new cycle_seconds */
|
||||
if (cleantimer) {
|
||||
tal_free(cleantimer);
|
||||
cleantimer = plugin_timer(plugin, time_from_sec(cycle_seconds),
|
||||
do_clean_timer, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const struct plugin_command commands[] = { {
|
||||
"autocleaninvoice",
|
||||
"payment",
|
||||
@ -626,11 +644,11 @@ int main(int argc, char *argv[])
|
||||
" invoices that have expired for at least"
|
||||
" this given seconds are cleaned",
|
||||
u64_option, &timer_cinfo.subsystem_age[EXPIREDINVOICES]),
|
||||
plugin_option("autoclean-cycle",
|
||||
"int",
|
||||
"Perform cleanup every"
|
||||
" given seconds",
|
||||
u64_option, &cycle_seconds),
|
||||
plugin_option_dynamic("autoclean-cycle",
|
||||
"int",
|
||||
"Perform cleanup every"
|
||||
" given seconds",
|
||||
cycle_seconds_option, NULL),
|
||||
plugin_option_dynamic("autoclean-succeededforwards-age",
|
||||
"int",
|
||||
"How old do successful forwards have to be before deletion (0 = never)",
|
||||
|
@ -3181,8 +3181,7 @@ def test_commando_badrune(node_factory):
|
||||
|
||||
|
||||
def test_autoclean(node_factory):
|
||||
l1, l2, l3 = node_factory.line_graph(3, opts={'autoclean-cycle': 10,
|
||||
'may_reconnect': True},
|
||||
l1, l2, l3 = node_factory.line_graph(3, opts={'may_reconnect': True},
|
||||
wait_for_announce=True)
|
||||
|
||||
# Under valgrind in CI, it can 50 seconds between creating invoice
|
||||
@ -3215,6 +3214,8 @@ def test_autoclean(node_factory):
|
||||
assert len(l3.rpc.listinvoices('inv2')['invoices']) == 1
|
||||
assert l3.rpc.listinvoices('inv1')['invoices'][0]['description'] == 'description1'
|
||||
|
||||
l3.rpc.setconfig('autoclean-cycle', 10)
|
||||
|
||||
# First it expires.
|
||||
wait_for(lambda: only_one(l3.rpc.listinvoices('inv1')['invoices'])['status'] == 'expired')
|
||||
# Now will get autocleaned
|
||||
@ -3275,6 +3276,7 @@ def test_autoclean(node_factory):
|
||||
assert only_one(l1.rpc.listpays(inv5['bolt11'])['pays'])['status'] == 'failed'
|
||||
assert only_one(l1.rpc.listpays(inv4['bolt11'])['pays'])['status'] == 'complete'
|
||||
l1.rpc.setconfig('autoclean-failedpays-age', 1)
|
||||
l1.rpc.setconfig('autoclean-cycle', 5)
|
||||
|
||||
wait_for(lambda: l1.rpc.listpays(inv5['bolt11'])['pays'] == [])
|
||||
assert l1.rpc.autoclean_status()['autoclean']['failedpays']['cleaned'] == 1
|
||||
@ -3290,6 +3292,7 @@ def test_autoclean(node_factory):
|
||||
assert len(l2.rpc.listforwards()['forwards']) == 2
|
||||
|
||||
# Clean failed ones.
|
||||
l2.rpc.setconfig('autoclean-cycle', 5)
|
||||
l2.rpc.setconfig('autoclean-failedforwards-age', 2)
|
||||
wait_for(lambda: l2.rpc.listforwards(status='failed')['forwards'] == [])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user