pytest: add test that we fixup "pending" payments which don't actually have HTLCs.
What changed, and why it matters
This commit only adds a new test case (and a small SQLite database snapshot used by the test). It does not change any production code. The test is currently marked as expected to fail (xfail), meaning it documents a known bug where Core Lightning may incorrectly report some payments as 'pending' when they actually have no active HTLCs. Because no fix is included, this commit by itself does not improve or worsen security.
No immediate action is required for this commit. Treat it as test-suite maintenance that flags a possible state-cleanup bug. If the underlying issue is confirmed, a follow-up fix should ensure payments without active HTLCs are correctly marked failed rather than pending.
Security signals we found
No production code changes
Test-only commit
xfail marker indicates known unfixed behavior
Potential data-integrity issue: payments may be stuck in pending state without underlying HTLCs
Evidence from the diff
The diff adds a binary SQLite3 snapshot (tests/data/l1-pending-sendpays-with-no-htlc.sqlite3.xz) and a new pytest in tests/test_wallet.py named test_pending_payments_cleanup. The test restores a node from the snapshot with database-upgrade enabled and asserts that listsendpays returns statuses [‘failed’, ‘pending’] and listpays returns [‘pending’]. It is decorated with @pytest.mark.xfail(strict=True), so it documents expected but currently failing behavior. No wallet, database, or payment logic is modified.
Changed components
tests/test_wallet.pytests/data/l1-pending-sendpays-with-no-htlc.sqlite3.xzInspect captured patch +10 / −0
diff --git a/tests/data/l1-pending-sendpays-with-no-htlc.sqlite3.xz b/tests/data/l1-pending-sendpays-with-no-htlc.sqlite3.xz
new file mode 100644
index 00000000..4a32fba4
Binary files /dev/null and b/tests/data/l1-pending-sendpays-with-no-htlc.sqlite3.xz differ
diff --git a/tests/test_wallet.py b/tests/test_wallet.py
index eec64d68..f3da6eb4 100644
--- a/tests/test_wallet.py
+++ b/tests/test_wallet.py
@@ -2467,3 +2467,13 @@ def test_old_htlcs_cleanup(node_factory, bitcoind):
# Now they're not
assert l1.db_query('SELECT COUNT(*) as c FROM channel_htlcs')[0]['c'] == 0
assert l1.rpc.listhtlcs() == {'htlcs': []}
+
+
+@pytest.mark.xfail(strict=True)
+@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Makes use of the sqlite3 db")
+@unittest.skipIf(TEST_NETWORK != 'regtest', "sqlite3 snapshot is regtest")
+def test_pending_payments_cleanup(node_factory, bitcoind):
+ bitcoind.generate_block(1)
+ l1 = node_factory.get_node(dbfile='l1-pending-sendpays-with-no-htlc.sqlite3.xz', options={'database-upgrade': True})
+ assert [p['status'] for p in l1.rpc.listsendpays()['payments']] == ['failed', 'pending']
+ assert [p['status'] for p in l1.rpc.listpays()['pays']] == ['pending']
Why this scored 11/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.