Skip to content

Commit 57a3960

Browse files
testing(lightclient): Mocking DA layer (#348)
* feat: mock da * update * update * fix * cleaner setup * another (failing) case * fixing bugs * new test cases, some fixes * ignoring too old headers * simplifications * new test cases * improvements
1 parent 5a646dc commit 57a3960

File tree

8 files changed

+524
-192
lines changed

8 files changed

+524
-192
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", packa
184184
curve25519-dalek-ng = { git = "https://github.com/sp1-patches/curve25519-dalek-ng", tag = "patch-4.1.1-sp1-4.0.0" }
185185
p256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-p256-13.2-sp1-4.1.0" }
186186
k256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-k256-13.4-sp1-4.1.0" }
187-
celestia-types = { git = "https://github.com/deltadevsde/lumina.git" }
187+
celestia-types = { git = "https://github.com/deltadevsde/lumina.git" }
188188
lumina-node = { git = "https://github.com/deltadevsde/lumina.git" }
189189

190190
[workspace.features]

crates/da/src/celestia/light_client.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ use lumina_node::{blockstore::IndexedDbBlockstore, store::IndexedDbStore};
2222
use lumina_node::NodeBuilder;
2323

2424
#[cfg(not(target_arch = "wasm32"))]
25-
use {
26-
blockstore::EitherBlockstore,
27-
redb::Database,
28-
tokio::task::spawn_blocking,
29-
};
25+
use {blockstore::EitherBlockstore, redb::Database, tokio::task::spawn_blocking};
3026

3127
#[cfg(feature = "uniffi")]
3228
use lumina_node_uniffi::types::NodeConfig;
@@ -183,6 +179,7 @@ impl LightDataAvailabilityLayer for LightClientConnection {
183179
Err(e) => return Err(anyhow!("Failed to fetch header: {}", e)),
184180
};
185181

182+
// TODO(Zombeescott): Implement retries + timeout
186183
match node.request_all_blobs(&header, self.snark_namespace, None).await {
187184
Ok(blobs) => {
188185
let epochs: Vec<VerifiableEpoch> = blobs

crates/da/src/events.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lumina_node::events::{NodeEvent, EventSubscriber as LuminaEventSub};
1+
use lumina_node::events::{EventSubscriber as LuminaEventSub, NodeEvent};
22
use prism_common::digest::Digest;
33
use serde::Serialize;
44
use std::{fmt, sync::Arc};
@@ -14,7 +14,9 @@ const EVENT_CHANNEL_CAPACITY: usize = 1024;
1414
#[serde(tag = "type")]
1515
#[serde(rename_all = "snake_case")]
1616
pub enum PrismEvent {
17-
SyncStarted { height: u64 },
17+
Ready,
18+
BackwardsSyncStarted { height: u64 },
19+
BackwardsSyncCompleted { height: Option<u64> },
1820
UpdateDAHeight { height: u64 },
1921
EpochVerificationStarted { height: u64 },
2022
EpochVerified { height: u64 },
@@ -35,8 +37,21 @@ pub enum PrismEvent {
3537
impl fmt::Display for PrismEvent {
3638
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3739
match self {
38-
PrismEvent::SyncStarted { height } => {
39-
write!(f, "Starting sync at height {}", height)
40+
PrismEvent::Ready => {
41+
write!(
42+
f,
43+
"Node is ready to start sync and listening for incoming headers"
44+
)
45+
}
46+
PrismEvent::BackwardsSyncStarted { height } => {
47+
write!(f, "Starting backwards sync at height {}", height)
48+
}
49+
PrismEvent::BackwardsSyncCompleted { height } => {
50+
write!(
51+
f,
52+
"Backwards sync complete, found epoch: {}",
53+
height.is_some()
54+
)
4055
}
4156
PrismEvent::UpdateDAHeight { height } => {
4257
write!(f, "Updated DA height to {}", height)

crates/da/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl From<EpochCommitments> for (Digest, Digest) {
6666

6767
/// `VerifiableStateTransition` is a trait wrapper around `FinalizedEpoch` that allows for mocking.
6868
/// The only concrete implementation of this trait is by `FinalizedEpoch`.
69+
#[automock]
6970
pub trait VerifiableStateTransition: Send {
7071
fn verify(
7172
&self,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
pub mod lightclient;
22
pub use lightclient::LightClient;
3+
4+
#[cfg(test)]
5+
mod tests;

0 commit comments

Comments
 (0)