Skip to content

Conversation

distractedm1nd
Copy link
Contributor

@distractedm1nd distractedm1nd commented Jun 17, 2025

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a method to retrieve the current synchronization state from the light client.
    • Made synchronization state publicly accessible and included it as part of the light client’s structure.
    • Introduced a new event indicating the light client is ready to start syncing.
  • Refactor

    • Centralized management of synchronization state within the light client, simplifying method signatures and internal state handling.
    • Enhanced backward synchronization logic to iteratively search and process multiple epochs for improved sync completeness.
    • Removed redundant verification and processing methods to streamline code.
  • Tests

    • Added extensive asynchronous integration tests for the light client, covering real-time sync, backward sync, error handling, and sync behavior under various scenarios.
  • Chores

    • Minor formatting cleanup in configuration files.
    • Updated event enums and mappings to reflect new sync lifecycle events.

Copy link

vercel bot commented Jun 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prism ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 1:17pm

Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Walkthrough

This update refactors the LightClient to embed its synchronization state internally, removing the need to pass sync state as a parameter. It makes SyncState public, adds a method to retrieve it, and introduces comprehensive async integration tests for synchronization logic. Minor formatting and test scaffolding changes are also included. Additionally, a new Ready event variant was added to signal readiness for syncing.

Changes

File(s) Change Summary
Cargo.toml Removed extra spaces around the git attribute in the [patch.crates-io] section.
crates/da/src/lib.rs Added #[automock] attribute to the VerifiableStateTransition trait for mocking in tests.
crates/da/src/events.rs Added Ready, BackwardsSyncStarted, and BackwardsSyncCompleted variants to PrismEvent enum; removed SyncStarted; updated display strings; reordered imports.
crates/da/src/celestia/light_client.rs Consolidated imports under #[cfg(not(target_arch = "wasm32"))]; added TODO comment for retry/timeout logic.
crates/node_types/lightclient/src/lib.rs Added a conditional tests module with #[cfg(test)].
crates/node_types/lightclient/src/lightclient.rs Refactored LightClient to embed sync_state, made SyncState public, updated method signatures, added get_sync_state, enhanced backward sync logic, improved error handling, removed redundant methods.
crates/node_types/lightclient/src/tests/mod.rs Added new async integration tests for LightClient sync scenarios, including macros for mocking and assertions.
crates/node_types/uniffi-lightclient/src/types.rs Added Ready and SyncCompleted variants to UniffiLightClientEvent enum; updated From<PrismEvent> mapping accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Case
    participant MockDA as Mock DAL
    participant LightClient as LightClient
    participant EventChannel as Event Channel

    Test->>MockDA: Setup finalized epochs and responses
    Test->>LightClient: Spawn run loop
    LightClient->>EventChannel: Publish PrismEvent::Ready
    Test->>EventChannel: Await Ready event
    Test->>EventChannel: Send UpdateDAHeight event(s)
    LightClient->>MockDA: Request finalized epoch data
    MockDA-->>LightClient: Return verifiable state transition(s)
    LightClient->>EventChannel: Publish Verification events
    Test->>EventChannel: Await verification events
    Test->>LightClient: Query get_sync_state / assert commitment
Loading

Possibly related PRs

Suggested reviewers

  • sebasti810

Poem

A bunny hopped through code so bright,
Refactored sync state—oh, what a delight!
Now LightClient keeps its state inside,
With tests that run both far and wide.
Commitments checked, events in queue,
This code hops forward, strong and true!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch mock-da

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 auto-generate unit tests to generate unit tests for 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.

@distractedm1nd distractedm1nd changed the base branch from verifiable-epochs to main June 24, 2025 10:14
@distractedm1nd distractedm1nd marked this pull request as ready for review June 25, 2025 10:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
crates/node_types/lightclient/src/lightclient.rs (1)

49-55: Consider documenting the public fields.

Since SyncState is now public with public fields, consider adding documentation comments to explain the purpose of each field, especially the distinction between initial_sync_completed and initial_sync_in_progress.

crates/node_types/lightclient/src/tests/mod.rs (1)

110-112: Consider cleanup of spawned tasks.

The spawned tasks running lc.run() will continue running after the test completes. Consider using tokio::task::JoinHandle and cancelling the task at the end of the test.

-    spawn(async move {
+    let handle = spawn(async move {
         runner.run().await.unwrap();
     });
+    // At the end of the test:
+    handle.abort();

Also applies to: 154-156, 184-186

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 85d067f and d834c24.

📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • crates/da/src/lib.rs (1 hunks)
  • crates/node_types/lightclient/src/lib.rs (1 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (6 hunks)
  • crates/node_types/lightclient/src/tests/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: coverage
  • GitHub Check: unit-test
  • GitHub Check: integration-test
  • GitHub Check: build-and-push-image
🔇 Additional comments (7)
crates/node_types/lightclient/src/lib.rs (1)

4-5: LGTM!

Standard pattern for organizing test modules with conditional compilation.

crates/da/src/lib.rs (1)

69-69: Good addition for testing infrastructure.

Adding #[automock] enables automatic mock generation for the VerifiableStateTransition trait, which is essential for the comprehensive tests being added in this PR.

Cargo.toml (1)

187-187: Minor formatting improvement.

Removing spaces for consistency with other patch entries.

crates/node_types/lightclient/src/lightclient.rs (3)

43-43: Good refactoring for centralized state management.

Embedding the sync_state within the LightClient struct simplifies the API and provides better encapsulation of synchronization state.

Also applies to: 69-70, 78-79


82-84: Good addition for external state access.

The get_sync_state() method provides safe read-only access to the current sync state, which is useful for monitoring and testing.


102-102: Simplified method signatures improve maintainability.

Removing the need to pass sync state as parameters makes the API cleaner and reduces the chance of state management errors.

Also applies to: 109-109, 116-116, 155-155, 168-168

crates/node_types/lightclient/src/tests/mod.rs (1)

13-60: Well-designed macro for mocking DA layer behavior.

The mock_da! macro provides a clean DSL for setting up mock DA layer responses with support for success cases, error cases, and multiple epochs at the same height.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
crates/node_types/lightclient/src/tests/mod.rs (1)

164-173: Unreachable code detected.

Lines 171-173 are unreachable because the function returns on line 167 when RecursiveVerificationCompleted is received.

Move the sync state assertions before the return statement:

     while let Ok(event_info) = sub.recv().await {
         if let PrismEvent::RecursiveVerificationCompleted { height: _ } = event_info.event {
             assert_current_commitment!(lc, "d");
+            let sync_state = lc.get_sync_state().await;
+            assert!(sync_state.initial_sync_completed);
+            assert!(!sync_state.initial_sync_in_progress);
             return;
         }
     }
-
-    let sync_state = lc.get_sync_state().await;
-    assert!(sync_state.initial_sync_completed);
-    assert!(!sync_state.initial_sync_in_progress);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a896e47 and f727dd0.

📒 Files selected for processing (4)
  • crates/da/src/events.rs (3 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (5 hunks)
  • crates/node_types/lightclient/src/tests/mod.rs (1 hunks)
  • crates/node_types/uniffi-lightclient/src/types.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/da/src/events.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/node_types/lightclient/src/lightclient.rs
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: clippy
  • GitHub Check: integration-test
  • GitHub Check: coverage
  • GitHub Check: unit-test
  • GitHub Check: unused dependencies
  • GitHub Check: build-and-push-image
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
crates/node_types/uniffi-lightclient/src/types.rs (1)

6-7: Clean implementation of the Ready event variant.

The addition of the Ready event variant is well-implemented and consistent with the existing event structure. The documentation clearly indicates its purpose for signaling when the LightClient is ready to start syncing.

Also applies to: 67-67

crates/node_types/lightclient/src/tests/mod.rs (2)

89-109: Well-structured test setup with proper initialization.

The setup function properly initializes all components and waits for the Ready event before proceeding, ensuring deterministic test behavior. Good use of Arc for shared ownership and proper event channel setup.


111-156: Comprehensive test coverage for sync scenarios.

The tests effectively cover real-time sync, backwards sync, and concurrent sync scenarios. Good use of the mock_da! macro to create flexible test fixtures and proper assertion of commitments at each stage.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds event handling for light client readiness and sync completion, centralizes sync state management under a new SyncState, and introduces extensive asynchronous integration tests using a mocked DA layer.

  • Added new Uniffi events (Ready, SyncCompleted) and updated event-to-enum mappings
  • Introduced SyncState with concurrency-safe getters and updated run/backwards sync logic
  • Added comprehensive async tests in lightclient/src/tests with a mock_da! macro

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/node_types/uniffi-lightclient/src/types.rs Added Ready & SyncCompleted events and mappings
crates/node_types/lightclient/src/lightclient.rs Introduced SyncState, updated imports and sync logic
crates/node_types/lightclient/src/tests/mod.rs New async integration tests with mock_da! macro
crates/node_types/lightclient/src/lib.rs Exposed test module
crates/da/src/lib.rs Added #[automock] to VerifiableStateTransition
crates/da/src/events.rs Expanded PrismEvent variants and formatting
crates/da/src/celestia/light_client.rs Unified imports and added a TODO for retries
Comments suppressed due to low confidence (4)

crates/node_types/uniffi-lightclient/src/types.rs:73

  • [nitpick] Mapping BackwardsSyncStarted to SyncStarted may be misleading. Consider renaming UniffiLightClientEvent::SyncStarted to something like BackwardsSyncStarted for clarity.
                UniffiLightClientEvent::SyncStarted { height }

crates/node_types/lightclient/src/lightclient.rs:5

  • The code references PrismEvent and EventPublisher but neither is imported. Consider importing prism_da::events::{PrismEvent, EventPublisher} to avoid unresolved name errors.
};

crates/node_types/lightclient/src/lightclient.rs:236

  • In the backward sync loop, if no epochs are found, current_height is never updated and the loop never breaks, leading to an infinite loop. You should either break or decrement current_height before looping.
            light_client.event_pub.send(PrismEvent::BackwardsSyncCompleted { height: None });

crates/node_types/lightclient/src/tests/mod.rs:253

  • [nitpick] Relying on sleep for test synchronization is fragile. Consider waiting on a specific event or using a notification mechanism instead of a fixed delay.
    tokio::time::sleep(Duration::from_secs(1)).await;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
crates/node_types/lightclient/src/tests/mod.rs (2)

252-255: Replace sleep with deterministic event waiting.

The TODO comment indicates this is a known issue. Using tokio::time::sleep makes tests non-deterministic and slower.

Consider implementing an event-based approach:

-    // TODO: Find better way
-    tokio::time::sleep(Duration::from_secs(1)).await;
+    // Wait for potential backward sync events and ensure none occur
+    let timeout = tokio::time::timeout(Duration::from_millis(100), async {
+        wait_for_event(&mut sub, |event| {
+            matches!(event, PrismEvent::BackwardsSyncStarted { .. })
+        }).await;
+    });
+    assert!(timeout.await.is_err(), "No backward sync should start");

265-271: Replace sleep with deterministic event waiting.

Similar to the previous case, this sleep should be replaced with proper event synchronization:

-    // TODO: replace with event listener
-    tokio::time::sleep(Duration::from_secs(1)).await;
+    // Verify no processing occurs by checking that sync state remains unchanged
+    let initial_state = lc.get_sync_state().await;
+    tokio::time::timeout(Duration::from_millis(100), async {
+        wait_for_sync(&mut sub, 8).await;
+    }).await.unwrap_err(); // Should timeout
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed04f38 and de6e031.

📒 Files selected for processing (5)
  • crates/da/src/celestia/light_client.rs (2 hunks)
  • crates/da/src/events.rs (3 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (8 hunks)
  • crates/node_types/lightclient/src/tests/mod.rs (1 hunks)
  • crates/node_types/uniffi-lightclient/src/types.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/da/src/celestia/light_client.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/da/src/events.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/node_types/lightclient/src/tests/mod.rs (4)
crates/da/src/events.rs (2)
  • new (110-113)
  • publisher (115-119)
crates/node_types/lightclient/src/lightclient.rs (3)
  • new (58-79)
  • get_latest_commitment (303-305)
  • get_sync_state (81-83)
crates/da/src/lib.rs (3)
  • new (50-52)
  • height (76-76)
  • height (118-120)
crates/keys/src/signing_keys.rs (1)
  • new_ed25519 (49-51)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: coverage
  • GitHub Check: integration-test
  • GitHub Check: build-and-push-image
  • GitHub Check: clippy
  • GitHub Check: unit-test
  • GitHub Check: unused dependencies
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (20)
crates/node_types/uniffi-lightclient/src/types.rs (3)

6-7: LGTM! New Ready event variant is well-documented.

The addition of the Ready variant with clear documentation aligns with the enhanced synchronization lifecycle.


13-16: LGTM! Optional height in SyncCompleted provides flexibility.

Making the height optional in SyncCompleted is a good design choice that allows signaling completion even when no specific height was reached (e.g., when backward sync finds no epochs).


71-77: LGTM! Event mapping correctly handles new synchronization events.

The From implementation properly maps the new PrismEvent variants:

  • ReadyReady
  • BackwardsSyncStartedSyncStarted
  • BackwardsSyncCompletedSyncCompleted

This maintains the external API while supporting the enhanced internal event model.

crates/node_types/lightclient/src/lightclient.rs (8)

42-42: LGTM! Embedding sync state improves encapsulation.

Moving the sync state inside the LightClient struct eliminates the need to pass it as a parameter and provides better encapsulation.


48-54: LGTM! Public SyncState provides necessary access.

Making SyncState and its fields public allows external access to sync information while maintaining the internal state management.


81-83: LGTM! Async getter provides safe state access.

The get_sync_state method provides a safe way to access the sync state by returning a clone, avoiding potential lock contention issues.


89-89: LGTM! Ready event signals proper initialization.

Emitting the PrismEvent::Ready event at startup provides a clear signal that the light client is ready to begin processing sync events.


120-131: LGTM! Height validation prevents processing stale updates.

The check to skip processing when the new height is lower than the current synced height is a good optimization that prevents unnecessary work on stale data.


243-244: LGTM! Method signature improvement adds boundary checking.

Adding the min_height parameter allows the method to respect the backward search depth limit, improving the search efficiency.


279-301: LGTM! Enhanced error handling in epoch processing.

The updated process_epoch method now properly emits EpochVerificationFailed events on verification errors, providing better observability of sync issues.


91-111: To determine whether start_backward_sync truly awaits the full sync or merely spawns background tasks (which could re-enter the loop), let’s inspect its implementation and any spawn calls:

#!/bin/bash
# 1. Locate and display the async fn start_backward_sync implementation
rg -n "async fn start_backward_sync" -A15 -B5 crates/node_types/lightclient/src/lightclient.rs

# 2. Check for tokio::spawn or other spawn calls in the same file
rg -n "spawn" -C3 crates/node_types/lightclient/src/lightclient.rs
crates/node_types/lightclient/src/tests/mod.rs (9)

14-61: LGTM! Comprehensive mocking macro with good error handling support.

The mock_da! macro provides excellent flexibility for creating test scenarios:

  • Supports success cases with tuple syntax ($h1, $h2)
  • Handles error cases with Err(...) and string literal shortcuts
  • Uses proper trait expectations with MockVerifiableStateTransition

The macro design makes tests readable and maintainable.


63-70: LGTM! Helper function provides clean event waiting.

The wait_for_sync function abstracts the common pattern of waiting for epoch verification events, making tests more readable.


72-77: LGTM! Commitment assertion macro provides clear test validation.

The macro simplifies commitment verification by handling the hash computation and assertion, making test intentions clear.


90-110: LGTM! Test setup function provides proper initialization.

The setup function correctly:

  1. Configures the mock DA layer with event channels
  2. Creates a light client with proper key generation
  3. Spawns the run loop asynchronously
  4. Waits for the Ready event before returning

This ensures tests start with a properly initialized light client.


112-142: LGTM! Comprehensive real-time sync test.

The test covers multiple scenarios:

  • No epochs at height 3
  • Single epoch at heights 4, 5, 8
  • Multiple epochs at height 7
  • Proper commitment progression

The test validates the forward sync behavior thoroughly.


144-156: LGTM! Backward sync test validates historical epoch discovery.

The test confirms that the light client can find and process historical epochs when starting from a height with no data.


158-170: LGTM! Error resilience test validates robust sync behavior.

The test confirms that backward sync continues searching when encountering verification errors, finding the first valid epoch.


274-297: LGTM! Complex concurrent sync test validates state coordination.

This test covers a sophisticated scenario where incoming epoch processing occurs during backward sync, validating that both operations can complete correctly and the final state is consistent.


299-318: LGTM! Sequential sync test validates proper ordering.

The test ensures that backward sync completes before processing new incoming epochs, validating the correct sequencing of sync operations.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
crates/node_types/lightclient/src/tests/mod.rs (2)

252-254: Address remaining TODO: Replace sleep with event-based synchronization.

This sleep statement still uses the non-deterministic approach that was flagged in previous reviews. Consider waiting for a specific event or state change instead.

-    // TODO: Find better way
-    tokio::time::sleep(Duration::from_secs(1)).await;
+    // Wait for any potential events to be processed
+    wait_for_event(&mut sub, |_| false).timeout(Duration::from_millis(100)).await.ok();

266-268: Address remaining TODO: Replace sleep with event-based synchronization.

Another instance of the non-deterministic sleep pattern that should be replaced with proper event handling.

Consider adding a mechanism to verify that no events are emitted within a reasonable timeframe, or check the sync state directly after a short deterministic wait.

🧹 Nitpick comments (1)
crates/node_types/lightclient/src/tests/mod.rs (1)

72-77: Consider handling the case where no commitment exists.

The macro uses unwrap() which will panic if get_latest_commitment() returns None. While this is acceptable in test context to indicate test failure, consider making the expectation explicit.

 macro_rules! assert_current_commitment {
     ($lc:expr, $expected:expr) => {
-        let actual = $lc.get_latest_commitment().await.unwrap();
+        let actual = $lc.get_latest_commitment().await
+            .expect("Expected a commitment to be present");
         assert_eq!(Digest::hash($expected), actual);
     };
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between de6e031 and edf73f3.

📒 Files selected for processing (2)
  • crates/node_types/lightclient/src/lightclient.rs (8 hunks)
  • crates/node_types/lightclient/src/tests/mod.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/node_types/lightclient/src/lightclient.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/node_types/lightclient/src/tests/mod.rs (4)
crates/da/src/events.rs (2)
  • new (110-113)
  • publisher (115-119)
crates/da/src/lib.rs (3)
  • new (50-52)
  • height (76-76)
  • height (118-120)
crates/node_types/lightclient/src/lightclient.rs (3)
  • new (58-79)
  • get_latest_commitment (307-309)
  • get_sync_state (81-83)
crates/keys/src/signing_keys.rs (1)
  • new_ed25519 (49-51)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: coverage
  • GitHub Check: unit-test
  • GitHub Check: build-and-push-image
  • GitHub Check: integration-test
  • GitHub Check: unused dependencies
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
crates/node_types/lightclient/src/tests/mod.rs (5)

1-12: LGTM! Imports are well-organized and complete.

The import statements are properly structured and include all necessary dependencies. The EpochVerificationError import at line 8 correctly addresses the previous review feedback.


14-61: Well-designed macro for flexible test setup.

The mock_da! macro provides a clean DSL for setting up mock data availability layer scenarios. The macro supports both success cases with tuple syntax and error cases with string or explicit error types. The internal pattern matching logic is sound and the move closures properly capture the necessary data.


90-110: Excellent improvement with deterministic synchronization.

The setup function now properly waits for the Ready event instead of using arbitrary sleep durations. This addresses the previous review feedback and makes tests more reliable and faster.


273-327: Complex test structure handles concurrent scenarios well.

This test properly handles the challenging scenario of concurrent backward sync and incoming epoch processing. The use of tokio::time::timeout prevents hanging, and the event tracking logic correctly validates both expected events occur.

The small delay at lines 303-304 is justified here for ensuring the receiver is ready before sending events.


112-362: Comprehensive test coverage with good scenario diversity.

The test suite covers essential synchronization scenarios including:

  • Real-time sync progression
  • Backward sync with and without errors
  • Error handling and recovery
  • Concurrent sync prevention
  • Edge cases like underflow and older epoch handling

The tests effectively validate the light client's event-driven architecture and state management.

@distractedm1nd distractedm1nd merged commit 57a3960 into main Jun 26, 2025
7 of 10 checks passed
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.

2 participants