From bccdccf770154fe9ecc6285e5e1747d13ad68319 Mon Sep 17 00:00:00 2001 From: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:56:49 +0530 Subject: [PATCH] change default devnet chain id (#264) Co-authored-by: antiyro <74653697+antiyro@users.noreply.github.com> --- CHANGELOG.md | 1 + crates/node/src/cli/block_production.rs | 5 +++++ crates/node/src/cli/mod.rs | 5 +++++ crates/node/src/main.rs | 13 ++++++++++++- crates/primitives/chain_config/src/chain_config.rs | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e1c4d5f..486faa106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- refactor: change default chain id and add custom flag to override - fix: generate a fixed set of public and private keys for devnet - fix: defaulted l1 gas price in devnet mode - fix: fixed anvil port value in tests diff --git a/crates/node/src/cli/block_production.rs b/crates/node/src/cli/block_production.rs index 3a848f409..d726bb9db 100644 --- a/crates/node/src/cli/block_production.rs +++ b/crates/node/src/cli/block_production.rs @@ -10,6 +10,11 @@ pub struct BlockProductionParams { #[arg(long)] pub devnet: bool, + /// Launch a devnet with a producton chain id (like SN_MAINNET, SN_SEPOLIA). + /// This in unsafe because your devnet transactiosn can be replayed on the actual network. + #[arg(long, default_value_t = false)] + pub override_devnet_chain_id: bool, + /// Create this number of contracts in the genesis block for the devnet configuration. #[arg(long, default_value_t = 10)] pub devnet_contracts: u64, diff --git a/crates/node/src/cli/mod.rs b/crates/node/src/cli/mod.rs index b75538fa9..86429e9e8 100644 --- a/crates/node/src/cli/mod.rs +++ b/crates/node/src/cli/mod.rs @@ -92,6 +92,9 @@ pub enum NetworkType { Test, /// The integration network. Integration, + /// A devnet for local testing + #[value(alias("devnet"))] + Devnet, } impl NetworkType { @@ -100,6 +103,7 @@ impl NetworkType { NetworkType::Main => "https://alpha-mainnet.starknet.io", NetworkType::Test => "https://alpha-sepolia.starknet.io", NetworkType::Integration => "https://integration-sepolia.starknet.io", + NetworkType::Devnet => unreachable!("Gateway url isn't needed for a devnet sequencer"), } } @@ -108,6 +112,7 @@ impl NetworkType { NetworkType::Main => Arc::new(ChainConfig::starknet_mainnet()), NetworkType::Test => Arc::new(ChainConfig::starknet_sepolia()), NetworkType::Integration => Arc::new(ChainConfig::starknet_integration()), + NetworkType::Devnet => Arc::new(ChainConfig::dev_config()), } } diff --git a/crates/node/src/main.rs b/crates/node/src/main.rs index 594b966a5..bac666ea3 100644 --- a/crates/node/src/main.rs +++ b/crates/node/src/main.rs @@ -11,6 +11,7 @@ mod cli; mod service; mod util; +use crate::cli::NetworkType; use crate::service::L1SyncService; use cli::RunCmd; use mc_db::DatabaseService; @@ -22,6 +23,7 @@ use mp_convert::ToFelt; use mp_utils::service::{Service, ServiceGroup}; use service::{BlockProductionService, RpcService, SyncService}; use starknet_providers::SequencerGatewayProvider; + const GREET_IMPL_NAME: &str = "Madara"; const GREET_SUPPORT_URL: &str = "https://github.com/madara-alliance/madara/issues"; @@ -32,7 +34,6 @@ async fn main() -> anyhow::Result<()> { crate::util::raise_fdlimit(); let mut run_cmd: RunCmd = RunCmd::parse(); - let chain_config = run_cmd.network.chain_config(); let node_name = run_cmd.node_name_or_provide().await.to_string(); @@ -158,6 +159,16 @@ async fn main() -> anyhow::Result<()> { .with(telemetry_service) .with(prometheus_service); + if run_cmd.block_production_params.devnet && run_cmd.network != NetworkType::Devnet { + if !run_cmd.block_production_params.override_devnet_chain_id { + panic!("‼️ You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network. Use `--network=devnet` instead. Or if this is the expected behavior please pass `--override-devnet-chain-id`", run_cmd.network); + } else { + // this log is immediately flooded with devnet accounts and so this can be missed. + // should we add a delay here to make this clearly visisble? + log::warn!("You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network.", run_cmd.network); + } + } + app.start_and_drive_to_end().await?; Ok(()) } diff --git a/crates/primitives/chain_config/src/chain_config.rs b/crates/primitives/chain_config/src/chain_config.rs index dbf06cac0..db13eb281 100644 --- a/crates/primitives/chain_config/src/chain_config.rs +++ b/crates/primitives/chain_config/src/chain_config.rs @@ -174,6 +174,20 @@ impl ChainConfig { } } + pub fn dev_config() -> Self { + Self { + chain_name: "MADARA".into(), + chain_id: ChainId::Other("MADARA_DEVNET".into()), + // A random sequencer address for fee transfers to work in block production. + sequencer_address: Felt::from_hex_unchecked( + "0x211b748338b39fe8fa353819d457681aa50ac598a3db84cacdd6ece0a17e1f3", + ) + .try_into() + .unwrap(), + ..ChainConfig::starknet_sepolia() + } + } + pub fn test_config() -> Self { Self { chain_name: "Test".into(),