Skip to content

fix: light-client error StateLookuptableNotFound - #1872

Merged
ananas-block merged 3 commits into
mainfrom
jorrit/fix-light-client-statelookuptablenotfound
Jul 20, 2025
Merged

fix: light-client error StateLookuptableNotFound#1872
ananas-block merged 3 commits into
mainfrom
jorrit/fix-light-client-statelookuptablenotfound

Conversation

@ananas-block

@ananas-block ananas-block commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages for indexer-related API errors, providing more detailed guidance and clearer reporting of unknown errors.
    • Updated behavior for displaying unknown API error messages, which may now appear as empty instead of a fixed message in certain cases.
  • New Features

    • Enhanced network detection for RPC calls, enabling more accurate selection of network-specific data and default values based on the detected environment (e.g., localnet, devnet, testnet).

@coderabbitai

coderabbitai Bot commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update error handling and messaging in the indexer and photon indexer modules, providing more informative error messages. Additionally, the LightClient now includes network detection logic, enabling it to return appropriate state tree information based on the detected network environment, including special handling for localnet and differentiating between mainnet and devnet lookup tables.

Changes

File(s) Change Summary
sdk-libs/client/src/indexer/error.rs Expanded error message for NotInitialized and improved unknown API error reporting to include debug info.
sdk-libs/client/src/indexer/photon_indexer.rs Changed error message fallback from "Unknown API error" to an empty string when the error message is missing.
sdk-libs/client/src/rpc/client.rs Added network detection logic and updated get_latest_active_state_trees to use network-aware state tree tables.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LightClient
    participant RPC
    participant StateTreeTables

    User->>LightClient: get_latest_active_state_trees()
    LightClient->>LightClient: detect_network()
    alt Localnet
        LightClient-->>User: Return hardcoded state trees
    else Other networks
        LightClient->>StateTreeTables: Select mainnet or devnet tables
        LightClient->>RPC: get_light_state_tree_infos(lookup_tables)
        RPC-->>LightClient: Return state tree infos
        LightClient-->>User: Return state tree infos
    end
Loading

Suggested reviewers

  • SwenSchaeferjohann

Poem

A bunny hops through code and net,
Detecting networks—no need to fret!
Errors now speak with wisdom clear,
And localnet trees are always near.
With lookup tables chosen right,
This patch brings clarity and delight!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
sdk-libs/client/src/indexer/photon_indexer.rs (1)

135-135: Consider the impact of empty error messages on debuggability.

While this change aligns with the broader error handling improvements mentioned in the AI summary, replacing "Unknown API error" with an empty string via unwrap_or_default() could potentially make debugging more difficult when the API doesn't provide an error message.

Ensure that the coordinated changes in error.rs (specifically the enhanced debug representation in unknown API error handling) compensate for this potential loss of context.

sdk-libs/client/src/rpc/client.rs (1)

132-148: Good network detection implementation with minor robustness considerations.

The network detection logic is clean and covers the main network types. The string-based URL matching approach is pragmatic and should work for most standard configurations.

Consider making the detection more robust by potentially using URL parsing to extract hostnames, which would be less sensitive to URL variations (e.g., different ports, protocols, or subdomains).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57cfd4f and f327271.

📒 Files selected for processing (3)
  • sdk-libs/client/src/indexer/error.rs (2 hunks)
  • sdk-libs/client/src/indexer/photon_indexer.rs (1 hunks)
  • sdk-libs/client/src/rpc/client.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: cli-v1
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test program-libs-fast
  • GitHub Check: stateless-js-v1
  • GitHub Check: cli-v2
  • GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
  • GitHub Check: system-programs (token-escrow-test, [ "cargo test-sbf -p token-escrow" ])
  • GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-test"])
  • GitHub Check: system-programs (counter-test, ["cargo test-sbf -p counter"])
  • GitHub Check: stateless-js-v2
  • GitHub Check: lint
🔇 Additional comments (4)
sdk-libs/client/src/indexer/error.rs (2)

49-51: Excellent improvement to error message specificity.

The expanded error message now provides clear, actionable guidance by specifying exactly what needs to be configured (photon_url in LightClientConfig) to resolve the initialization issue. This significantly improves the developer experience.


96-96: Good enhancement of unknown API error reporting.

This change replaces the generic "Unknown API error" message with the actual debug representation of the error, providing much more useful diagnostic information. This improvement works well with the coordinated change in photon_indexer.rs where empty error messages are now used as fallbacks.

sdk-libs/client/src/rpc/client.rs (2)

685-712: Excellent localnet handling with appropriate feature flag differentiation.

The localnet-specific logic provides sensible default test values and properly handles the difference between v2 and v1 configurations using feature flags. This eliminates unnecessary network calls during local development and testing.

The hardcoded pubkeys are appropriately differentiated by feature flags, ensuring the correct tree types are used.


714-729: Well-implemented network-aware lookup table selection.

The logic correctly maps network types to appropriate lookup tables:

  • Development networks (Devnet, Testnet, ZKTestnet) use devnet tables
  • Production and custom URLs default to mainnet tables

This provides a sensible fallback strategy and maintains backward compatibility while adding network awareness.

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@ananas-block ananas-block changed the title fix: unknown api error, and StateLookuptable not found fix: light-client error StateLookuptableNotFound Jul 20, 2025
@ananas-block
ananas-block merged commit 30759b1 into main Jul 20, 2025
24 of 25 checks passed
@ananas-block
ananas-block deleted the jorrit/fix-light-client-statelookuptablenotfound branch July 20, 2025 21:30
ananas-block added a commit that referenced this pull request Jul 20, 2025
* fix: unknown api error, and StateLookuptable not found

* fix: get_latest_active_state_trees for localnet with hardcoded values

* fix: lint
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.

2 participants