From 084fca677daa70c3b95d2c15f3f47291963f62ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ceyhun=20=C5=9Een?= Date: Mon, 7 Oct 2024 15:22:55 +0300 Subject: [PATCH] config: Seperation of bridge backend config and test config. --- src/bridge_backend.rs | 38 +---------------- src/config/bridge_backend.rs | 80 +++++++++++++++++++----------------- src/config/docker.rs | 2 +- src/config/mod.rs | 2 +- src/config/test.rs | 2 +- tests/bridge_backend.rs | 2 +- 6 files changed, 48 insertions(+), 78 deletions(-) diff --git a/src/bridge_backend.rs b/src/bridge_backend.rs index 30994a0..1ed7b56 100644 --- a/src/bridge_backend.rs +++ b/src/bridge_backend.rs @@ -10,7 +10,6 @@ use tokio::time::sleep; use super::config::BridgeBackendConfig; use super::docker::DockerEnv; -use super::framework::TestContext; use super::Result; use crate::client::Client; use crate::node::NodeKind; @@ -153,7 +152,7 @@ impl NodeT for BridgeBackendNode { } fn config(&self) -> &::Config { - todo!() + &self.config } } @@ -203,38 +202,3 @@ impl LogProvider for BridgeBackendNode { todo!() } } - -pub struct BridgeBackendNodeCluster { - inner: Vec, -} - -impl BridgeBackendNodeCluster { - pub async fn new(ctx: &TestContext) -> Result { - let n_nodes = ctx.config.test_case.n_nodes; - let mut cluster = Self { - inner: Vec::with_capacity(n_nodes), - }; - for config in ctx.config.bridge_backend.iter() { - let node = BridgeBackendNode::new(config, Arc::clone(&ctx.docker)).await?; - cluster.inner.push(node) - } - - Ok(cluster) - } - - pub async fn stop_all(&mut self) -> Result<()> { - for node in &mut self.inner { - node.stop().await?; - } - Ok(()) - } - - pub fn get(&self, index: usize) -> Option<&BridgeBackendNode> { - self.inner.get(index) - } - - #[allow(unused)] - pub fn get_mut(&mut self, index: usize) -> Option<&mut BridgeBackendNode> { - self.inner.get_mut(index) - } -} diff --git a/src/config/bridge_backend.rs b/src/config/bridge_backend.rs index 224aa7d..f3ae67a 100644 --- a/src/config/bridge_backend.rs +++ b/src/config/bridge_backend.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, path::PathBuf}; /// Real config values for bridge backend itself. #[derive(Debug, Clone)] @@ -45,52 +45,58 @@ pub struct BridgeBackendClient { pub aggregator_url: String, } +impl Default for BridgeBackendClient { + fn default() -> Self { + Self { + host: "localhost".to_string(), + port: 8080, + + pghost: "localhost".to_string(), + pgport: 5432, + pguser: "citrea".to_string(), + pgpassword: "".to_string(), + pgdatabase: "citrea_bridge".to_string(), + + redis_url: "redis://localhost:6379".to_string(), + + user_takes_after: "c800".to_string(), + verifier_pks: "7c4803421956db53eed29ee45bddbe60d16e66560f918a94270ea5272b2b4e90".to_string(), + bridge_amount_btc: 1, + confirmation_threshold: 6, + + bitcoin_rest_endpoint: "".to_string(), + bitcoin_rest_auth_header: "".to_string(), + + citrea_rest_endpoint: "".to_string(), + bitcoin_lightclient_contract_address: "0x3100000000000000000000000000000000000001".to_string(), + bridge_contract_address: "".to_string(), + declare_withdraw_filler_private_key: "".to_string(), + + faucet_private_key: "".to_string(), + faucet_amount: "".to_string(), + faucet_amount_limit: "".to_string(), + faucet_count_limit: "".to_string(), + + operator_urls: "http://localhost:17007,http://localhost:17008,http://localhost:17009".to_string(), + verifier_urls: "http://localhost:17000,http://localhost:17001,http://localhost:17002,http://localhost:17003,http://localhost:17004,http://localhost:17005,http://localhost:17006".to_string(), + aggregator_url: "http://localhost:17010".to_string(), + } + } +} + #[derive(Debug, Clone)] pub struct BridgeBackendConfig { pub client: BridgeBackendClient, - pub docker_image: Option, + pub data_dir: PathBuf, } impl Default for BridgeBackendConfig { fn default() -> Self { Self { - client: BridgeBackendClient { - host: "localhost".to_string(), - port: 8080, - - pghost: "localhost".to_string(), - pgport: 5432, - pguser: "citrea".to_string(), - pgpassword: "".to_string(), - pgdatabase: "citrea_bridge".to_string(), - - redis_url: "redis://localhost:6379".to_string(), - - user_takes_after: "c800".to_string(), - verifier_pks: "7c4803421956db53eed29ee45bddbe60d16e66560f918a94270ea5272b2b4e90".to_string(), - bridge_amount_btc: 1, - confirmation_threshold: 6, - - bitcoin_rest_endpoint: "".to_string(), - bitcoin_rest_auth_header: "".to_string(), - - citrea_rest_endpoint: "".to_string(), - bitcoin_lightclient_contract_address: "0x3100000000000000000000000000000000000001".to_string(), - bridge_contract_address: "".to_string(), - declare_withdraw_filler_private_key: "".to_string(), - - faucet_private_key: "".to_string(), - faucet_amount: "".to_string(), - faucet_amount_limit: "".to_string(), - faucet_count_limit: "".to_string(), - - operator_urls: "http://localhost:17007,http://localhost:17008,http://localhost:17009".to_string(), - verifier_urls: "http://localhost:17000,http://localhost:17001,http://localhost:17002,http://localhost:17003,http://localhost:17004,http://localhost:17005,http://localhost:17006".to_string(), - aggregator_url: "http://localhost:17010".to_string(), - }, - + client: BridgeBackendClient::default(), docker_image: None, + data_dir: PathBuf::from("bridge_backend"), } } } diff --git a/src/config/docker.rs b/src/config/docker.rs index ca0e684..c2d8980 100644 --- a/src/config/docker.rs +++ b/src/config/docker.rs @@ -51,7 +51,7 @@ impl From<&BridgeBackendConfig> for DockerConfig { ports: vec![v.client.port.try_into().unwrap()], image: v.docker_image.clone().unwrap(), cmd: vec![], - log_path: PathBuf::new(), + log_path: v.data_dir.join("stdout"), volume: VolumeConfig { name: format!("bridge-backend"), target: "/home/bridge_backend/.bridge_backend".to_string(), diff --git a/src/config/mod.rs b/src/config/mod.rs index 7b76a24..2cf61ba 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -10,7 +10,7 @@ use std::path::PathBuf; pub use bitcoin::BitcoinConfig; pub use bitcoin_da::service::BitcoinServiceConfig; -pub use bridge_backend::BridgeBackendConfig; +pub use bridge_backend::{BridgeBackendClient, BridgeBackendConfig}; pub use citrea_sequencer::SequencerConfig; pub use docker::DockerConfig; pub use rollup::{default_rollup_config, RollupConfig}; diff --git a/src/config/test.rs b/src/config/test.rs index ee223a6..1f3073b 100644 --- a/src/config/test.rs +++ b/src/config/test.rs @@ -7,7 +7,7 @@ use super::{ pub struct TestConfig { pub test_case: TestCaseConfig, pub bitcoin: Vec, - pub bridge_backend: Vec, + pub bridge_backend: BridgeBackendConfig, pub sequencer: FullSequencerConfig, pub prover: FullProverConfig, pub full_node: FullFullNodeConfig, diff --git a/tests/bridge_backend.rs b/tests/bridge_backend.rs index 9434a9a..a3c77f1 100644 --- a/tests/bridge_backend.rs +++ b/tests/bridge_backend.rs @@ -23,7 +23,7 @@ impl TestCase for BasicBridgeBackendTest { let Some(_da) = f.bitcoin_nodes.get(0) else { bail!("bitcoind not running!") }; - let Some(_bridge_backend) = f.bridge_backend_nodes.get(0) else { + let Some(_bridge_backend) = &f.bridge_backend else { bail!("Bridge backend is not running!") };