-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implement citrea configs and remove related dependencies
- Loading branch information
Showing
9 changed files
with
412 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// 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<String>, | ||
|
||
// absolute path to the directory where the txs will be written to | ||
pub tx_backup_dir: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 bitcoin; | ||
pub(crate) mod prover; | ||
pub(crate) mod rollup; | ||
pub(crate) mod sequencer; | ||
|
||
#[cfg(test)] | ||
/// Reads toml file as a specific type. | ||
pub fn from_toml_path<P: AsRef<std::path::Path>, R: serde::de::DeserializeOwned>( | ||
path: P, | ||
) -> anyhow::Result<R> { | ||
use std::{fs::File, io::Read}; | ||
|
||
let mut contents = String::new(); | ||
{ | ||
let mut file = File::open(path)?; | ||
file.read_to_string(&mut contents)?; | ||
} | ||
log::debug!("Config file size: {} bytes", contents.len()); | ||
log::trace!("Config file contents: {}", &contents); | ||
|
||
let result: R = toml::from_str(&contents)?; | ||
|
||
Ok(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
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<D>(deserializer: D) -> Result<ProverGuestRunConfig, D::Error> | ||
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 ProverConfig { | ||
/// 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 ProverConfig { | ||
fn default() -> Self { | ||
Self { | ||
proving_mode: ProverGuestRunConfig::Execute, | ||
proof_sampling_number: 0, | ||
enable_recovery: true, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::io::Write; | ||
|
||
use serde::de::DeserializeOwned; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::Path; | ||
use tempfile::NamedTempFile; | ||
|
||
use super::*; | ||
|
||
/// Reads toml file as a specific type. | ||
pub fn from_toml_path<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> anyhow::Result<R> { | ||
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: ProverConfig = from_toml_path(config_file.path()).unwrap(); | ||
let expected = ProverConfig { | ||
proving_mode: ProverGuestRunConfig::Skip, | ||
proof_sampling_number: 500, | ||
enable_recovery: true, | ||
}; | ||
assert_eq!(config, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use std::path::PathBuf; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// 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, | ||
/// Only true for tests | ||
pub accept_public_input_as_proven: Option<bool>, | ||
/// Number of blocks to request during sync | ||
#[serde(default = "default_sync_blocks_count")] | ||
pub sync_blocks_count: u64, | ||
} | ||
|
||
/// 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<i32>, | ||
} | ||
|
||
/// 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<u8>, | ||
/// DA Signing Public Key of the Sequencer | ||
/// serialized as hex | ||
#[serde(with = "hex::serde")] | ||
pub sequencer_da_pub_key: Vec<u8>, | ||
/// DA Signing Public Key of the Prover | ||
/// serialized as hex | ||
#[serde(with = "hex::serde")] | ||
pub prover_da_pub_key: Vec<u8>, | ||
} | ||
|
||
/// Rollup Configuration | ||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] | ||
pub struct FullNodeConfig<BitcoinServiceConfig> { | ||
/// RPC configuration | ||
pub rpc: RpcConfig, | ||
/// Currently rollup config runner only supports storage path parameter | ||
pub storage: StorageConfig, | ||
/// Runner own configuration. | ||
pub runner: Option<RunnerConfig>, // optional bc sequencer doesn't need it | ||
/// Data Availability service configuration. | ||
pub da: BitcoinServiceConfig, | ||
/// Important pubkeys | ||
pub public_keys: RollupPublicKeys, | ||
} |
Oops, something went wrong.