Skip to content

Conversation

distractedm1nd
Copy link
Contributor

@distractedm1nd distractedm1nd commented Jun 13, 2025

This PR:

  • Makes FinalizedEpoch mockable by wrapping it in a trait
  • Makes LightDataAvailabilityLayer mockable by reworking the event system
    • Means moving events to da crate
    • Implementing it correctly for inmemory and celestia fn da layers
    • Reworking how the subscribers/publishers are instantiated

Summary by CodeRabbit

  • New Features

    • Introduced a unified event channel system for event handling and publishing across components.
    • Added a trait-based abstraction for verifiable epochs, enabling more flexible and mockable verification logic.
    • Integrated detailed signature and commitment verification with custom error handling.
  • Improvements

    • Simplified and unified event types and event publishing, replacing multiple event systems with a single interface.
    • Updated epoch verification to use a trait, encapsulating proof and signature checks for better maintainability.
    • Verification keys are now managed and retrieved through a dedicated interface.
  • Bug Fixes

    • Enhanced error reporting for signature and commitment verification failures.
  • Refactor

    • Replaced optional public key fields with mandatory ones in several components.
    • Updated method signatures and trait interfaces for consistency and clarity.
    • Removed unused or redundant code related to previous event handling and verification approaches.
  • Chores

    • Updated dependencies and verification key files to reflect new key values and added supporting libraries.

Copy link

vercel bot commented Jun 13, 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 24, 2025 9:01am

Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

This update introduces a trait-based abstraction for epoch verification, refactors event handling to use a unified event channel and event type, and removes optionality from verifying key usage. The data availability layer and light client now interact through boxed verifiable epochs and publish events using a new event channel interface. Several APIs and struct fields are updated for consistency.

Changes

File(s) Change Summary
crates/cli/src/cfg.rs, crates/cli/src/main.rs Refactored verifying key handling: removed warnings, made verifying key non-optional, and updated argument application logic.
crates/da/Cargo.toml Added new dependencies: thiserror, serde_json, web-time, sp1-verifier, mockall.
crates/da/src/celestia/full_node.rs, crates/da/src/celestia/light_client.rs, crates/da/src/memory.rs Integrated EventChannel for event publishing, changed epoch return types to boxed trait objects, refactored event subscription methods.
crates/da/src/events.rs Renamed LightClientEvent to PrismEvent, updated event publishing and forwarding logic, added channel forwarding from subscribers.
crates/da/src/lib.rs Introduced VerifiableStateTransition trait, boxed VerifiableEpoch, commitment verification, and refactored DA layer trait with #[automock].
crates/da/src/utils.rs Made verifying_key non-optional in NetworkConfig, updated default and formatting logic; added cross-platform spawn_task utility for async task spawning.
crates/node_types/lightclient/src/lib.rs Removed re-export of events module.
crates/node_types/lightclient/src/lightclient.rs Refactored to use boxed verifiable epochs, unified event handling via EventChannel, removed optional prover key, and simplified verification logic.
crates/node_types/prover/src/prover/tests/mod.rs Updated test to use new commitment and height accessors on verifiable epochs.
crates/node_types/prover/src/prover_engine.rs Added method to retrieve verification keys, removed explicit epoch proof verification method.
crates/node_types/prover/src/syncer.rs Refactored to use VerifiableEpoch, integrated commitment verification, and removed explicit proof checking.
crates/node_types/uniffi-lightclient/src/lib.rs Switched to direct event subscriber usage, updated event channel handling, and removed optionality.
crates/node_types/uniffi-lightclient/src/types.rs Updated event conversion to use PrismEvent instead of LightClientEvent.
crates/tests/src/lib.rs Simplified LightClient construction, removed event channel handling.
verification_keys/keys.json Replaced base and recursive verification key values with new hex strings.
crates/errors/src/lib.rs Added detailed error enums for epoch verification, signature, and commitment errors; extended DataAvailabilityError.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LightClient
    participant DA_Layer as DataAvailabilityLayer
    participant EventChannel

    User->>LightClient: Start client (run)
    LightClient->>DA_Layer: Subscribe to event_channel
    DA_Layer->>EventChannel: Publish PrismEvent::UpdateDAHeight
    EventChannel->>LightClient: Receive UpdateDAHeight event
    LightClient->>DA_Layer: get_finalized_epoch (returns Vec<VerifiableEpoch>)
    LightClient->>VerifiableEpoch: verify (with verifying key)
    VerifiableEpoch-->>LightClient: Commitments, verification result
    LightClient->>EventChannel: Publish PrismEvent (sync events)
Loading

Possibly related PRs

Suggested reviewers

  • sebasti810

Poem

🐇
In the garden of epochs, events now bloom,
With channels and traits, we sweep out the gloom.
Commitments verified, keys shining bright—
Rabbits hop forward, code refactored just right.
From boxed epochs we leap,
Into verifiable sleep,
Prism’s light shines anew in the night!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 01c8caa and 3e071a3.

📒 Files selected for processing (2)
  • crates/da/src/celestia/light_client.rs (5 hunks)
  • verification_keys/keys.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • verification_keys/keys.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/da/src/celestia/light_client.rs
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build-and-push-image
  • GitHub Check: clippy
  • GitHub Check: unused dependencies
  • GitHub Check: coverage
  • GitHub Check: integration-test
  • GitHub Check: unit-test
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch verifiable-epochs

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 marked this pull request as ready for review June 16, 2025 10:35
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: 5

🔭 Outside diff range comments (3)
crates/cli/src/cfg.rs (1)

235-300: Incorrect fallback ignores verifying_key loaded from the config file

network_config is derived from config.network.network.config()a fresh default for the selected network – not the already-deserialized config.network.
If the user specifies a verifying key only in config.toml, it will be silently discarded and replaced by the default key produced in Network::config(). This breaks existing deployments and violates the new “verifying key is mandatory” contract.

-            verifying_key: args
-                .verifying_key
-                .and_then(|x| VerifyingKey::from_base64(x).ok())
-                .unwrap_or(network_config.verifying_key.clone()),
+            verifying_key: args
+                .verifying_key
+                .and_then(|x| VerifyingKey::from_base64(x).ok())
+                // fall back to the key that was *actually* read from the config file
+                .unwrap_or_else(|| config.network.verifying_key.clone()),

Failing to fix this will cause signature-verification mismatches at runtime.

crates/da/src/celestia/utils.rs (1)

60-70: Random placeholder verifying_key causes inconsistent configs

SigningKey::new_ed25519().verifying_key() generates a new random key every time NetworkConfig::default() is called. As a result:

• Two components in the same process may hold different “default” keys.
• The key written to a freshly-generated config.toml will not match the key later produced by Network::Custom(..).config() during runtime, breaking signature verification.

-            // TODO: This is just a placeholder, don't let this get merged
-            verifying_key: SigningKey::new_ed25519().verifying_key(),
+            // MUST be supplied by the user; use a clearly invalid sentinel to fail fast
+            verifying_key: VerifyingKey::from_base64("").unwrap_or_else(|_| {
+                panic!("verifying_key must be provided in the configuration")
+            }),

Alternatively, keep it Option<VerifyingKey> and enforce presence during CLI validation.

Leaving this as-is will yield hard-to-trace verification failures.

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

92-117: Release write-locks before broadcasting / publishing events.

blocks, pending_*, and latest_height write-locks remain held while:

  1. sending over the height/channel
  2. publishing PrismEvent::UpdateDAHeight

If any subscriber tries to acquire a read-lock on blocks in its handler you have a classic write-→read dead-lock.

Move the lock scopes into a separate block so they are dropped before I/O:

{
    let mut blocks = self.blocks.write().await;
    /* build & push new_block */
} // <- locks released here

// now broadcast + publish
let _ = self.height_update_tx.send(*latest_height);
let _ = self.block_update_tx.send(new_block.clone());
event_publisher.send(PrismEvent::UpdateDAHeight { height: *latest_height });
🧹 Nitpick comments (18)
crates/da/Cargo.toml (2)

21-25: Move test-only crates to [dev-dependencies]

serde_json, web-time (with serde feature), sp1-verifier, and especially mockall pull in large transitive graphs.
Unless they are needed in the final WASM / binary, place them under [dev-dependencies] (or behind a feature flag) to keep compile time and binary size down.

-[dependencies]
+# Runtime deps
 [dependencies]
 …
 
-[dependencies]
-mockall = { workspace = true }
+[dev-dependencies]
+mockall = { workspace = true }

Also applies to: 29-30, 35-36


24-24: web-time is not wasm32-friendly by default

web-time relies on std::time for native targets. On the wasm32 build you already gate tokio, but web-time is unconditional here.
If you need it in WASM, enable "wasm-bindgen" or guard the entire dep with cfg(not(target_arch="wasm32")).

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

17-18: EventChannel import is now unused

After inlining event handling inside LightClient, this import can be dropped to avoid the unused_imports warning.

-use prism_da::events::EventChannel;
crates/cli/src/main.rs (1)

17-19: Remove stale EventChannel import

No symbol from prism_da::events is used after the refactor.

-use prism_da::events::EventChannel;
crates/da/src/utils.rs (1)

11-17: Return the JoinHandle (or at least log it) to avoid silently dropped panics

tokio::spawn returns a JoinHandle. By discarding it we (a) detach the task, making shutdown coordination harder, and (b) lose the panic/error information. Consider:

-    tokio::spawn(future);
+    tokio::spawn(future);
+    // Option A – propagate handle
+    // Option B – at minimum:  tracing::debug!("spawned task: {:?}", handle);

Keeping the handle (or logging it) is a low-cost way to surface runtime failures.

crates/node_types/prover/src/prover_engine.rs (2)

2-3: Remove unused import

VerifiableEpoch is imported but not referenced anywhere in this file.
Drop it to silence the unused import lint.

-use prism_da::{VerifiableEpoch, VerificationKeys};
+use prism_da::VerificationKeys;

50-61: verification_keys can avoid repeated allocations

Calling bytes32() on each access clones the full 32-byte array every time verification_keys() is called.
Given this method is expected to be invoked inside hot paths (e.g. once per-epoch verification), cache the pre-computed VerificationKeys inside the struct or return references instead of freshly-allocated copies.

This is optional, but it will shave a few heap-free copies per call.

crates/node_types/prover/src/syncer.rs (2)

167-171: Logging shows the wrong value

Inside the loop we log

debug!("Found finalized epoch {} at height {}", epoch.height(), height);

Good.
But a few lines below, when skipping an already-processed epoch, the branch logs current_epoch instead of the skipped height (see lines 229-231). That obscures which epoch was dropped.

Consider:

- debug!("epoch {} already processed internally", current_epoch);
+ debug!("epoch {} already processed internally", height);

233-235: Avoid creating a fresh VerificationKeys for every epoch

epoch.verify(&self.verifying_key, &self.prover_engine.verification_keys())

verification_keys() allocates new 32-byte arrays on each call.
Compute once at Syncer construction and reuse, or hold an Arc<VerificationKeys> inside ProverEngine and return a reference to prevent needless cloning.

crates/da/src/celestia/full_node.rs (2)

3-6: Drop unused EventPublisher import

The file never references the type directly; inference handles it.
Removing the import eliminates the warning seen in CI.

-use crate::{
-    FinalizedEpoch, LightDataAvailabilityLayer, VerifiableEpoch,
-    events::{EventChannel, EventPublisher, PrismEvent},
-};
+use crate::{
+    FinalizedEpoch, LightDataAvailabilityLayer, VerifiableEpoch,
+    events::{EventChannel, PrismEvent},
+};

128-141: Handle send failures on saturated event channel

event_publisher.send(PrismEvent::UpdateDAHeight { height });

EventPublisher::send drops the message silently when the channel is full.
For long-running tasks this can mask back-pressure problems. At minimum log the error:

if let Err(e) = event_publisher.send(PrismEvent::UpdateDAHeight { height }) {
    trace!("event channel full, dropping DA-height update: {}", e);
}
crates/da/src/events.rs (2)

1-1: Remove unused NodeEventInfo import

It’s not referenced after the refactor and triggers unused import lints.

-use lumina_node::events::{NodeEvent, NodeEventInfo};
+use lumina_node::events::NodeEvent;

112-138: Non-wasm32 builds silently drop forwarded Lumina events

start_forwarding only re-publishes Lumina events on WASM targets; desktop builds merely log them with trace!.
If downstream consumers rely on those events they will never receive them.

Consider always forwarding, gating the log behind target-specific code instead:

publisher.send(PrismEvent::LuminaEvent { event: event.clone() });
#[cfg(not(target_arch = "wasm32"))]
trace!("lumina event: {:?}", event);
crates/da/src/celestia/light_client.rs (1)

125-129: Redundant clone of lumina_sub

EventChannel::from(lumina_sub.clone()) clones the Arc immediately after creation; the original lumina_sub is never reused.
Create the Arc once:

-let lumina_sub = Arc::new(Mutex::new(event_subscriber));
-// Creates an EventChannel that starts forwarding lumina events
-let prism_chan = EventChannel::from(lumina_sub.clone());
+let lumina_sub = Arc::new(Mutex::new(event_subscriber));
+let prism_chan = EventChannel::from(lumina_sub);
crates/da/src/memory.rs (1)

128-136: Avoid the extra epoch clone per call.

map(|epoch| Box::new(epoch) …) clones every FinalizedEpoch; for large proofs this is expensive.
If the caller only needs read-only access consider storing epochs in Arc and returning Arc<dyn VerifiableStateTransition> to eliminate the copy.

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

62-67: Redundant Arc around EventPublisher.

event_chan.publisher() already returns a cheap, cloneable handle; wrapping it inside another Arc adds an extra layer and forces event_pub.send(..) to rely on deref-coercion.
Consider using the value directly:

-        let event_pub = Arc::new(event_chan.publisher());
+        let event_pub = event_chan.publisher();

261-270: Suppress unused variable warning for prev_commitment.

prev_commitment is never used after verification. Prefix with _ or drop the binding:

-        let (prev_commitment, curr_commitment) =
+        let (_, curr_commitment) =
             epoch.verify(&self.prover_pubkey, &self.sp1_vkeys)?;
crates/node_types/uniffi-lightclient/src/lib.rs (1)

9-13: Remove or use the now-unused imports to avoid dead_code/unused_imports warnings

LightDataAvailabilityLayer and EventChannel are brought into scope but never referenced in this file.
If the workspace has #![deny(warnings)] (common in CI), this will turn into a compilation error.

-use prism_da::{
-    LightDataAvailabilityLayer,
-    celestia::{light_client::LightClientConnection, utils::Network},
-    events::{EventChannel, EventSubscriber},
-};
+use prism_da::{
+    celestia::{light_client::LightClientConnection, utils::Network},
+    events::EventSubscriber,
+};

Or keep them and add a TODO explaining their future use.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5049c56 and 52faab8.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • crates/cli/src/cfg.rs (1 hunks)
  • crates/cli/src/main.rs (3 hunks)
  • crates/da/Cargo.toml (1 hunks)
  • crates/da/src/celestia/full_node.rs (8 hunks)
  • crates/da/src/celestia/light_client.rs (5 hunks)
  • crates/da/src/celestia/utils.rs (4 hunks)
  • crates/da/src/events.rs (5 hunks)
  • crates/da/src/lib.rs (6 hunks)
  • crates/da/src/memory.rs (9 hunks)
  • crates/da/src/utils.rs (1 hunks)
  • crates/node_types/lightclient/src/lib.rs (0 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (10 hunks)
  • crates/node_types/prover/src/prover/tests/mod.rs (1 hunks)
  • crates/node_types/prover/src/prover_engine.rs (2 hunks)
  • crates/node_types/prover/src/syncer.rs (4 hunks)
  • crates/node_types/uniffi-lightclient/src/lib.rs (4 hunks)
  • crates/node_types/uniffi-lightclient/src/types.rs (2 hunks)
  • crates/tests/src/lib.rs (2 hunks)
  • verification_keys/keys.json (1 hunks)
💤 Files with no reviewable changes (1)
  • crates/node_types/lightclient/src/lib.rs
🧰 Additional context used
🧬 Code Graph Analysis (5)
crates/node_types/prover/src/prover/tests/mod.rs (1)
crates/da/src/lib.rs (2)
  • height (48-48)
  • height (90-92)
crates/tests/src/lib.rs (1)
crates/node_types/lightclient/src/lightclient.rs (1)
  • new (58-76)
crates/node_types/prover/src/syncer.rs (3)
crates/telemetry/src/metrics_registry.rs (1)
  • get_metrics (100-108)
crates/da/src/lib.rs (2)
  • height (48-48)
  • height (90-92)
crates/node_types/lightclient/src/lightclient.rs (1)
  • process_epoch (261-273)
crates/da/src/celestia/light_client.rs (6)
crates/da/src/events.rs (2)
  • new (95-98)
  • from (142-146)
crates/da/src/celestia/full_node.rs (3)
  • new (43-71)
  • event_channel (114-116)
  • get_finalized_epoch (76-112)
crates/da/src/memory.rs (3)
  • new (40-61)
  • event_channel (141-143)
  • get_finalized_epoch (128-139)
crates/node_types/lightclient/src/lightclient.rs (1)
  • new (58-76)
crates/da/src/celestia/utils.rs (1)
  • create_namespace (110-120)
crates/da/src/lib.rs (5)
  • event_channel (226-226)
  • get_finalized_epoch (224-224)
  • height (48-48)
  • height (90-92)
  • try_from (211-217)
crates/da/src/celestia/full_node.rs (5)
crates/da/src/lib.rs (5)
  • event_channel (226-226)
  • get_finalized_epoch (224-224)
  • height (48-48)
  • height (90-92)
  • try_from (211-217)
crates/da/src/celestia/light_client.rs (3)
  • event_channel (183-185)
  • new (99-137)
  • get_finalized_epoch (187-227)
crates/da/src/memory.rs (3)
  • event_channel (141-143)
  • new (40-61)
  • get_finalized_epoch (128-139)
crates/da/src/events.rs (1)
  • new (95-98)
crates/node_types/lightclient/src/lightclient.rs (1)
  • new (58-76)
🪛 GitHub Check: integration-test
crates/da/src/events.rs

[failure] 1-1:
unused import: NodeEventInfo

crates/da/src/celestia/full_node.rs

[failure] 5-5:
unused import: EventPublisher

crates/da/src/lib.rs

[failure] 19-19:
unused import: EventSubscriber


[failure] 108-108:
unused borrow that must be used

🪛 GitHub Check: unit-test
crates/da/src/events.rs

[failure] 1-1:
unused import: NodeEventInfo

crates/da/src/celestia/full_node.rs

[failure] 5-5:
unused import: EventPublisher

crates/da/src/lib.rs

[failure] 19-19:
unused import: EventSubscriber


[failure] 108-108:
unused borrow that must be used

🪛 GitHub Check: clippy
crates/da/src/events.rs

[failure] 1-1:
unused import: NodeEventInfo

crates/da/src/celestia/full_node.rs

[failure] 5-5:
unused import: EventPublisher

crates/da/src/lib.rs

[failure] 19-19:
unused import: EventSubscriber


[failure] 108-108:
unused borrow that must be used


[failure] 108-108:
unnecessary operation

🪛 GitHub Check: coverage
crates/da/src/events.rs

[failure] 1-1:
unused import: NodeEventInfo

crates/da/src/celestia/full_node.rs

[failure] 5-5:
unused import: EventPublisher

crates/da/src/lib.rs

[failure] 19-19:
unused import: EventSubscriber


[failure] 108-108:
unused borrow that must be used

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: unused dependencies
🔇 Additional comments (7)
verification_keys/keys.json (1)

1-1: Hex length / prefix sanity-check required before merging

The two verifying-key blobs look well-formed (0x + 64 hex chars) but this file is consumed by several crates at runtime. A single wrong nibble bricks verification and the failure mode is silent (proof always fails).

Please add an integrity assertion (e.g. unit test that parses the keys and matches the expected byte-length) or, at minimum, document the commit / circuit these keys were generated from so future rotations are traceable.

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

116-118: Height expectation likely off by the configured gap

You wait until height >= initial_epoch_height + 6, then expect
gap_proof.height() == initial_epoch.height() + 1.
Shouldn’t the gap proof be at initial_epoch.height() + 6 (or + max_epochless_gap)?
Please double-check the business rule; otherwise this assertion may produce false positives.


114-122: Type mismatch in assert_eq! will not compile

gap_proof.commitments() returns a pair by reference; commitment_after_epoch.commitment is an owned value.
assert_eq! between &T and T fails unless PartialEq<&T> is implemented.

-let (_, current_commitment) = gap_proof.commitments();
-
-assert_eq!(
-    current_commitment, commitment_after_epoch.commitment,
+let (_, current_commitment) = gap_proof.commitments();
+assert_eq!(
+    *current_commitment, commitment_after_epoch.commitment,

Likely an incorrect or invalid review comment.

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

103-104: LightClient::new call reflects new API – LGTM

The constructor now only needs (da, vk); test code adapts correctly.

crates/cli/src/main.rs (1)

94-95: Constructor adaption looks correct

LightClient::new(da, verifying_key) matches the new signature – good catch on simplifying setup.

crates/node_types/uniffi-lightclient/src/types.rs (1)

62-95: Ensure match is kept exhaustive when new PrismEvent variants are added

The current conversion matches every variant that exists today, but any future addition to PrismEvent will silently trigger a compiler-silenced “non-exhaustive” pattern via the wildcard arm you just removed. Please add a final _ => unreachable!() (or equivalent) to make missing mappings a compile-time error, or explicitly mark PrismEvent as #[non_exhaustive] upstream.

This prevents the mobile bindings from diverging from core functionality.

crates/node_types/uniffi-lightclient/src/lib.rs (1)

26-27: Good move: eliminate the Option wrapper

By storing EventSubscriber directly in the Mutex you guarantee the subscriber is always initialised, simplifying the control flow and removing one failure branch in next_event(). 👍

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 refactors the data‐availability and lightclient layers to make FinalizedEpoch mockable, centralizes event definitions in the da crate, and updates downstream code to use the new trait and event API.

  • Introduces VerifiableStateTransition trait and updates LightDataAvailabilityLayer to return VerifiableEpoch
  • Moves event types into crates/da/src/events.rs (renamed to PrismEvent) and updates subscribers/publishers
  • Updates lightclient and prover code (and tests) to consume VerifiableEpoch and the new event channel API

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/da/src/lib.rs Defined VerifiableStateTransition trait and VerifiableEpoch alias
crates/da/src/events.rs Moved event enum into DA crate, renamed to PrismEvent
crates/da/src/memory.rs In-memory DA layer now returns VerifiableEpoch and publishes events
crates/da/src/utils.rs Added spawn_task helper for WASM vs native
crates/da/src/celestia/utils.rs Changed NetworkConfig.verifying_key to non-optional
crates/node_types/prover/src/syncer.rs Refactored process_epoch to use VerifiableEpoch
crates/node_types/prover/src/prover_engine.rs Added verification_keys() helper, removed old proof‐verify method
crates/node_types/lightclient/src/lightclient.rs Refactored to use the new event_channel API and VerifiableEpoch
crates/node_types/uniffi-lightclient/src/types.rs Switched mapping from LightClientEvent to PrismEvent
crates/tests/src/lib.rs Updated tests to accommodate new LightClient::new signature
Comments suppressed due to low confidence (1)

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

  • The FinalizedEpoch import isn’t referenced in this file after the refactor. You can remove it to avoid dead code.
use prism_da::{FinalizedEpoch, LightDataAvailabilityLayer, VerifiableEpoch, VerificationKeys, events::EventChannel,};

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: 2

♻️ Duplicate comments (2)
crates/da/src/lib.rs (2)

19-20: Remove unused EventSubscriber import

EventSubscriber is no longer referenced – keeping it breaks cargo check when rustc is run with -D warnings.


115-116: &self.verify_signature(..)? causes a hard compile-error

? cannot be applied to &Result<…>.
Remove the leading & (and avoid the unnecessary clone() if you accept a reference).

-        &self.verify_signature(vk.clone())?;
+        self.verify_signature(vk)?;
🧹 Nitpick comments (5)
crates/da/src/lib.rs (2)

184-184: Accept &VerifyingKey to avoid needless cloning

The key is never mutated; passing by reference removes the clone() and allocations elsewhere.

-pub fn verify_signature(&self, vk: VerifyingKey) -> Result<(), EpochVerificationError> {
+pub fn verify_signature(&self, vk: &VerifyingKey) -> Result<(), EpochVerificationError> {

Call-sites can then pass vk by reference.


236-237: Minor typo in error message

"epoch proo verification error""epoch proof verification error".

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

2-2: Delete unused NodeEvent import

The symbol isn’t used anywhere in this module and will trigger the linter.

-use lumina_node::events::NodeEvent;

11-11: Drop redundant std::self in use-statement

-use std::{self, sync::Arc};
+use std::sync::Arc;

262-263: Suppress unused variable warning

prev_commitment isn’t used after verification; prefix with an underscore to silence the warning cleanly.

-        let (prev_commitment, curr_commitment) =
+        let (_, curr_commitment) =
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52faab8 and 05cf862.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • crates/cli/src/cfg.rs (1 hunks)
  • crates/cli/src/main.rs (3 hunks)
  • crates/da/Cargo.toml (1 hunks)
  • crates/da/src/celestia/full_node.rs (8 hunks)
  • crates/da/src/celestia/light_client.rs (5 hunks)
  • crates/da/src/celestia/utils.rs (4 hunks)
  • crates/da/src/events.rs (5 hunks)
  • crates/da/src/lib.rs (4 hunks)
  • crates/da/src/memory.rs (9 hunks)
  • crates/da/src/utils.rs (1 hunks)
  • crates/node_types/lightclient/src/lib.rs (0 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (10 hunks)
  • crates/node_types/prover/src/prover/tests/mod.rs (1 hunks)
  • crates/node_types/prover/src/prover_engine.rs (2 hunks)
  • crates/node_types/prover/src/syncer.rs (4 hunks)
  • crates/node_types/uniffi-lightclient/src/lib.rs (4 hunks)
  • crates/node_types/uniffi-lightclient/src/types.rs (2 hunks)
  • crates/tests/src/lib.rs (2 hunks)
  • verification_keys/keys.json (1 hunks)
💤 Files with no reviewable changes (1)
  • crates/node_types/lightclient/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (16)
  • verification_keys/keys.json
  • crates/da/Cargo.toml
  • crates/da/src/utils.rs
  • crates/node_types/prover/src/prover/tests/mod.rs
  • crates/tests/src/lib.rs
  • crates/cli/src/cfg.rs
  • crates/cli/src/main.rs
  • crates/node_types/prover/src/prover_engine.rs
  • crates/da/src/celestia/utils.rs
  • crates/node_types/uniffi-lightclient/src/types.rs
  • crates/node_types/prover/src/syncer.rs
  • crates/da/src/events.rs
  • crates/da/src/celestia/full_node.rs
  • crates/da/src/memory.rs
  • crates/node_types/uniffi-lightclient/src/lib.rs
  • crates/da/src/celestia/light_client.rs
🔇 Additional comments (1)
crates/node_types/lightclient/src/lightclient.rs (1)

65-67: Potential double-Arc around EventPublisher

event_chan.publisher() already returns an Arc<EventPublisher> (per typical channel APIs). Wrapping it again nests two Arcs and forces extra derefs on every call.

-        let event_pub = Arc::new(event_chan.publisher());
+        let event_pub = event_chan.publisher();

Please verify the actual return type of publisher().
If it already is an Arc, adjust the field type to Arc<EventPublisher> and remove the extra wrapper.

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: 4

♻️ Duplicate comments (2)
crates/da/src/lib.rs (2)

124-129: Illegal move of self.proof on the WASM path

self.proof is moved out of &self, which is not allowed because Vec<u8> is not Copy.
Borrow instead:

-#[cfg(target_arch = "wasm32")]
-let finalized_epoch_proof = self.proof;
+#[cfg(target_arch = "wasm32")]
+let finalized_epoch_proof = &self.proof;

The same pattern is already used for the native path; keep both consistent.


150-153: Do not unwrap() during signature insertion

encode_to_bytes() can fail; an unwrap() here will crash the node.
Propagate the error instead:

-let plaintext = self.encode_to_bytes().unwrap();
+let plaintext = self
+    .encode_to_bytes()
+    .map_err(|e| EpochVerificationError::SerializationError(e.to_string()))?;
🧹 Nitpick comments (3)
crates/node_types/lightclient/src/lightclient.rs (1)

306-364: Remove dead code: local commitment-verification helpers

extract_commitments, verify_commitments, and verify_snark_proof are no longer used after delegating verification to VerifiableStateTransition::verify.
Leaving them in place bloats the binary and risks divergence if future logic changes.

Consider deleting them or making them #[cfg(test)] helpers if they are only needed in unit tests.

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

114-115: Avoid cloning the verifying key on every epoch verification

verify_signature only needs a shared reference. Change the signature to accept &VerifyingKey and pass it directly:

-self.verify_signature(vk.clone())?;
+self.verify_signature(vk)?;

This removes an unnecessary heap allocation and improves performance.


235-236: Typo in error message

"epoch proo verification error""epoch proof verification error".

Even minor typos make debugging harder and pollute logs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 05cf862 and 6e9c5a0.

📒 Files selected for processing (9)
  • crates/cli/src/cfg.rs (2 hunks)
  • crates/cli/src/main.rs (3 hunks)
  • crates/da/src/celestia/full_node.rs (8 hunks)
  • crates/da/src/events.rs (5 hunks)
  • crates/da/src/lib.rs (4 hunks)
  • crates/node_types/lightclient/src/lightclient.rs (10 hunks)
  • crates/node_types/prover/src/prover_engine.rs (2 hunks)
  • crates/node_types/prover/src/syncer.rs (4 hunks)
  • crates/node_types/uniffi-lightclient/src/lib.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • crates/cli/src/cfg.rs
  • crates/cli/src/main.rs
  • crates/node_types/uniffi-lightclient/src/lib.rs
  • crates/node_types/prover/src/prover_engine.rs
  • crates/da/src/celestia/full_node.rs
  • crates/node_types/prover/src/syncer.rs
  • crates/da/src/events.rs
🔇 Additional comments (1)
crates/node_types/lightclient/src/lightclient.rs (1)

86-100: Possible mismatch between subscriber item type and access pattern

event_sub.recv().await typically yields the event itself (PrismEvent); the code then accesses an .event field:

if let PrismEvent::UpdateDAHeight { height } = event_info.event { ... }

Unless EventChannel wraps events in a struct with an event field, this will not compile.
Please verify the actual type returned by recv() and remove the extra indirection if necessary.

Copy link
Contributor

@sebasti810 sebasti810 left a comment

Choose a reason for hiding this comment

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

its still very beautiful, tried to be as pedantic as possible

Copy link
Contributor

@sebasti810 sebasti810 left a comment

Choose a reason for hiding this comment

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

two more comments, all in all beautiful

Copy link
Contributor

@sebasti810 sebasti810 left a comment

Choose a reason for hiding this comment

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

Love

@distractedm1nd distractedm1nd merged commit 85d067f into main Jun 24, 2025
8 of 11 checks passed
Zombeescott pushed a commit to Zombeescott/prism that referenced this pull request Jun 24, 2025
…eltadevsde#342)

* verifiable epochs

* refactor: moving event channel code to DA crate

* refactor: renaming LightClientEvent to PrismEvent

* feat: implement event channel for inmemory da and fn celestia

* a bit more sensible errors for FinalizedEpoch verification

* clippy

* fix: review comments

* update
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