Skip to content

Commit 629e82f

Browse files
authored
Yaziciahmet/light client type (#13)
* Rename Prover namespace to BatchProver * Add light client type * Separate batch and light client prover configs * Add citrea light client proving config * lint * Remove unused dep * Minor cleanup * Fix comment * Lint
1 parent 669d14f commit 629e82f

20 files changed

+310
-85
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ bitcoin = { version = "0.32.2", features = ["serde", "rand"] }
1111
bitcoincore-rpc = { version = "0.18.0" }
1212
bollard = { version = "0.17.1" }
1313
futures = "0.3"
14+
hex = { version = "0.4.3", default-features = false, features = ["serde"] }
15+
jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] }
1416
log = "0.4"
1517
rand = "0.8"
1618
serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] }
@@ -19,13 +21,10 @@ tempfile = "3.8"
1921
tokio = { version = "1.39", features = ["full"] }
2022
toml = "0.8.0"
2123
which = "6.0.1"
22-
jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] }
23-
hex = { version = "0.4.3", default-features = false, features = ["serde"] }
2424

2525
# Citrea dependencies
2626
sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", default-features = false, features = ["client"] }
2727
sov-rollup-interface = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d" }
28-
syn = { version = "1.0", features = ["full", "extra-traits"] }
2928

3029
[patch.crates-io]
3130
bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "0ae498d" }

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ lint: ## cargo check and clippy. Skip clippy on guest code since it's not suppo
2929
dprint check
3030
cargo +nightly fmt --all --check
3131
cargo check --all-targets --all-features
32-
$(MAKE) check-fuzz
33-
SKIP_GUEST_BUILD=1 cargo clippy --all-targets --all-features
32+
cargo clippy --all-targets --all-features
3433

3534
lint-fix: ## dprint fmt, cargo fmt, fix and clippy. Skip clippy on guest code since it's not supported by risc0
3635
dprint fmt
3736
cargo +nightly fmt --all
3837
cargo fix --allow-dirty
39-
SKIP_GUEST_BUILD=1 cargo clippy --fix --allow-dirty
38+
cargo clippy --fix --allow-dirty
4039

4140
docs: ## Generates documentation locally
4241
cargo doc --open

src/prover.rs renamed to src/batch_prover.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use std::time::SystemTime;
22

3-
use super::{config::FullProverConfig, Result};
4-
use crate::node::Node;
53
use anyhow::bail;
64
use log::debug;
75
use tokio::time::{sleep, Duration};
86

9-
pub type Prover = Node<FullProverConfig>;
7+
use super::{config::FullBatchProverConfig, Result};
8+
use crate::node::Node;
9+
10+
pub type BatchProver = Node<FullBatchProverConfig>;
1011

11-
impl Prover {
12+
impl BatchProver {
1213
pub async fn wait_for_l1_height(&self, height: u64, timeout: Option<Duration>) -> Result<()> {
1314
let start = SystemTime::now();
1415
let timeout = timeout.unwrap_or(Duration::from_secs(600));
1516
loop {
16-
debug!("Waiting for prover height {}", height);
17+
debug!("Waiting for batch prover height {}", height);
1718
let latest_block = self.client.ledger_get_last_scanned_l1_height().await?;
1819

1920
if latest_block >= height {
@@ -22,7 +23,7 @@ impl Prover {
2223

2324
let now = SystemTime::now();
2425
if start + timeout <= now {
25-
bail!("Timeout. Latest prover L1 height is {}", latest_block);
26+
bail!("Timeout. Latest batch prover L1 height is {}", latest_block);
2627
}
2728

2829
sleep(Duration::from_secs(1)).await;

src/bitcoin.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ impl BitcoinNode {
128128
async fn load_wallets(&self) {
129129
let _ = self.load_wallet(&NodeKind::Bitcoin.to_string()).await;
130130
let _ = self.load_wallet(&NodeKind::Sequencer.to_string()).await;
131-
let _ = self.load_wallet(&NodeKind::Prover.to_string()).await;
131+
let _ = self.load_wallet(&NodeKind::BatchProver.to_string()).await;
132+
let _ = self
133+
.load_wallet(&NodeKind::LightClientProver.to_string())
134+
.await;
132135
}
133136

134137
// Switch this over to Node signature once we add support for docker to citrea nodes

src/citrea_config/prover.rs renamed to src/citrea_config/batch_prover.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'de> Deserialize<'de> for ProverGuestRunConfig {
3232

3333
/// Prover configuration
3434
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
35-
pub struct ProverConfig {
35+
pub struct BatchProverConfig {
3636
/// Prover run mode
3737
pub proving_mode: ProverGuestRunConfig,
3838
/// Average number of commitments to prove
@@ -41,7 +41,7 @@ pub struct ProverConfig {
4141
pub enable_recovery: bool,
4242
}
4343

44-
impl Default for ProverConfig {
44+
impl Default for BatchProverConfig {
4545
fn default() -> Self {
4646
Self {
4747
proving_mode: ProverGuestRunConfig::Execute,
@@ -53,12 +53,13 @@ impl Default for ProverConfig {
5353

5454
#[cfg(test)]
5555
mod tests {
56-
use std::io::Write;
56+
use std::{
57+
fs::File,
58+
io::{Read, Write},
59+
path::Path,
60+
};
5761

5862
use serde::de::DeserializeOwned;
59-
use std::fs::File;
60-
use std::io::Read;
61-
use std::path::Path;
6263
use tempfile::NamedTempFile;
6364

6465
use super::*;
@@ -91,8 +92,8 @@ mod tests {
9192

9293
let config_file = create_config_from(config);
9394

94-
let config: ProverConfig = from_toml_path(config_file.path()).unwrap();
95-
let expected = ProverConfig {
95+
let config: BatchProverConfig = from_toml_path(config_file.path()).unwrap();
96+
let expected = BatchProverConfig {
9697
proving_mode: ProverGuestRunConfig::Skip,
9798
proof_sampling_number: 500,
9899
enable_recovery: true,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::batch_prover::ProverGuestRunConfig;
4+
5+
/// Light client prover configuration
6+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
7+
pub struct LightClientProverConfig {
8+
/// Prover run mode
9+
pub proving_mode: ProverGuestRunConfig,
10+
/// Average number of commitments to prove
11+
pub proof_sampling_number: usize,
12+
/// If true prover will try to recover ongoing proving sessions
13+
pub enable_recovery: bool,
14+
}
15+
16+
impl Default for LightClientProverConfig {
17+
fn default() -> Self {
18+
Self {
19+
proving_mode: ProverGuestRunConfig::Execute,
20+
proof_sampling_number: 0,
21+
enable_recovery: true,
22+
}
23+
}
24+
}
25+
26+
#[cfg(test)]
27+
mod tests {
28+
use std::{
29+
fs::File,
30+
io::{Read, Write},
31+
path::Path,
32+
};
33+
34+
use serde::de::DeserializeOwned;
35+
use tempfile::NamedTempFile;
36+
37+
use super::*;
38+
39+
/// Reads toml file as a specific type.
40+
pub fn from_toml_path<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> anyhow::Result<R> {
41+
let mut contents = String::new();
42+
{
43+
let mut file = File::open(path)?;
44+
file.read_to_string(&mut contents)?;
45+
}
46+
let result: R = toml::from_str(&contents)?;
47+
48+
Ok(result)
49+
}
50+
51+
fn create_config_from(content: &str) -> NamedTempFile {
52+
let mut config_file = NamedTempFile::new().unwrap();
53+
config_file.write_all(content.as_bytes()).unwrap();
54+
config_file
55+
}
56+
57+
#[test]
58+
fn test_correct_prover_config() {
59+
let config = r#"
60+
proving_mode = "skip"
61+
proof_sampling_number = 500
62+
enable_recovery = true
63+
"#;
64+
65+
let config_file = create_config_from(config);
66+
67+
let config: LightClientProverConfig = from_toml_path(config_file.path()).unwrap();
68+
let expected = LightClientProverConfig {
69+
proving_mode: ProverGuestRunConfig::Skip,
70+
proof_sampling_number: 500,
71+
enable_recovery: true,
72+
};
73+
assert_eq!(config, expected);
74+
}
75+
}

src/citrea_config/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// Should ideally be automatically kept in sync somehow but manually copied here for the time being.
44
// Configs are stable and not expected to change much.
55

6+
pub(crate) mod batch_prover;
67
pub(crate) mod bitcoin;
7-
pub(crate) mod prover;
8+
pub(crate) mod light_client_prover;
89
pub(crate) mod rollup;
910
pub(crate) mod sequencer;
1011

src/citrea_config/rollup.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct RunnerConfig {
1414
/// Number of blocks to request during sync
1515
#[serde(default = "default_sync_blocks_count")]
1616
pub sync_blocks_count: u64,
17+
/// Configurations for pruning
18+
pub pruning_config: Option<PruningConfig>,
1719
}
1820

1921
/// RPC configuration.
@@ -118,3 +120,16 @@ pub struct FullNodeConfig<BitcoinServiceConfig> {
118120
/// Important pubkeys
119121
pub public_keys: RollupPublicKeys,
120122
}
123+
124+
/// A configuration type to define the behaviour of the pruner.
125+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
126+
pub struct PruningConfig {
127+
/// Defines the number of blocks from the tip of the chain to remove.
128+
pub distance: u64,
129+
}
130+
131+
impl Default for PruningConfig {
132+
fn default() -> Self {
133+
Self { distance: 256 }
134+
}
135+
}

src/citrea_config/sequencer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ mod tests {
7474

7575
use tempfile::NamedTempFile;
7676

77-
use crate::citrea_config::from_toml_path;
78-
7977
use super::*;
78+
use crate::citrea_config::from_toml_path;
8079

8180
fn create_config_from(content: &str) -> NamedTempFile {
8281
let mut config_file = NamedTempFile::new().unwrap();

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::time::{Duration, SystemTime};
22

33
use anyhow::{bail, Result};
4-
use jsonrpsee::core::client::ClientT;
54
use jsonrpsee::{
5+
core::client::ClientT,
66
http_client::{HttpClient, HttpClientBuilder},
77
rpc_params,
88
};

0 commit comments

Comments
 (0)