Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Jul 15, 2024
1 parent 4faf5ee commit f44d3b5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
4 changes: 3 additions & 1 deletion config/example-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ GlobalQueue = 1024
L2GasPriceSuggesterFactor = 0.5

[Layer1]
URL = "http://localhost:8545"
ChainID = 1337
NodeURL = "http://localhost:8545"
RollupManagerContract = "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
ForkIDChunkSize = 20000

[EthTxManager]
Expand Down
16 changes: 3 additions & 13 deletions crates/cdk-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
//! The agglayer is configured via its TOML configuration file, `agglayer.toml`
//! by default, which is deserialized into the [`Config`] struct.

use std::collections::HashMap;

use auth::deserialize_auth;
use outbound::OutboundConfig;
use serde::Deserialize;
use shutdown::ShutdownConfig;
use url::Url;

use self::{rpc::deserialize_rpc_map, telemetry::TelemetryConfig};

pub(crate) const DEFAULT_IP: std::net::Ipv4Addr = std::net::Ipv4Addr::new(0, 0, 0, 0);

Expand All @@ -37,10 +32,6 @@ pub use rpc::RpcConfig;
pub struct Config {
/// A map of Zkevm node RPC endpoints for each rollup.
///
/// The key is the rollup ID, and the value is the URL of the associated RPC
/// endpoint.
#[serde(rename = "FullNodeRPCs", deserialize_with = "deserialize_rpc_map")]
pub full_node_rpcs: HashMap<u32, Url>,
/// The log configuration.
#[serde(rename = "Log")]
pub log: Log,
Expand All @@ -56,10 +47,9 @@ pub struct Config {
/// The authentication configuration.
#[serde(alias = "EthTxManager", default, deserialize_with = "deserialize_auth")]
pub auth: AuthConfig,
/// Telemetry configuration.
#[serde(rename = "Telemetry")]
pub telemetry: TelemetryConfig,

// /// Telemetry configuration.
// #[serde(rename = "Telemetry")]
// pub telemetry: TelemetryConfig,
/// The Epoch configuration.
#[serde(rename = "Epoch", default = "Epoch::default")]
pub epoch: Epoch,
Expand Down
37 changes: 37 additions & 0 deletions crates/cdk/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::env;
use std::path::PathBuf;
use std::process::Command;

fn main() {
// Determine the directory where the build script is located
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let build_path = PathBuf::from(dir + "../../");

// Optionally, specify the directory where your Makefile is located
// For this example, it's assumed to be the same as the build script's directory
// If your Makefile is in a different directory, adjust `build_path` accordingly

// Call the make command
let output = Command::new("make")
.current_dir(build_path) // Set the current directory for the command
.output() // Execute the command and capture the output
.expect("Failed to execute make command");

// Check the output and react accordingly
if !output.status.success() {
// If the make command failed, print the error and exit
let error_message = String::from_utf8_lossy(&output.stderr);
panic!("Make command failed with error: {}", error_message);
}

// Optionally, print the output of the make command
println!(
"Make command output: {}",
String::from_utf8_lossy(&output.stdout)
);

// Here you can also add additional commands to inform Cargo about
// how to rerun the build script. For example, to rerun this script
// only when a specific file changes:
// println!("cargo:rerun-if-changed=path/to/file");
}
2 changes: 1 addition & 1 deletion crates/cdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct Cli {
pub(crate) enum Commands {
Run {
/// The path to the configuration file.
#[arg(long, short, value_hint = ValueHint::FilePath, default_value = "config/example-config.toml", env = "CONFIG_PATH")]
#[arg(long, short, value_hint = ValueHint::FilePath, default_value = "config/example-config.toml", env = "CDK_CONFIG_PATH")]
cfg: PathBuf,
},
}
20 changes: 20 additions & 0 deletions crates/cdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
use cdk_config::Config;
use clap::Parser;
use cli::Cli;
use execute::Execute;
use std::path::PathBuf;
use std::process::Command;
use std::sync::Arc;

mod cli;
mod logging;

const CDK_CLIENT_PATH: &str = "cdk-client";
const CDK_ERIGON_PATH: &str = "cdk-erigon";

fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();

Expand All @@ -32,6 +37,21 @@ pub fn run(cfg: PathBuf) -> anyhow::Result<()> {
// Load the configuration file
let config: Arc<Config> = Arc::new(toml::from_str(&std::fs::read_to_string(cfg)?)?);

// Run the node passing the parsed config values as flags
let mut command = Command::new(CDK_CLIENT_PATH);

let output = command.execute_output().unwrap();

if let Some(exit_code) = output.status.code() {
if exit_code == 0 {
println!("Ok.");
} else {
eprintln!("Failed.");
}
} else {
eprintln!("Interrupted!");
}

// Initialize the logger
logging::tracing(&config.log);

Expand Down

0 comments on commit f44d3b5

Please sign in to comment.