Skip to content

Commit

Permalink
fix: genesis types
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Sep 19, 2024
1 parent 7c63de3 commit cd0847f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
8 changes: 4 additions & 4 deletions crates/cdk-config/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use url::Url;
#[derive(Deserialize, Debug, Clone)]
pub struct Aggregator {
#[serde(rename = "ChainID")]
pub chain_id: u64,
pub chain_id: String,
#[serde(rename = "Host")]
pub host: String,
#[serde(rename = "Port")]
pub port: u16,
pub port: String,
#[serde(rename = "RetryTime")]
pub retry_time: String,
#[serde(rename = "VerifyProofInterval")]
Expand Down Expand Up @@ -58,9 +58,9 @@ impl Default for Aggregator {
fn default() -> Self {
// Values are coming from https://github.com/0xPolygon/agglayer/blob/main/config/default.go#L11
Self {
chain_id: 1,
chain_id: "1".to_string(),
host: "localhost".to_string(),
port: 8545,
port: "8545".to_string(),
retry_time: "10s".to_string(),
verify_proof_interval: "1m".to_string(),
proof_state_polling_interval: "10s".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk-config/src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
pub struct L1 {
#[serde(rename = "L1ChainID")]
pub l1_chain_id: u64,
pub l1_chain_id: String,
#[serde(rename = "PolAddr")]
pub pol_addr: Address,
#[serde(rename = "ZkEVMAddr")]
Expand All @@ -21,7 +21,7 @@ impl Default for L1 {
fn default() -> Self {
// Values are coming from https://github.com/0xPolygon/agglayer/blob/main/config/default.go#L11
Self {
l1_chain_id: 1337,
l1_chain_id: "1337".to_string(),
pol_addr: "0x5b06837A43bdC3dD9F114558DAf4B26ed49842Ed"
.parse()
.unwrap(),
Expand Down
6 changes: 2 additions & 4 deletions crates/cdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub(crate) struct Cli {
long,
short,
value_hint = ValueHint::FilePath,
global = true,
required = true,
// global = true,
env = "CDK_CONFIG_PATH"
)]
pub(crate) config: PathBuf,
Expand All @@ -22,8 +21,7 @@ pub(crate) struct Cli {
long,
short = 'g',
value_hint = ValueHint::FilePath,
global = true,
required = true,
// global = true,
env = "CDK_GENESIS_PATH"
)]
pub(crate) chain: PathBuf,
Expand Down
21 changes: 10 additions & 11 deletions crates/cdk/src/config_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@ use std::fs;
use std::path::PathBuf;
use tempfile::{tempdir, TempDir};

pub fn render(chain_id: u64, _genesis_file: PathBuf) -> Result<TempDir, Error> {
pub fn render(chain_id: String, _genesis_file: PathBuf) -> Result<TempDir, Error> {
// Create a temporary directory
let tmp_dir = tempdir()?;

let res = crate::allocs_render::render_allocs("./tmp/cdk/genesis/genesis.json")?;
// Write the three files to disk
fs::write(
tmp_dir.path().join(format!(
"dynamic-{}-allocs.json",
chain_id.to_string().clone()
)),
tmp_dir
.path()
.join(format!("dynamic-{}-allocs.json", chain_id.clone())),
res.output,
)?;
fs::write(
tmp_dir
.path()
.join(format!("dynamic-{}-chainspec.json", chain_id.to_string())),
render_chainspec(chain_id),
.join(format!("dynamic-{}-chainspec.json", chain_id.clone())),
render_chainspec(chain_id.clone()),
)?;
fs::write(
tmp_dir
.path()
.join(format!("dynamic-{}-conf.json", chain_id.to_string())),
.join(format!("dynamic-{}-conf.json", chain_id.clone())),
render_conf(res.wrapper.root, 1000000000000000000),
)?;
fs::write(
tmp_dir
.path()
.join(format!("dynamic-{}.yaml", chain_id.to_string())),
.join(format!("dynamic-{}.yaml", chain_id.clone())),
render_yaml(chain_id),
)?;

Ok(tmp_dir)
}

fn render_chainspec(chain_id: u64) -> String {
fn render_chainspec(chain_id: String) -> String {
format!(
r#"
{{
Expand Down Expand Up @@ -85,7 +84,7 @@ fn render_conf(root: String, gas_limit: u64) -> String {
}

// render_config renders the configuration file for the Erigon node.
fn render_yaml(chain_id: u64) -> String {
fn render_yaml(chain_id: String) -> String {
format!(
r#"
datadir: ./data/dynamic-{}
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ pub fn node(config_path: PathBuf) -> anyhow::Result<()> {
/// This function starts everything needed to run an Erigon node.
pub fn erigon(config: Config, genesis_file: PathBuf) -> anyhow::Result<()> {
// Render configuration files
let erigon_config_path = config_render::render(config.aggregator.chain_id, genesis_file)?;
let erigon_config_path =
config_render::render(config.aggregator.chain_id.clone(), genesis_file)?;

debug!("Starting erigon with config: {:?}", erigon_config_path);

Expand Down

0 comments on commit cd0847f

Please sign in to comment.