Skip to content

refactor: smartrouter - lava#2097

Closed
avitenzer wants to merge 201 commits intomainfrom
smart-router-lava-refactor
Closed

refactor: smartrouter - lava#2097
avitenzer wants to merge 201 commits intomainfrom
smart-router-lava-refactor

Conversation

@avitenzer
Copy link
Collaborator

@avitenzer avitenzer commented Oct 30, 2025

Description

Major architectural refactoring that splits lavap into two distinct deployment modes and decouples the smart router from blockchain dependencies.

Core Changes

1. Split lavap into two separate commands:

  • lavap rpcconsumer - Decentralized mode with blockchain pairing
  • lavap rpcsmartrouter - Centralized/enterprise mode with static providers

2. Disconnected rpcsmartrouter from blockchain:

  • No blockchain state tracking - Removed dependency on ongoing blockchain queries
  • No epoch management - Uses standalone epoch timer (15-minute default)
  • No on-chain pairing - Static providers configured via YAML instead
  • Optional blockchain connection - Only queries spec once during initialization (can use static spec files)
  • Ephemeral key mode - Can run without keyring/wallet using generated ephemeral keys
  • Approximate block height - Calculated from epoch timer instead of blockchain queries

Additional Improvements

  • Enhanced static provider validation: Added spec path validation and improved configuration handling for standalone mode
  • Improved session/epoch management: Refactored session epoch handling with callbacks for flexible block height sources
  • Better error handling: Streamlined error handling in relay functions, health commands, and E2E test scripts
  • E2E test infrastructure: Added error diagnostics, improved wait logic, and enhanced blockchain query handling
  • Code quality: Fixed linting issues, improved code readability, and reduced conditional nesting

Architecture Impact

Aspect rpcconsumer (Decentralized) rpcsmartrouter (Centralized)
Provider Discovery Blockchain pairing Static YAML configuration
Blockchain Dependency Required (ongoing) Optional (one-time spec query)
Epoch Management On-chain epochs Standalone timer
Trust Model Trustless verification Trust configured providers
Setup Requires wallet/keyring Can use ephemeral keys
Best For Public networks Enterprise/known infrastructure

Note: This PR consolidates 187 commits from the smart-router-lava-refactor branch.

KodamaHQ and others added 30 commits August 25, 2024 18:25
…test_block_metric

feat: FB - Added provider_endpoint to lava_consumer_latest_provider_block
…s_metrics

feat: FB add provider endpoint to qos metrics
…into PRT-fb-branch-with-offline-policy-v-4-2-4
avitenzer and others added 17 commits November 9, 2025 00:16
- Simplified error checking in `sendRelayWithRetries` methods for both `RPCConsumerServer` and `RPCSmartRouterServer` by removing unnecessary conditional nesting.
- Improved readability and maintainability of the code while ensuring consistent error logging for relay failures.
- Updated logic in `SeparateAddonsExtensions` to streamline addon checks in `BaseChainParser`.
- Streamlined error handling in the health command by reducing conditional nesting for posting health results.
- Improved code readability and maintainability while ensuring consistent error logging for health run failures.
…inter

- Added a new setting in the .golangci.yml file to disable the 'elseif' check in the gocritic linter.
- This change aims to improve linting flexibility and accommodate coding style preferences.
…ript

- Add ERR trap to show which command fails with line number
- Add 2 wait_next_block calls before first governance proposal
- Helps diagnose E2E test failures on CI by showing exact failure point

This improves debuggability for timing-sensitive E2E test failures.
- Introduced a new function `getLavaBlockHeight` in `ConsumerSessionManager` to fetch the current Lava blockchain block height.
- Updated `GetSessions` method to use the block height for `RelaySession.Epoch` instead of the pairing epoch.
- Added `SetLavaBlockHeightCallback` method to allow setting the block height retrieval function after the session manager is created.
- Integrated block height callback in both `RPCConsumer` and `RPCSmartRouter` to ensure accurate epoch calculations.
- Implemented the `LatestBlock` method in `mockConsumerStateTracker` to return a fixed block height of 1000.
- Updated the mock interface in `consumer_state_tracker_mock.go` to include the new method.
- Enhanced the test setup in `rpcconsumer_server_test.go` to expect calls to `LatestBlock` and return the specified block height, improving test coverage for block height retrieval.
- Modified the `GetSessions` method in `ConsumerSessionManager` to use the pairing epoch for provider validation instead of the Lava blockchain block height.
- This change ensures accurate epoch calculations for session management and improves the clarity of the code.
…essions method

- Updated comments in `ConsumerSessionManager` to accurately reflect the usage of the `getLavaBlockHeight` function.
- Enhanced the formatting of the `SessionInfo` struct initialization for better readability in the `GetSessions` method.
- These changes improve code clarity and maintainability.
… init_e2e.sh

- Improved the `wait_next_block` function to include error handling for blockchain queries, ensuring it waits until the blockchain is responsive before proceeding.
- Updated `current_block` function to return a default value if the blockchain is unresponsive.
- Enhanced the `init_e2e.sh` script to check if `lavad` is operational before proceeding with block waits, improving robustness and error diagnostics during end-to-end tests.
- Added informative echo statements to provide better feedback during script execution.
- Introduced a custom HTTP client with a 30-second timeout in the `getRequest` function to prevent hanging requests.
- Added progress logging for the REST relay tests to provide better visibility during execution.
- Included a completion message for successful test runs, improving feedback for end-to-end testing.
- Reduced the number of REST relay tests from 70 to 10, optimizing test execution time while maintaining reliability.
- Updated progress logging to reflect the new test count, enhancing visibility during test runs.
- Added a small delay between requests to prevent overwhelming the system, improving overall test stability.
…d init_e2e.sh

- Reduced the maximum attempts for blockchain queries from 60 to 30 seconds, improving response time.
- Simplified the logic in `operator_address` function by removing unnecessary error handling and echo statements.
- Enhanced feedback during the execution of the `init_e2e.sh` script by adding a stabilization wait after transactions.
- Improved overall script clarity and efficiency, ensuring smoother operation during end-to-end tests.
- Updated the `UpdateAllProviders` method in the consumer session manager test to verify that calling it with the same epoch does not result in an error, ensuring idempotent behavior.
- Adjusted test assertions to reflect the expected outcome, improving test reliability and accuracy.
@AnnaR-prog AnnaR-prog force-pushed the smart-router-lava-refactor branch from 8ce459e to 5bd4952 Compare November 10, 2025 11:01
avitenzer and others added 4 commits November 10, 2025 13:39
…test

- Added detailed logging for each virtual epoch signal to help diagnose hanging issues
- Added elapsed time tracking for REST relay tests
- Added 5-minute safety timeout to prevent indefinite hanging in REST relay tests
- Helps identify exactly where test execution stalls in CI environment
- Removed unnecessary blank lines in the `runProtocolE2E` function to improve code readability and maintainability.
@NadavLevi NadavLevi force-pushed the smart-router-lava-refactor branch from 4a642c8 to 7cd3bad Compare November 12, 2025 14:15
@NadavLevi NadavLevi force-pushed the smart-router-lava-refactor branch from 7cd3bad to a1093a2 Compare November 12, 2025 14:25
@NadavLevi NadavLevi force-pushed the smart-router-lava-refactor branch from a1093a2 to 774c766 Compare November 12, 2025 14:37
@avitenzer avitenzer closed this Nov 19, 2025
@NadavLevi NadavLevi deleted the smart-router-lava-refactor branch December 8, 2025 12:19
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.