Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ key_path = "keys.example.json"

[[modules]]
id = "DA_COMMIT"
path = "target/debug/da_commit"
sleep_secs = 5
docker_image="da_commit"

@David-Petrov David-Petrov Jun 26, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the example image that must be available in the local registry before starting commit-boost.
You can find the example source code in this repo.

NOTE: Whilst we're still in development, you will have to modify the Cargo.toml of the example module to point to a correct source for the cb-... dependencies.

sleep_secs = 5
2 changes: 2 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ eyre.workspace = true

tree_hash.workspace = true
tree_hash_derive.workspace = true

bollard = "0.16.1"
38 changes: 26 additions & 12 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,38 @@ impl Args {
Command::Start { config: config_path } => {
let config = CommitBoostConfig::from_file(&config_path);

// Initialize Docker client
let docker = bollard::Docker::connect_with_local_defaults().expect("Failed to connect to Docker");

@David-Petrov David-Petrov Jun 26, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we currently expect that CB and the docker engine run on the same machine.

However, the way we connect to the docker daemon is modifiable if more complex needs arise: ref.


if let Some(modules) = config.modules {
let signer_config = config.signer.expect("missing signer config with modules");

// this mocks the commit boost client starting containers, processes etc
let mut child_handles = Vec::with_capacity(modules.len());
// start signing server
tokio::spawn(SigningService::run(config.chain, signer_config));

for module in modules {
let child = std::process::Command::new(module.path)
.env(MODULE_ID_ENV, module.id)
.env(CONFIG_PATH_ENV, &config_path)
.spawn()
.expect("failed to start process");
let config = bollard::container::Config {
image: Some(module.docker_image.clone()),
host_config: Some(bollard::secret::HostConfig {
binds: {
let full_config_path = std::fs::canonicalize(&config_path).unwrap().to_string_lossy().to_string();
Some(vec![format!("{}:{}", full_config_path, "/config.toml")])
},
network_mode: Some(String::from("host")), // Use the host network
..Default::default()
}),
env: Some(vec![
format!("{}={}", MODULE_ID_ENV, module.id),
format!("{}={}", CONFIG_PATH_ENV, "/config.toml"),
]),
..Default::default()
};

child_handles.push(child);
}
let container = docker.create_container::<&str, String>(None, config).await?;
let container_id = container.id;
docker.start_container::<String>(&container_id, None).await?;

// start signing server
tokio::spawn(SigningService::run(config.chain, signer_config));
println!("Started container: {} from image {}", container_id, module.docker_image);
}
}

// start pbs server
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const fn default_u256() -> U256 {
#[derive(Debug, Deserialize, Serialize)]
pub struct ModuleConfig<T = ()> {
pub id: String,
pub path: String,
pub docker_image: String,
#[serde(flatten)]
pub extra: T,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
#[async_trait]
pub trait BuilderApi<S: BuilderApiState>: 'static {
/// Use to extend the BuilderApi
fn routes() -> Option<Router<BuilderState<S>>> {
fn extra_routes() -> Option<Router<BuilderState<S>>> {
None
}

Expand Down
2 changes: 1 addition & 1 deletion crates/pbs/src/routes/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn create_app_router<S: BuilderApiState, T: BuilderApi<S>>(state: BuilderSta

let builder_api = Router::new().nest(BULDER_API_PATH, builder_routes);

let app = if let Some(extra_routes) = T::routes() {
let app = if let Some(extra_routes) = T::extra_routes() {
builder_api.merge(extra_routes)
} else {
builder_api
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl BuilderApi<StatusCounter> for MyBuilderApi {
Ok(())
}

fn routes() -> Option<Router<BuilderState<StatusCounter>>> {
fn extra_routes() -> Option<Router<BuilderState<StatusCounter>>> {
let router = Router::new().route("/custom/stats", get(handle_stats));
Some(router)
}
Expand Down