diff --git a/common/eth2_config/src/lib.rs b/common/eth2_config/src/lib.rs index 9cea725865..7e3c025a83 100644 --- a/common/eth2_config/src/lib.rs +++ b/common/eth2_config/src/lib.rs @@ -69,7 +69,7 @@ impl Eth2Config { #[derive(Copy, Clone, Debug, PartialEq)] pub struct Eth2NetArchiveAndDirectory<'a> { pub name: &'a str, - pub unique_id: &'a str, + pub config_dir: &'a str, pub genesis_is_known: bool, } @@ -81,7 +81,7 @@ impl<'a> Eth2NetArchiveAndDirectory<'a> { .parse::() .expect("should parse manifest dir as path") .join(PREDEFINED_NETWORKS_DIR) - .join(self.unique_id) + .join(self.config_dir) } pub fn genesis_state_archive(&self) -> PathBuf { @@ -96,6 +96,7 @@ const GENESIS_STATE_IS_KNOWN: bool = true; #[derive(Copy, Clone, Debug, PartialEq)] pub struct HardcodedNet { pub name: &'static str, + pub config_dir: &'static str, pub genesis_is_known: bool, pub config: &'static [u8], pub deploy_block: &'static [u8], @@ -108,15 +109,15 @@ pub struct HardcodedNet { /// It also defines a `include__file!` macro which provides a wrapper around /// `std::include_bytes`, allowing the inclusion of bytes from the specific testnet directory. macro_rules! define_archive { - ($name_ident: ident, $name_str: tt, $genesis_is_known: ident) => { + ($name_ident: ident, $config_dir: tt, $genesis_is_known: ident) => { paste! { #[macro_use] pub mod $name_ident { use super::*; pub const ETH2_NET_DIR: Eth2NetArchiveAndDirectory = Eth2NetArchiveAndDirectory { - name: $name_str, - unique_id: $name_str, + name: stringify!($name_ident), + config_dir: $config_dir, genesis_is_known: $genesis_is_known, }; @@ -130,7 +131,7 @@ macro_rules! define_archive { "/", $this_crate::predefined_networks_dir!(), "/", - $name_str, + $config_dir, "/", $filename )) @@ -149,6 +150,7 @@ macro_rules! define_net { $this_crate::HardcodedNet { name: ETH2_NET_DIR.name, + config_dir: ETH2_NET_DIR.config_dir, genesis_is_known: ETH2_NET_DIR.genesis_is_known, config: $this_crate::$include_file!($this_crate, "../", "config.yaml"), deploy_block: $this_crate::$include_file!($this_crate, "../", "deploy_block.txt"), @@ -164,13 +166,13 @@ macro_rules! define_net { /// - `HARDCODED_NET_NAMES`: a list of the *names* of the networks defined by this macro. #[macro_export] macro_rules! define_nets { - ($this_crate: ident, $($name_ident: ident, $name_str: tt,)+) => { + ($this_crate: ident, $($name_ident: ident,)+) => { $this_crate::paste! { $( const [<$name_ident:upper>]: $this_crate::HardcodedNet = $this_crate::define_net!($this_crate, $name_ident, [<include_ $name_ident _file>]); )+ const HARDCODED_NETS: &[$this_crate::HardcodedNet] = &[$([<$name_ident:upper>],)+]; - pub const HARDCODED_NET_NAMES: &[&'static str] = &[$($name_str,)+]; + pub const HARDCODED_NET_NAMES: &[&'static str] = &[$(stringify!($name_ident),)+]; } }; } @@ -197,9 +199,9 @@ macro_rules! define_nets { /// `build.rs` which will unzip the genesis states. Then, that `eth2_network_configs` crate can /// perform the final step of using `std::include_bytes` to bake the files (bytes) into the binary. macro_rules! define_hardcoded_nets { - ($(($name_ident: ident, $name_str: tt, $genesis_is_known: ident)),+) => { + ($(($name_ident: ident, $config_dir: tt, $genesis_is_known: ident)),+) => { $( - define_archive!($name_ident, $name_str, $genesis_is_known); + define_archive!($name_ident, $config_dir, $genesis_is_known); )+ pub const ETH2_NET_DIRS: &[Eth2NetArchiveAndDirectory<'static>] = &[$($name_ident::ETH2_NET_DIR,)+]; @@ -213,7 +215,7 @@ macro_rules! define_hardcoded_nets { #[macro_export] macro_rules! instantiate_hardcoded_nets { ($this_crate: ident) => { - $this_crate::define_nets!($this_crate, $($name_ident, $name_str,)+); + $this_crate::define_nets!($this_crate, $($name_ident,)+); } } }; @@ -234,10 +236,76 @@ macro_rules! define_hardcoded_nets { // // The directory containing the testnet files should match the human-friendly name (element 1). define_hardcoded_nets!( - (mainnet, "mainnet", GENESIS_STATE_IS_KNOWN), - (prater, "prater", GENESIS_STATE_IS_KNOWN), - (gnosis, "gnosis", GENESIS_STATE_IS_KNOWN), - (kiln, "kiln", GENESIS_STATE_IS_KNOWN), - (ropsten, "ropsten", GENESIS_STATE_IS_KNOWN), - (sepolia, "sepolia", GENESIS_STATE_IS_KNOWN) + ( + // Network name (must be unique among all networks). + mainnet, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "mainnet", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + prater, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "prater", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + goerli, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + // + // The Goerli network is effectively an alias to Prater. + "prater", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + gnosis, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "gnosis", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + kiln, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "kiln", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + ropsten, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "ropsten", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ), + ( + // Network name (must be unique among all networks). + sepolia, + // The name of the directory in the `eth2_network_config/built_in_network_configs` + // directory where the configuration files are located for this network. + "sepolia", + // Set to `true` if the genesis state can be found in the `built_in_network_configs` + // directory. + GENESIS_STATE_IS_KNOWN + ) ); diff --git a/common/eth2_network_config/src/lib.rs b/common/eth2_network_config/src/lib.rs index 8df54a5a8b..2bfd003266 100644 --- a/common/eth2_network_config/src/lib.rs +++ b/common/eth2_network_config/src/lib.rs @@ -256,6 +256,13 @@ mod tests { config.beacon_state::<E>().expect("beacon state can decode"); } + #[test] + fn prater_and_goerli_are_equal() { + let goerli = Eth2NetworkConfig::from_hardcoded_net(&GOERLI).unwrap(); + let prater = Eth2NetworkConfig::from_hardcoded_net(&PRATER).unwrap(); + assert_eq!(goerli, prater); + } + #[test] fn hard_coded_nets_work() { for net in HARDCODED_NETS { @@ -275,7 +282,7 @@ mod tests { "{:?}", net.name ); - assert_eq!(config.config.config_name, Some(net.name.to_string())); + assert_eq!(config.config.config_name, Some(net.config_dir.to_string())); } }