From 9def124380601422902f1d10483eb81271c49e06 Mon Sep 17 00:00:00 2001 From: ziggie Date: Mon, 16 Feb 2026 10:15:25 +0100 Subject: [PATCH] payments/db: fix silent error in duplicate payment lookup When duplicatePaymentSequenceKey is missing from a duplicate payment sub-bucket, the code returned the outer function's err variable which is nil at that point. This caused corrupted duplicate entries to be silently treated as "not found" instead of failing loudly. Return a new dedicated ErrNoDuplicateSequenceNumber error so malformed data is detected immediately. --- payments/db/errors.go | 5 +++++ payments/db/kv_store.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/payments/db/errors.go b/payments/db/errors.go index 0457db600..3b4e25bd9 100644 --- a/payments/db/errors.go +++ b/payments/db/errors.go @@ -136,6 +136,11 @@ var ( ErrNoDuplicateNestedBucket = errors.New("nested duplicate bucket not " + "found") + // ErrNoDuplicateSequenceNumber is returned when a duplicate payment + // sub-bucket does not contain the sequence number key. + ErrNoDuplicateSequenceNumber = errors.New("duplicate payment " + + "sequence number not found") + // ErrNoSequenceNrIndex is returned when an attempt to lookup a payment // index is made for a sequence number that is not indexed. // diff --git a/payments/db/kv_store.go b/payments/db/kv_store.go index 6d21048d7..b3fffe1e1 100644 --- a/payments/db/kv_store.go +++ b/payments/db/kv_store.go @@ -1236,7 +1236,7 @@ func fetchPaymentWithSequenceNumber(tx kvdb.RTx, paymentHash lntypes.Hash, seqBytes := subBucket.Get(duplicatePaymentSequenceKey) if seqBytes == nil { - return err + return ErrNoDuplicateSequenceNumber } // If this duplicate payment is not the sequence number we are