Skip to content

Commit

Permalink
Refactor Config trait (#65)
Browse files Browse the repository at this point in the history
* Remove Config trait

* Lint

* Use local_config when running local bitcoind node
  • Loading branch information
jfldde authored Jan 31, 2025
1 parent 8d7aa3d commit 4a6d30b
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 281 deletions.
33 changes: 0 additions & 33 deletions src/batch_prover.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl BitcoinNode {
}

fn spawn(config: &BitcoinConfig) -> Result<SpawnOutput> {
let args = config.args();
let args = config.local_args();
debug!("Running bitcoind with args : {args:?}");

info!(
Expand Down
4 changes: 2 additions & 2 deletions src/citrea_config/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct RollupPublicKeys {

/// Rollup Configuration
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct FullNodeConfig<BitcoinServiceConfig> {
pub struct RollupConfig {
/// RPC configuration
pub rpc: RpcConfig,
/// Currently rollup config runner only supports storage path parameter
Expand All @@ -125,7 +125,7 @@ pub struct FullNodeConfig<BitcoinServiceConfig> {
pub telemetry: TelemetryConfig,
}

impl Default for FullNodeConfig<BitcoinServiceConfig> {
impl Default for RollupConfig {
fn default() -> Self {
Self {
rpc: RpcConfig {
Expand Down
17 changes: 14 additions & 3 deletions src/config/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ impl BitcoinConfig {
"-regtest".to_string(),
format!("-datadir={}", self.data_dir.display()),
format!("-port={}", self.p2p_port),
format!("-bind=0.0.0.0:{}", self.p2p_port),
format!("-rpcport={}", self.rpc_port),
format!("-bind=0.0.0.0:{}", self.rpc_port),
format!("-rpcuser={}", self.rpc_user),
format!("-rpcpassword={}", self.rpc_password),
"-server".to_string(),
Expand All @@ -68,10 +66,23 @@ impl BitcoinConfig {
]
.concat()
}

/// Args to use whe running local bitcoind node
/// This prevents odd port conflict when assigning rpc/p2p ports
pub fn local_args(&self) -> Vec<String> {
[
self.base_args(),
vec![
format!("-bind=0.0.0.0:{}", self.p2p_port),
format!("-bind=0.0.0.0:{}", self.rpc_port),
],
]
.concat()
}
}

impl LogPathProvider for BitcoinConfig {
fn kind() -> NodeKind {
fn kind(&self) -> NodeKind {
NodeKind::Bitcoin
}

Expand Down
15 changes: 7 additions & 8 deletions src/config/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::{fmt::Debug, path::PathBuf};
use serde::Serialize;
use tracing::debug;

use super::{BitcoinConfig, FullL2NodeConfig, NodeKindMarker};
use super::{BitcoinConfig, FullL2NodeConfig};
use crate::{
log_provider::LogPathProvider,
node::{get_citrea_args, Config, NodeKind},
node::{get_citrea_args, NodeKind},
utils::get_genesis_path,
};

Expand Down Expand Up @@ -62,11 +61,10 @@ impl From<&BitcoinConfig> for DockerConfig {

impl<T> From<FullL2NodeConfig<T>> for DockerConfig
where
T: Clone + Serialize + Debug,
FullL2NodeConfig<T>: NodeKindMarker,
T: Clone + Debug + Serialize + Send + Sync,
{
fn from(config: FullL2NodeConfig<T>) -> Self {
let kind = FullL2NodeConfig::<T>::kind();
let kind = config.kind();

debug!("Converting config {config:?} for {kind} to docker config");

Expand All @@ -75,18 +73,19 @@ where
Self {
ports: vec![config.rollup.rpc.bind_port],
image: config
.base
.docker_image
.clone()
.unwrap_or(DEFAULT_CITREA_DOCKER_IMAGE.to_string()),
cmd: args,
log_path: config.dir.join("stdout.log"),
log_path: config.dir().join("stdout.log"),
volume: VolumeConfig {
name: format!("{kind}"),
target: format!("/{kind}/data"),
},
host_dir: Some(vec![
config.dir().to_owned().display().to_string(),
get_genesis_path(&config),
get_genesis_path(config.dir()),
]),
kind,
}
Expand Down
Loading

0 comments on commit 4a6d30b

Please sign in to comment.