AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 61 Bitcoin

Fix races when removing per-peer state from KVStore in LSPS2/5

Public commit record

What the developer wrote

Authored by Matt Corallo

73/100 · Adequate
Fix races when removing per-peer state from KVStore in LSPS2/5

If we note that a peer should be removed in LSPS2/5 handling, we
need to make sure that the peer wasn't re-added between dropping
its state in memory and going to remove its state from disk. If it
is, we need to overwrite the current on-disk state instead.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This patch fixes a race condition in the Lightning Dev Kit's liquidity service plugins (LSPS2 and LSPS5). Previously, when the code decided a peer's state should be removed from disk, it could drop the in-memory lock before deleting the stored data. In that gap, another operation could re-add state for the same peer. The removal could then delete the newly-written state, or an outdated write could overwrite newer data, leading to lost or inconsistent peer records. The fix holds the appropriate locks until the storage write or remove operation is started, and re-checks whether the peer is still removable before deleting anything. If the peer was re-added, it now forces a fresh persist instead of removing.

Recommended action

Review and merge the patch. After deployment, monitor for any persisted-state inconsistencies in LSPS2/5 services and consider adding tests that interleave peer disconnect/reconnect with the periodic prune/persist task to prevent regression.

Security signals we found

01

Race condition between in-memory state pruning and on-disk state removal

02

TOCTOU window between dropping peer state and KVStore remove/write

03

Potential loss or inconsistency of persisted peer state

04

Lock scope tightened to cover the start of async storage operations

05

Re-validation of prunability under write lock before deletion

06

Fallback to re-persist when peer state is re-added concurrently

Risk score

Why this scored 61/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 10/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.