Skip to content

Commit 669d14f

Browse files
committed
Re-implement citrea configs and remove related dependencies
1 parent c9c0eee commit 669d14f

File tree

9 files changed

+412
-10
lines changed

9 files changed

+412
-10
lines changed

Diff for: Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ tokio = { version = "1.39", features = ["full"] }
2020
toml = "0.8.0"
2121
which = "6.0.1"
2222
jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] }
23+
hex = { version = "0.4.3", default-features = false, features = ["serde"] }
2324

2425
# Citrea dependencies
25-
bitcoin-da = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", features = ["native"] }
26-
citrea-sequencer = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d" }
27-
sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", features = ["client"] }
26+
sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", default-features = false, features = ["client"] }
2827
sov-rollup-interface = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d" }
29-
sov-stf-runner = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", features = ["native"] }
28+
syn = { version = "1.0", features = ["full", "extra-traits"] }
3029

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

Diff for: src/bitcoin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
use anyhow::{bail, Context};
99
use async_trait::async_trait;
1010
use bitcoin::Address;
11-
use bitcoin_da::service::FINALITY_DEPTH;
1211
use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi};
1312
use futures::TryStreamExt;
1413
use tokio::{process::Command, sync::OnceCell, time::sleep};
@@ -22,6 +21,8 @@ use super::{
2221
};
2322
use crate::node::NodeKind;
2423

24+
pub const FINALITY_DEPTH: u64 = 8;
25+
2526
pub struct BitcoinNode {
2627
spawn_output: SpawnOutput,
2728
pub config: BitcoinConfig,

Diff for: src/citrea_config/bitcoin.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Runtime configuration for the DA service
4+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
5+
pub struct BitcoinServiceConfig {
6+
/// The URL of the Bitcoin node to connect to
7+
pub node_url: String,
8+
pub node_username: String,
9+
pub node_password: String,
10+
11+
// network of the bitcoin node
12+
pub network: bitcoin::Network,
13+
14+
// da private key of the sequencer
15+
pub da_private_key: Option<String>,
16+
17+
// absolute path to the directory where the txs will be written to
18+
pub tx_backup_dir: String,
19+
}

Diff for: src/citrea_config/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Config imported as is from `citrea` repository `node-config` directory.
2+
// This is done in order not to have cyclical dependencies with `citrea`.
3+
// Should ideally be automatically kept in sync somehow but manually copied here for the time being.
4+
// Configs are stable and not expected to change much.
5+
6+
pub(crate) mod bitcoin;
7+
pub(crate) mod prover;
8+
pub(crate) mod rollup;
9+
pub(crate) mod sequencer;
10+
11+
#[cfg(test)]
12+
/// Reads toml file as a specific type.
13+
pub fn from_toml_path<P: AsRef<std::path::Path>, R: serde::de::DeserializeOwned>(
14+
path: P,
15+
) -> anyhow::Result<R> {
16+
use std::{fs::File, io::Read};
17+
18+
let mut contents = String::new();
19+
{
20+
let mut file = File::open(path)?;
21+
file.read_to_string(&mut contents)?;
22+
}
23+
log::debug!("Config file size: {} bytes", contents.len());
24+
log::trace!("Config file contents: {}", &contents);
25+
26+
let result: R = toml::from_str(&contents)?;
27+
28+
Ok(result)
29+
}

Diff for: src/citrea_config/prover.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// The possible configurations of the prover.
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
5+
#[serde(rename_all = "lowercase")]
6+
pub enum ProverGuestRunConfig {
7+
/// Skip proving.
8+
Skip,
9+
/// Run the rollup verification logic inside the current process.
10+
Simulate,
11+
/// Run the rollup verifier in a zkVM executor.
12+
Execute,
13+
/// Run the rollup verifier and create a SNARK of execution.
14+
Prove,
15+
}
16+
17+
impl<'de> Deserialize<'de> for ProverGuestRunConfig {
18+
fn deserialize<D>(deserializer: D) -> Result<ProverGuestRunConfig, D::Error>
19+
where
20+
D: serde::Deserializer<'de>,
21+
{
22+
let s = String::deserialize(deserializer)?;
23+
match s.as_str() {
24+
"skip" => Ok(ProverGuestRunConfig::Skip),
25+
"simulate" => Ok(ProverGuestRunConfig::Simulate),
26+
"execute" => Ok(ProverGuestRunConfig::Execute),
27+
"prove" => Ok(ProverGuestRunConfig::Prove),
28+
_ => Err(serde::de::Error::custom("invalid prover guest run config")),
29+
}
30+
}
31+
}
32+
33+
/// Prover configuration
34+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
35+
pub struct ProverConfig {
36+
/// Prover run mode
37+
pub proving_mode: ProverGuestRunConfig,
38+
/// Average number of commitments to prove
39+
pub proof_sampling_number: usize,
40+
/// If true prover will try to recover ongoing proving sessions
41+
pub enable_recovery: bool,
42+
}
43+
44+
impl Default for ProverConfig {
45+
fn default() -> Self {
46+
Self {
47+
proving_mode: ProverGuestRunConfig::Execute,
48+
proof_sampling_number: 0,
49+
enable_recovery: true,
50+
}
51+
}
52+
}
53+
54+
#[cfg(test)]
55+
mod tests {
56+
use std::io::Write;
57+
58+
use serde::de::DeserializeOwned;
59+
use std::fs::File;
60+
use std::io::Read;
61+
use std::path::Path;
62+
use tempfile::NamedTempFile;
63+
64+
use super::*;
65+
66+
/// Reads toml file as a specific type.
67+
pub fn from_toml_path<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> anyhow::Result<R> {
68+
let mut contents = String::new();
69+
{
70+
let mut file = File::open(path)?;
71+
file.read_to_string(&mut contents)?;
72+
}
73+
let result: R = toml::from_str(&contents)?;
74+
75+
Ok(result)
76+
}
77+
78+
fn create_config_from(content: &str) -> NamedTempFile {
79+
let mut config_file = NamedTempFile::new().unwrap();
80+
config_file.write_all(content.as_bytes()).unwrap();
81+
config_file
82+
}
83+
84+
#[test]
85+
fn test_correct_prover_config() {
86+
let config = r#"
87+
proving_mode = "skip"
88+
proof_sampling_number = 500
89+
enable_recovery = true
90+
"#;
91+
92+
let config_file = create_config_from(config);
93+
94+
let config: ProverConfig = from_toml_path(config_file.path()).unwrap();
95+
let expected = ProverConfig {
96+
proving_mode: ProverGuestRunConfig::Skip,
97+
proof_sampling_number: 500,
98+
enable_recovery: true,
99+
};
100+
assert_eq!(config, expected);
101+
}
102+
}

Diff for: src/citrea_config/rollup.rs

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
use std::path::PathBuf;
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
/// Runner configuration.
6+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
7+
pub struct RunnerConfig {
8+
/// Sequencer client configuration.
9+
pub sequencer_client_url: String,
10+
/// Saves sequencer soft confirmations if set to true
11+
pub include_tx_body: bool,
12+
/// Only true for tests
13+
pub accept_public_input_as_proven: Option<bool>,
14+
/// Number of blocks to request during sync
15+
#[serde(default = "default_sync_blocks_count")]
16+
pub sync_blocks_count: u64,
17+
}
18+
19+
/// RPC configuration.
20+
#[derive(Debug, Clone, PartialEq, Deserialize, Default, Serialize)]
21+
pub struct RpcConfig {
22+
/// RPC host.
23+
pub bind_host: String,
24+
/// RPC port.
25+
pub bind_port: u16,
26+
/// Maximum number of concurrent requests.
27+
/// if not set defaults to 100.
28+
#[serde(default = "default_max_connections")]
29+
pub max_connections: u32,
30+
/// Max request body request
31+
#[serde(default = "default_max_request_body_size")]
32+
pub max_request_body_size: u32,
33+
/// Max response body request
34+
#[serde(default = "default_max_response_body_size")]
35+
pub max_response_body_size: u32,
36+
/// Maximum number of batch requests
37+
#[serde(default = "default_batch_requests_limit")]
38+
pub batch_requests_limit: u32,
39+
/// Disable subscription RPCs
40+
#[serde(default = "default_enable_subscriptions")]
41+
pub enable_subscriptions: bool,
42+
/// Maximum number of subscription connections
43+
#[serde(default = "default_max_subscriptions_per_connection")]
44+
pub max_subscriptions_per_connection: u32,
45+
}
46+
47+
#[inline]
48+
const fn default_max_connections() -> u32 {
49+
100
50+
}
51+
52+
#[inline]
53+
const fn default_max_request_body_size() -> u32 {
54+
10 * 1024 * 1024
55+
}
56+
57+
#[inline]
58+
const fn default_max_response_body_size() -> u32 {
59+
10 * 1024 * 1024
60+
}
61+
62+
#[inline]
63+
const fn default_batch_requests_limit() -> u32 {
64+
50
65+
}
66+
67+
#[inline]
68+
const fn default_sync_blocks_count() -> u64 {
69+
10
70+
}
71+
72+
#[inline]
73+
const fn default_enable_subscriptions() -> bool {
74+
true
75+
}
76+
77+
#[inline]
78+
const fn default_max_subscriptions_per_connection() -> u32 {
79+
100
80+
}
81+
82+
/// Simple storage configuration
83+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
84+
pub struct StorageConfig {
85+
/// Path that can be utilized by concrete rollup implementation
86+
pub path: PathBuf,
87+
/// File descriptor limit for RocksDB
88+
pub db_max_open_files: Option<i32>,
89+
}
90+
91+
/// Important public keys for the rollup
92+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
93+
pub struct RollupPublicKeys {
94+
/// Soft confirmation signing public key of the Sequencer
95+
#[serde(with = "hex::serde")]
96+
pub sequencer_public_key: Vec<u8>,
97+
/// DA Signing Public Key of the Sequencer
98+
/// serialized as hex
99+
#[serde(with = "hex::serde")]
100+
pub sequencer_da_pub_key: Vec<u8>,
101+
/// DA Signing Public Key of the Prover
102+
/// serialized as hex
103+
#[serde(with = "hex::serde")]
104+
pub prover_da_pub_key: Vec<u8>,
105+
}
106+
107+
/// Rollup Configuration
108+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
109+
pub struct FullNodeConfig<BitcoinServiceConfig> {
110+
/// RPC configuration
111+
pub rpc: RpcConfig,
112+
/// Currently rollup config runner only supports storage path parameter
113+
pub storage: StorageConfig,
114+
/// Runner own configuration.
115+
pub runner: Option<RunnerConfig>, // optional bc sequencer doesn't need it
116+
/// Data Availability service configuration.
117+
pub da: BitcoinServiceConfig,
118+
/// Important pubkeys
119+
pub public_keys: RollupPublicKeys,
120+
}

0 commit comments

Comments
 (0)