Skip to content

Commit

Permalink
feat: allow chain ID duplications in profiles
Browse files Browse the repository at this point in the history
There are legitimate use cases for defining networks with the same chain
IDs - devnets, different RPC URLs for accessing the same network, etc..
Starkli should not enforce chain ID uniqueness.

One unfortunate side effect of this is that when using `--rpc` directly,
we can no longer uniquely match the chain ID fetched to a network
defined in the profile (this matching doesn't matter now, but will do in
the future when we have network-specific settings). This is not ideal
but still fine as it's expected that those who define custom networks
are likely to use `--network` instead of `--rpc` anyways. And by using
`--network` directly, users can always uniquely choose the network they
want the settings applied.
  • Loading branch information
xJonathanLEI committed Dec 28, 2023
1 parent 27402da commit 5f5da16
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::{hash_map::Entry, HashMap},
fmt::Display,
io::{Read, Write},
path::PathBuf,
Expand Down Expand Up @@ -83,23 +82,6 @@ impl Profiles {
);
}

if let Some(default_profile) = loaded_profiles.profiles.get(DEFAULT_PROFILE_NAME) {
// Checks chain ID duplication
let mut chain_id_last_used_in_network = HashMap::new();
for (network_id, network) in default_profile.networks.iter() {
match chain_id_last_used_in_network.entry(network.chain_id) {
Entry::Occupied(entry) => anyhow::bail!(
"invalid profile `default`: networks {} and {} have the same chain ID",
entry.get(),
network_id
),
Entry::Vacant(entry) => {
entry.insert(network_id);
}
}
}
}

Ok(loaded_profiles)
}

Expand Down

0 comments on commit 5f5da16

Please sign in to comment.