pytest: test that we don't delete htlcs as soon as channel closed, wait for restart.
What changed, and why it matters
This commit only adds a new test to the test suite. It checks that old payment records (HTLCs) are not deleted from the database immediately when a channel closes, but are instead cleaned up later when the node restarts. There is no code change that fixes or changes any behavior.
No action needed. This is a test-only commit. If investigating a related issue, review the production code that performs the lazy HTLC cleanup on restart.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single pytest function, test_old_htlcs_cleanup, in tests/test_wallet.py. The test verifies lazy cleanup behavior: after a channel is closed and settled on-chain, the channel_htlcs table still contains 10 rows until the node restarts, at which point they are removed. No production code is modified.
Changed components
tests/test_wallet.pyInspect captured patch +23 / −0
diff --git a/tests/test_wallet.py b/tests/test_wallet.py
index b0a77471..b26679b1 100644
--- a/tests/test_wallet.py
+++ b/tests/test_wallet.py
@@ -1885,3 +1885,26 @@ def test_onchain_missing_no_p2tr_migrate(node_factory, bitcoind):
# This can actually take a while for 100 blocks!
l2.daemon.wait_for_log('Rescan finished! 1 outputs recovered')
+
+
+def test_old_htlcs_cleanup(node_factory, bitcoind):
+ """We lazily delete htlcs from channel_htlcs table"""
+ l1, l2 = node_factory.line_graph(2)
+
+ for _ in range(10):
+ l1.pay(l2, 1000)
+
+ l1.rpc.close(l2.info['id'])
+ bitcoind.generate_block(100, wait_for_mempool=1)
+ wait_for(lambda: l1.rpc.listpeerchannels() == {'channels': []})
+ # We don't see them!
+ assert l1.rpc.listhtlcs() == {'htlcs': []}
+
+ l1.stop()
+ # They're still there.
+ assert l1.db_query('SELECT COUNT(*) as c FROM channel_htlcs')[0]['c'] == 10
+
+ l1.start()
+ # Now they're not
+ assert l1.db_query('SELECT COUNT(*) as c FROM channel_htlcs')[0]['c'] == 0
+ assert l1.rpc.listhtlcs() == {'htlcs': []}
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.