From 7634d674c70e0c84e5155ca70aa948c1d66ac8c9 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:00:24 +0100 Subject: [PATCH] Use citrea-config --- Cargo.toml | 1 + src/citrea_config/batch_prover.rs | 103 ---------- src/citrea_config/bitcoin.rs | 38 ---- src/citrea_config/light_client_prover.rs | 80 -------- src/citrea_config/mod.rs | 30 --- src/citrea_config/rollup.rs | 228 ----------------------- src/citrea_config/sequencer.rs | 129 ------------- src/config/bitcoin.rs | 16 ++ src/config/mod.rs | 8 +- src/lib.rs | 1 - 10 files changed, 18 insertions(+), 616 deletions(-) delete mode 100644 src/citrea_config/batch_prover.rs delete mode 100644 src/citrea_config/bitcoin.rs delete mode 100644 src/citrea_config/light_client_prover.rs delete mode 100644 src/citrea_config/mod.rs delete mode 100644 src/citrea_config/rollup.rs delete mode 100644 src/citrea_config/sequencer.rs diff --git a/Cargo.toml b/Cargo.toml index 80f2b3f..8a2b7a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ tokio = { version = "1.39", features = ["full"] } toml = "0.8.0" tracing = { version = "0.1.40", default-features = false } tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] } +citrea-config = { git = "https://github.com/chainwayxyz/citrea", branch = "refactor-citrea-e2e", features = ["testing"] } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "5ce1bed" } diff --git a/src/citrea_config/batch_prover.rs b/src/citrea_config/batch_prover.rs deleted file mode 100644 index c72a86c..0000000 --- a/src/citrea_config/batch_prover.rs +++ /dev/null @@ -1,103 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// The possible configurations of the prover. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] -#[serde(rename_all = "lowercase")] -pub enum ProverGuestRunConfig { - /// Skip proving. - Skip, - /// Run the rollup verification logic inside the current process. - Simulate, - /// Run the rollup verifier in a zkVM executor. - Execute, - /// Run the rollup verifier and create a SNARK of execution. - Prove, -} - -impl<'de> Deserialize<'de> for ProverGuestRunConfig { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - let s = String::deserialize(deserializer)?; - match s.as_str() { - "skip" => Ok(ProverGuestRunConfig::Skip), - "simulate" => Ok(ProverGuestRunConfig::Simulate), - "execute" => Ok(ProverGuestRunConfig::Execute), - "prove" => Ok(ProverGuestRunConfig::Prove), - _ => Err(serde::de::Error::custom("invalid prover guest run config")), - } - } -} - -/// Prover configuration -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct BatchProverConfig { - /// Prover run mode - pub proving_mode: ProverGuestRunConfig, - /// Average number of commitments to prove - pub proof_sampling_number: usize, - /// If true prover will try to recover ongoing proving sessions - pub enable_recovery: bool, -} - -impl Default for BatchProverConfig { - fn default() -> Self { - Self { - proving_mode: ProverGuestRunConfig::Execute, - proof_sampling_number: 0, - enable_recovery: true, - } - } -} - -#[cfg(test)] -mod tests { - use std::{ - fs::File, - io::{Read, Write}, - path::Path, - }; - - use serde::de::DeserializeOwned; - use tempfile::NamedTempFile; - - use super::*; - - /// Reads toml file as a specific type. - pub fn from_toml_path, R: DeserializeOwned>(path: P) -> anyhow::Result { - let mut contents = String::new(); - { - let mut file = File::open(path)?; - file.read_to_string(&mut contents)?; - } - let result: R = toml::from_str(&contents)?; - - Ok(result) - } - - fn create_config_from(content: &str) -> NamedTempFile { - let mut config_file = NamedTempFile::new().unwrap(); - config_file.write_all(content.as_bytes()).unwrap(); - config_file - } - - #[test] - fn test_correct_prover_config() { - let config = r#" - proving_mode = "skip" - proof_sampling_number = 500 - enable_recovery = true - "#; - - let config_file = create_config_from(config); - - let config: BatchProverConfig = from_toml_path(config_file.path()).unwrap(); - let expected = BatchProverConfig { - proving_mode: ProverGuestRunConfig::Skip, - proof_sampling_number: 500, - enable_recovery: true, - }; - assert_eq!(config, expected); - } -} diff --git a/src/citrea_config/bitcoin.rs b/src/citrea_config/bitcoin.rs deleted file mode 100644 index e877a96..0000000 --- a/src/citrea_config/bitcoin.rs +++ /dev/null @@ -1,38 +0,0 @@ -use serde::{Deserialize, Serialize}; - -impl Default for MonitoringConfig { - fn default() -> Self { - Self { - check_interval: 1, - history_limit: 100, - max_history_size: 1_000_000, // Default to 1mb for test - } - } -} - -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct MonitoringConfig { - pub check_interval: u64, - pub history_limit: usize, - pub max_history_size: usize, -} - -/// Runtime configuration for the DA service -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct BitcoinServiceConfig { - /// The URL of the Bitcoin node to connect to - pub node_url: String, - pub node_username: String, - pub node_password: String, - - // network of the bitcoin node - pub network: bitcoin::Network, - - // da private key of the sequencer - pub da_private_key: Option, - - // absolute path to the directory where the txs will be written to - pub tx_backup_dir: String, - - pub monitoring: Option, -} diff --git a/src/citrea_config/light_client_prover.rs b/src/citrea_config/light_client_prover.rs deleted file mode 100644 index 3ec134e..0000000 --- a/src/citrea_config/light_client_prover.rs +++ /dev/null @@ -1,80 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::batch_prover::ProverGuestRunConfig; - -/// Light client prover configuration -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct LightClientProverConfig { - /// Prover run mode - pub proving_mode: ProverGuestRunConfig, - /// Average number of commitments to prove - pub proof_sampling_number: usize, - /// If true prover will try to recover ongoing proving sessions - pub enable_recovery: bool, - /// The starting DA block to sync from - pub initial_da_height: u64, -} - -impl Default for LightClientProverConfig { - fn default() -> Self { - Self { - proving_mode: ProverGuestRunConfig::Execute, - proof_sampling_number: 0, - enable_recovery: true, - initial_da_height: 1, - } - } -} - -#[cfg(test)] -mod tests { - use std::{ - fs::File, - io::{Read, Write}, - path::Path, - }; - - use serde::de::DeserializeOwned; - use tempfile::NamedTempFile; - - use super::*; - - /// Reads toml file as a specific type. - pub fn from_toml_path, R: DeserializeOwned>(path: P) -> anyhow::Result { - let mut contents = String::new(); - { - let mut file = File::open(path)?; - file.read_to_string(&mut contents)?; - } - let result: R = toml::from_str(&contents)?; - - Ok(result) - } - - fn create_config_from(content: &str) -> NamedTempFile { - let mut config_file = NamedTempFile::new().unwrap(); - config_file.write_all(content.as_bytes()).unwrap(); - config_file - } - - #[test] - fn test_correct_prover_config() { - let config = r#" - proving_mode = "skip" - proof_sampling_number = 500 - enable_recovery = true - initial_da_height = 15 - "#; - - let config_file = create_config_from(config); - - let config: LightClientProverConfig = from_toml_path(config_file.path()).unwrap(); - let expected = LightClientProverConfig { - proving_mode: ProverGuestRunConfig::Skip, - proof_sampling_number: 500, - enable_recovery: true, - initial_da_height: 15, - }; - assert_eq!(config, expected); - } -} diff --git a/src/citrea_config/mod.rs b/src/citrea_config/mod.rs deleted file mode 100644 index 687682f..0000000 --- a/src/citrea_config/mod.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Config imported as is from `citrea` repository `node-config` directory. -// This is done in order not to have cyclical dependencies with `citrea`. -// Should ideally be automatically kept in sync somehow but manually copied here for the time being. -// Configs are stable and not expected to change much. - -pub(crate) mod batch_prover; -pub(crate) mod bitcoin; -pub(crate) mod light_client_prover; -pub(crate) mod rollup; -pub(crate) mod sequencer; - -#[cfg(test)] -/// Reads toml file as a specific type. -pub fn from_toml_path, R: serde::de::DeserializeOwned>( - path: P, -) -> anyhow::Result { - use std::{fs::File, io::Read}; - - let mut contents = String::new(); - { - let mut file = File::open(path)?; - file.read_to_string(&mut contents)?; - } - tracing::debug!("Config file size: {} bytes", contents.len()); - tracing::trace!("Config file contents: {}", &contents); - - let result: R = toml::from_str(&contents)?; - - Ok(result) -} diff --git a/src/citrea_config/rollup.rs b/src/citrea_config/rollup.rs deleted file mode 100644 index 0048fbd..0000000 --- a/src/citrea_config/rollup.rs +++ /dev/null @@ -1,228 +0,0 @@ -use std::path::PathBuf; - -use serde::{Deserialize, Serialize}; -use tempfile::TempDir; - -use super::bitcoin::MonitoringConfig; -use crate::config::{BitcoinConfig, BitcoinServiceConfig}; - -/// Runner configuration. -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct RunnerConfig { - /// Sequencer client configuration. - pub sequencer_client_url: String, - /// Saves sequencer soft confirmations if set to true - pub include_tx_body: bool, - /// Number of blocks to request during sync - #[serde(default = "default_sync_blocks_count")] - pub sync_blocks_count: u64, - /// Configurations for pruning - pub pruning_config: Option, -} - -/// RPC configuration. -#[derive(Debug, Clone, PartialEq, Deserialize, Default, Serialize)] -pub struct RpcConfig { - /// RPC host. - pub bind_host: String, - /// RPC port. - pub bind_port: u16, - /// Maximum number of concurrent requests. - /// if not set defaults to 100. - #[serde(default = "default_max_connections")] - pub max_connections: u32, - /// Max request body request - #[serde(default = "default_max_request_body_size")] - pub max_request_body_size: u32, - /// Max response body request - #[serde(default = "default_max_response_body_size")] - pub max_response_body_size: u32, - /// Maximum number of batch requests - #[serde(default = "default_batch_requests_limit")] - pub batch_requests_limit: u32, - /// Disable subscription RPCs - #[serde(default = "default_enable_subscriptions")] - pub enable_subscriptions: bool, - /// Maximum number of subscription connections - #[serde(default = "default_max_subscriptions_per_connection")] - pub max_subscriptions_per_connection: u32, -} - -#[inline] -const fn default_max_connections() -> u32 { - 100 -} - -#[inline] -const fn default_max_request_body_size() -> u32 { - 10 * 1024 * 1024 -} - -#[inline] -const fn default_max_response_body_size() -> u32 { - 10 * 1024 * 1024 -} - -#[inline] -const fn default_batch_requests_limit() -> u32 { - 50 -} - -#[inline] -const fn default_sync_blocks_count() -> u64 { - 10 -} - -#[inline] -const fn default_enable_subscriptions() -> bool { - true -} - -#[inline] -const fn default_max_subscriptions_per_connection() -> u32 { - 100 -} - -/// Simple storage configuration -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct StorageConfig { - /// Path that can be utilized by concrete rollup implementation - pub path: PathBuf, - /// File descriptor limit for `RocksDB` - pub db_max_open_files: Option, -} - -/// Important public keys for the rollup -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct RollupPublicKeys { - /// Soft confirmation signing public key of the Sequencer - #[serde(with = "hex::serde")] - pub sequencer_public_key: Vec, - /// DA Signing Public Key of the Sequencer - /// serialized as hex - #[serde(with = "hex::serde")] - pub sequencer_da_pub_key: Vec, - /// DA Signing Public Key of the Prover - /// serialized as hex - #[serde(with = "hex::serde")] - pub prover_da_pub_key: Vec, -} - -/// Rollup Configuration -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct FullNodeConfig { - /// RPC configuration - pub rpc: RpcConfig, - /// Currently rollup config runner only supports storage path parameter - pub storage: StorageConfig, - /// Runner own configuration. - pub runner: Option, // optional bc sequencer doesn't need it - /// Data Availability service configuration. - pub da: BitcoinServiceConfig, - /// Important pubkeys - pub public_keys: RollupPublicKeys, - /// Telemetry config - pub telemetry: TelemetryConfig, -} - -impl Default for FullNodeConfig { - fn default() -> Self { - Self { - rpc: RpcConfig { - bind_host: "127.0.0.1".into(), - bind_port: 0, - max_connections: 100, - max_request_body_size: 10 * 1024 * 1024, - max_response_body_size: 10 * 1024 * 1024, - batch_requests_limit: 50, - enable_subscriptions: true, - max_subscriptions_per_connection: 100, - }, - storage: StorageConfig { - path: TempDir::new() - .expect("Failed to create temporary directory") - .into_path(), - db_max_open_files: None, - }, - runner: None, - da: BitcoinServiceConfig { - node_url: String::new(), - node_username: String::from("user"), - node_password: String::from("password"), - network: bitcoin::Network::Regtest, - da_private_key: None, - tx_backup_dir: TempDir::new() - .expect("Failed to create temporary directory") - .into_path() - .display() - .to_string(), - monitoring: Some(MonitoringConfig::default()), - }, - public_keys: RollupPublicKeys { - sequencer_public_key: vec![ - 32, 64, 64, 227, 100, 193, 15, 43, 236, 156, 31, 229, 0, 161, 205, 76, 36, 124, - 137, 214, 80, 160, 30, 215, 232, 44, 171, 168, 103, 135, 124, 33, - ], - // private key [4, 95, 252, 129, 163, 193, 253, 179, 175, 19, 89, 219, 242, 209, 20, 176, 179, 239, 191, 127, 41, 204, 156, 93, 160, 18, 103, 170, 57, 210, 199, 141] - // Private Key (WIF): KwNDSCvKqZqFWLWN1cUzvMiJQ7ck6ZKqR6XBqVKyftPZtvmbE6YD - sequencer_da_pub_key: vec![ - 3, 136, 195, 18, 11, 187, 25, 37, 38, 109, 184, 237, 247, 208, 131, 219, 162, - 70, 35, 174, 234, 47, 239, 247, 60, 51, 174, 242, 247, 112, 186, 222, 30, - ], - // private key [117, 186, 249, 100, 208, 116, 89, 70, 0, 54, 110, 91, 17, 26, 29, 168, 248, 107, 46, 254, 45, 34, 218, 81, 200, 216, 33, 38, 160, 252, 172, 114] - // Private Key (WIF): L1AZdJXzDGGENBBPZGSL7dKJnwn5xSKqzszgK6CDwiBGThYQEVTo - prover_da_pub_key: vec![ - 2, 138, 232, 157, 214, 46, 7, 210, 235, 33, 105, 239, 71, 169, 105, 233, 239, - 84, 172, 112, 13, 54, 9, 206, 106, 138, 251, 218, 15, 28, 137, 112, 127, - ], - }, - telemetry: Default::default(), - } - } -} - -/// Telemetry configuration. -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct TelemetryConfig { - /// Server host. - pub bind_host: String, - /// Server port. - pub bind_port: u16, -} - -impl Default for TelemetryConfig { - fn default() -> Self { - Self { - bind_host: "0.0.0.0".to_owned(), - bind_port: 0, - } - } -} - -impl From for BitcoinServiceConfig { - fn from(v: BitcoinConfig) -> Self { - let ip = v.docker_host.unwrap_or(String::from("127.0.0.1")); - Self { - node_url: format!("{}:{}", ip, v.rpc_port), - node_username: v.rpc_user, - node_password: v.rpc_password, - network: v.network, - da_private_key: None, - tx_backup_dir: String::new(), - monitoring: Some(Default::default()), - } - } -} - -/// A configuration type to define the behaviour of the pruner. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct PruningConfig { - /// Defines the number of blocks from the tip of the chain to remove. - pub distance: u64, -} - -impl Default for PruningConfig { - fn default() -> Self { - Self { distance: 256 } - } -} diff --git a/src/citrea_config/sequencer.rs b/src/citrea_config/sequencer.rs deleted file mode 100644 index 412527e..0000000 --- a/src/citrea_config/sequencer.rs +++ /dev/null @@ -1,129 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// Rollup Configuration -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct SequencerConfig { - /// Private key of the sequencer - pub private_key: String, - /// Min. soft confirmaitons for sequencer to commit - pub min_soft_confirmations_per_commitment: u64, - /// Whether or not the sequencer is running in test mode - pub test_mode: bool, - /// Limit for the number of deposit transactions to be included in the block - pub deposit_mempool_fetch_limit: usize, - /// Sequencer specific mempool config - pub mempool_conf: SequencerMempoolConfig, - /// DA layer update loop interval in ms - pub da_update_interval_ms: u64, - /// Block production interval in ms - pub block_production_interval_ms: u64, -} - -impl Default for SequencerConfig { - fn default() -> Self { - SequencerConfig { - private_key: "1212121212121212121212121212121212121212121212121212121212121212" - .to_string(), - min_soft_confirmations_per_commitment: 4, - test_mode: true, - deposit_mempool_fetch_limit: 10, - block_production_interval_ms: 100, - da_update_interval_ms: 100, - mempool_conf: SequencerMempoolConfig::default(), - } - } -} - -/// Mempool Config for the sequencer -/// Read: https://github.com/ledgerwatch/erigon/wiki/Transaction-Pool-Design -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct SequencerMempoolConfig { - /// Max number of transactions in the pending sub-pool - pub pending_tx_limit: u64, - /// Max megabytes of transactions in the pending sub-pool - pub pending_tx_size: u64, - /// Max number of transactions in the queued sub-pool - pub queue_tx_limit: u64, - /// Max megabytes of transactions in the queued sub-pool - pub queue_tx_size: u64, - /// Max number of transactions in the base-fee sub-pool - pub base_fee_tx_limit: u64, - /// Max megabytes of transactions in the base-fee sub-pool - pub base_fee_tx_size: u64, - /// Max number of executable transaction slots guaranteed per account - pub max_account_slots: u64, -} - -impl Default for SequencerMempoolConfig { - fn default() -> Self { - Self { - pending_tx_limit: 100_000, - pending_tx_size: 200, - queue_tx_limit: 100_000, - queue_tx_size: 200, - base_fee_tx_limit: 100_000, - base_fee_tx_size: 200, - max_account_slots: 16, - } - } -} - -#[cfg(test)] -mod tests { - use std::io::Write; - - use tempfile::NamedTempFile; - - use super::*; - use crate::citrea_config::from_toml_path; - - fn create_config_from(content: &str) -> NamedTempFile { - let mut config_file = NamedTempFile::new().unwrap(); - config_file.write_all(content.as_bytes()).unwrap(); - config_file - } - - #[test] - fn test_correct_config_sequencer() { - let config = r#" - private_key = "1212121212121212121212121212121212121212121212121212121212121212" - min_soft_confirmations_per_commitment = 123 - test_mode = false - deposit_mempool_fetch_limit = 10 - da_update_interval_ms = 1000 - block_production_interval_ms = 1000 - [mempool_conf] - pending_tx_limit = 100000 - pending_tx_size = 200 - queue_tx_limit = 100000 - queue_tx_size = 200 - base_fee_tx_limit = 100000 - base_fee_tx_size = 200 - max_account_slots = 16 - "#; - - let config_file = create_config_from(config); - - let config: SequencerConfig = from_toml_path(config_file.path()).unwrap(); - - let expected = SequencerConfig { - private_key: "1212121212121212121212121212121212121212121212121212121212121212" - .to_string(), - min_soft_confirmations_per_commitment: 123, - test_mode: false, - deposit_mempool_fetch_limit: 10, - mempool_conf: SequencerMempoolConfig { - pending_tx_limit: 100000, - pending_tx_size: 200, - queue_tx_limit: 100000, - queue_tx_size: 200, - base_fee_tx_limit: 100000, - base_fee_tx_size: 200, - max_account_slots: 16, - }, - da_update_interval_ms: 1000, - block_production_interval_ms: 1000, - }; - assert_eq!(config, expected); - } -} diff --git a/src/config/bitcoin.rs b/src/config/bitcoin.rs index 5344362..6b04eba 100644 --- a/src/config/bitcoin.rs +++ b/src/config/bitcoin.rs @@ -1,10 +1,26 @@ use std::path::PathBuf; use bitcoin::Network; +use citrea_config::BitcoinServiceConfig; use tempfile::TempDir; use crate::{log_provider::LogPathProvider, node::NodeKind}; +impl From for BitcoinServiceConfig { + fn from(v: BitcoinConfig) -> Self { + let ip = v.docker_host.unwrap_or(String::from("127.0.0.1")); + Self { + node_url: format!("{}:{}", ip, v.rpc_port), + node_username: v.rpc_user, + node_password: v.rpc_password, + network: v.network, + da_private_key: None, + tx_backup_dir: String::new(), + monitoring: Some(Default::default()), + } + } +} + #[derive(Debug, Clone)] pub struct BitcoinConfig { pub p2p_port: u16, diff --git a/src/config/mod.rs b/src/config/mod.rs index 264788c..30236a4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -19,18 +19,12 @@ pub use test::TestConfig; pub use test_case::{TestCaseConfig, TestCaseDockerConfig, TestCaseEnv}; pub use utils::config_to_file; -pub use crate::citrea_config::{ - batch_prover::{BatchProverConfig, ProverGuestRunConfig}, - bitcoin::BitcoinServiceConfig, - light_client_prover::LightClientProverConfig, - rollup::{FullNodeConfig, RollupPublicKeys, RpcConfig, RunnerConfig, StorageConfig}, - sequencer::{SequencerConfig, SequencerMempoolConfig}, -}; use crate::{ log_provider::LogPathProvider, node::{Config, NodeKind}, Result, }; +pub use citrea_config::*; #[derive(Clone, Debug, Default)] pub enum DaLayer { diff --git a/src/lib.rs b/src/lib.rs index 0108d76..0cf65f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ pub mod batch_prover; pub mod bitcoin; -mod citrea_config; mod client; pub mod config; mod docker;