Skip to content

Commit

Permalink
change default devnet chain id (#264)
Browse files Browse the repository at this point in the history
Co-authored-by: antiyro <[email protected]>
  • Loading branch information
apoorvsadana and antiyro authored Sep 17, 2024
1 parent e6531e8 commit bccdccf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/node/src/cli/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions crates/node/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub enum NetworkType {
Test,
/// The integration network.
Integration,
/// A devnet for local testing
#[value(alias("devnet"))]
Devnet,
}

impl NetworkType {
Expand All @@ -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"),
}
}

Expand All @@ -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()),
}
}

Expand Down
13 changes: 12 additions & 1 deletion crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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();
Expand Down Expand Up @@ -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(())
}
14 changes: 14 additions & 0 deletions crates/primitives/chain_config/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit bccdccf

Please sign in to comment.