Skip to content

Only log if we actually persisted LiquidityManager data (0.2 backport)#4662

Open
tnull wants to merge 1 commit into
lightningdevkit:0.2from
tnull:2025-11-less-spammy-liqman-persistence-backport
Open

Only log if we actually persisted LiquidityManager data (0.2 backport)#4662
tnull wants to merge 1 commit into
lightningdevkit:0.2from
tnull:2025-11-less-spammy-liqman-persistence-backport

Conversation

@tnull
Copy link
Copy Markdown
Contributor

@tnull tnull commented Jun 5, 2026

Backport of #4246.

Previously, we logged "Persisting LiquidityManager..." on each background processor wakeup, which can be very spammy, even on TRACE level.

Here, we opt to only log if something actually needed to be repersisted and we did so (in case of failure we're logging that anyways, too).

Previously, we logged "Persisting LiquidityManager..." on each
background processor wakeup, which can be very spammy, even on TRACE
level.

Here, we opt to only log if something actually needed to be repersisted
and we did so (in case of failure we're logging that anyways, too).
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Jun 5, 2026

I've assigned @valentinewallace as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull changed the title Only log if we actually persisted LiquidityManager data Only log if we actually persisted LiquidityManager data (0.2 backport) Jun 5, 2026
/// Persists the state of the service handlers towards the given [`KVStore`] implementation if
/// needed.
///
/// Returns `true` if it persisted sevice handler data.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "sevice" → "service"

@@ -1285,8 +1289,10 @@ where

/// Persists the state of the service handlers towards the given [`KVStoreSync`] implementation.
///
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same typo: "sevice" → "service"

future.await?;
did_persist = true;
} else {
self.persist_peer_state(counterparty_node_id).await?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: did_persist is not set to true here. When a peer was initially flagged for removal but is no longer prunable (it got new state while we were persisting), needs_persist is forced to true on line 1845, and persist_peer_state here will actually write to the KV store (it checks needs_persist, finds it true, clears it, and persists). So real persistence happens, but the return value won't reflect it.

Low severity since it only affects logging, but the return value is inaccurate.

Suggested change
self.persist_peer_state(counterparty_node_id).await?;
self.persist_peer_state(counterparty_node_id).await?;
did_persist = true;

future.await?;
did_persist = true;
} else {
self.persist_peer_state(client_id).await?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same bug as in lsps2: did_persist is not set to true when persist_peer_state actually writes data in the need_remove fallback path. When a peer was initially flagged for removal but is no longer prunable, needs_persist is forced to true on line 307, and persist_peer_state here will actually persist. The return value will be inaccurate.

Suggested change
self.persist_peer_state(client_id).await?;
self.persist_peer_state(client_id).await?;
did_persist = true;

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

Review Summary

Issues found:

  1. lightning-liquidity/src/lsps2/service.rs:1857 — Missing did_persist = true in the need_remove fallback path where persist_peer_state actually writes data (peer was no longer prunable after re-acquiring the write lock).

  2. lightning-liquidity/src/lsps5/service.rs:319 — Same missing did_persist = true in the equivalent need_remove fallback path.

  3. lightning-liquidity/src/manager.rs:676 — Typo "sevice" → "service" in doc comment.

  4. lightning-liquidity/src/manager.rs:1291 — Same typo "sevice" → "service" in doc comment.

Issues 1 and 2 are low severity since they only affect logging accuracy, but they make the did_persist return value incorrect in an edge case: when a peer was initially flagged for removal, but by the time the write lock is acquired it has new state, the code calls persist_peer_state (which does write to the KV store) without setting did_persist = true.

Copy link
Copy Markdown
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from Claude's feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants