Skip to content

Commit

Permalink
config: Seperation of bridge backend config and test config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Oct 7, 2024
1 parent 15493d4 commit 084fca6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 78 deletions.
38 changes: 1 addition & 37 deletions src/bridge_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -153,7 +152,7 @@ impl NodeT for BridgeBackendNode {
}

fn config(&self) -> &<Self as NodeT>::Config {
todo!()
&self.config
}
}

Expand Down Expand Up @@ -203,38 +202,3 @@ impl LogProvider for BridgeBackendNode {
todo!()
}
}

pub struct BridgeBackendNodeCluster {
inner: Vec<BridgeBackendNode>,
}

impl BridgeBackendNodeCluster {
pub async fn new(ctx: &TestContext) -> Result<Self> {
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)
}
}
80 changes: 43 additions & 37 deletions src/config/bridge_backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};

/// Real config values for bridge backend itself.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -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<String>,
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"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/config/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{
pub struct TestConfig {
pub test_case: TestCaseConfig,
pub bitcoin: Vec<BitcoinConfig>,
pub bridge_backend: Vec<BridgeBackendConfig>,
pub bridge_backend: BridgeBackendConfig,
pub sequencer: FullSequencerConfig,
pub prover: FullProverConfig,
pub full_node: FullFullNodeConfig,
Expand Down
2 changes: 1 addition & 1 deletion tests/bridge_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
};

Expand Down

0 comments on commit 084fca6

Please sign in to comment.