Skip to content

multi: let all V1Store ForEach* methods take a reset call-back#10068

Merged
guggero merged 11 commits intolightningnetwork:masterfrom
ellemouton:graphResetForCallbacks
Jul 15, 2025
Merged

multi: let all V1Store ForEach* methods take a reset call-back#10068
guggero merged 11 commits intolightningnetwork:masterfrom
ellemouton:graphResetForCallbacks

Conversation

@ellemouton
Copy link
Collaborator

@ellemouton ellemouton commented Jul 11, 2025

The ForEach* methods should expose the underlying reset param that is passed to the DB call
so that callers can correctly "clean" any state that was collected during the execution of the main
call-back if a DB-retry occurs.

In the longer term, we should aim to replace these ForEach methods with proper/safe iterators that
only apply the call-backs to successful DB fetches. But for now, this is at least an improvement & fixes a few pre-existing bugs.

@ellemouton ellemouton self-assigned this Jul 11, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ellemouton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability of database iteration methods by introducing a reset callback. This callback is invoked upon database retry attempts, allowing for the cleanup of transient state accumulated during the iteration. This is a crucial step towards preventing data inconsistencies and improving the overall robustness of operations that interact with the graph database, particularly in the context of potential database retries.

Highlights

  • API and Interface Changes: Modified numerous ForEach* methods across various packages (e.g., autopilot, graph/db, routing, discovery, rpcserver) to accept an additional reset func() parameter. This change is propagated through several interfaces, including autopilot/interface.go, graph/db/interfaces.go, graph/interfaces.go, and routing/graph.go, ensuring consistency across the codebase.
  • Database Interaction Robustness: The primary intent of this change is to improve the robustness of database interactions. The new reset callback allows callers to clear any accumulated state if a database operation needs to be retried. This prevents bugs that could arise from stale or partially collected data during retries, ensuring data integrity.
  • State Management During Retries: Implemented specific state-clearing logic within the new reset callbacks at various call sites. This includes clearing maps, slices, and other variables that accumulate data during ForEach* iterations, ensuring a clean slate for subsequent retry attempts. Examples include clearing nodes and addresses in autopilot/agent.go, localChans in routing/bandwidth.go, and various RPC response fields in rpcserver.go.
  • Underlying Database Store Updates: The V1Store implementations, both KV-based (graph/db/kv_store.go) and SQL-based (graph/db/sql_store.go), have been updated to support and pass through the reset callback. This ensures that the cleanup mechanism is effective at the lowest layers of database interaction.
  • Test Coverage Updates: Corresponding test files have been updated to accommodate the new function signatures, providing appropriate reset callbacks. This includes adding func(){} for simple cases where no state needs explicit clearing, and specific state resets for more complex scenarios in test setups.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds a reset callback to all V1Store ForEach* methods to handle database retries gracefully. The changes are extensive and have been applied consistently across interfaces, implementations, and call sites. The refactoring in some places to make the callbacks purer is a great improvement for code clarity and robustness.

I've found one minor style issue related to line length that should be addressed. Otherwise, the changes look solid and well-implemented.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very nice way of splitting up this quite large change into multiple commits. LGTM 🎉

Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🌊

@ellemouton ellemouton force-pushed the graphResetForCallbacks branch from d6378e5 to c5031c3 Compare July 15, 2025 04:56
This commit passes no-op reset callbacks to various places where they
are needed in the KVStore. Upcoming commits will replace the no-ops by
adding reset params to the methods that require it.
This commit just surfaces the locations in the SQLStore where we will
later pass reset params through.
Add a `reset` call-back param to the V1Store ForEachChannel method.
@ellemouton ellemouton force-pushed the graphResetForCallbacks branch from c5031c3 to 83f6dc4 Compare July 15, 2025 09:25
@ellemouton
Copy link
Collaborator Author

cc @guggero for le override powers

@guggero guggero merged commit df6c02e into lightningnetwork:master Jul 15, 2025
34 of 39 checks passed
@ellemouton ellemouton deleted the graphResetForCallbacks branch July 15, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants