Skip to content

Commit

Permalink
feat(zk_toolbox): Add holesky testnet as layer1 network (#2632)
Browse files Browse the repository at this point in the history
## What ❔

Add `holesky` for `--l1-network` config in ecosystem cmd, that will make
the testnet use holesky testnet (chain id: 17000) as l1 network

## Why ❔

It can make us deploy testnet into holesky testnet more easy, in
zk_inception, it will write the layer1 's chain id into the config, when
use `ecosystem init` cmd, it will start chain init also, if use wrong
chain id for layer1 endpoint, it will make cmd run failed, so we cannot
just use layer1 endpoint to deploy a testnet in holesky.

Now we add `holesky` for `--l1-network` config to let it write 17000 as
chain id, that will make us to deploy testnet more easy.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.

---------

Co-authored-by: Danil <deniallugo@gmail.com>
  • Loading branch information
fyInALT and Deniallugo authored Aug 23, 2024
1 parent 9080428 commit d9266e5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions core/lib/basic_types/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum Network {
Goerli,
/// Ethereum Sepolia testnet.
Sepolia,
/// Ethereum Holešky testnet.
Holesky,
/// Self-hosted Ethereum network.
Localhost,
/// Self-hosted L2 network.
Expand All @@ -48,6 +50,7 @@ impl FromStr for Network {
"localhost" => Self::Localhost,
"localhostL2" => Self::LocalhostL2,
"sepolia" => Self::Sepolia,
"holesky" => Self::Holesky,
"test" => Self::Test,
another => return Err(another.to_owned()),
})
Expand All @@ -64,6 +67,7 @@ impl fmt::Display for Network {
Self::Localhost => write!(f, "localhost"),
Self::LocalhostL2 => write!(f, "localhostL2"),
Self::Sepolia => write!(f, "sepolia"),
Self::Holesky => write!(f, "holesky"),
Self::Unknown => write!(f, "unknown"),
Self::Test => write!(f, "test"),
}
Expand All @@ -80,6 +84,7 @@ impl Network {
5 => Self::Goerli,
9 => Self::Localhost,
11155111 => Self::Sepolia,
17000 => Self::Holesky,
270 => Self::LocalhostL2,
_ => Self::Unknown,
}
Expand All @@ -94,6 +99,7 @@ impl Network {
Self::Goerli => SLChainId(5),
Self::Localhost => SLChainId(9),
Self::Sepolia => SLChainId(11155111),
Self::Holesky => SLChainId(17000),
Self::LocalhostL2 => SLChainId(270),
Self::Unknown => panic!("Unknown chain ID"),
Self::Test => panic!("Test chain ID"),
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/types/src/l1_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum L1Network {
#[default]
Localhost,
Sepolia,
Holesky,
Mainnet,
}

Expand All @@ -30,6 +31,7 @@ impl L1Network {
match self {
L1Network::Localhost => 9,
L1Network::Sepolia => 11_155_111,
L1Network::Holesky => 17000,
L1Network::Mainnet => 1,
}
}
Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_inception/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Create a new ecosystem and chain, setting necessary configurations for later ini
- `--ecosystem-name <ECOSYSTEM_NAME>`
- `--l1-network <L1_NETWORK>` — L1 Network

Possible values: `localhost`, `sepolia`, `mainnet`
Possible values: `localhost`, `sepolia`, `holesky`, `mainnet`

- `--link-to-code <LINK_TO_CODE>` — Code link
- `--chain-name <CHAIN_NAME>`
Expand Down
28 changes: 21 additions & 7 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ use crate::{
},
},
messages::{
msg_ecosystem_initialized, msg_initializing_chain, MSG_CHAIN_NOT_INITIALIZED,
msg_ecosystem_initialized, msg_ecosystem_no_found_preexisting_contract,
msg_initializing_chain, MSG_CHAIN_NOT_INITIALIZED,
MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_DEPLOYING_ERC20,
MSG_DEPLOYING_ERC20_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR,
MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM,
Expand Down Expand Up @@ -242,17 +243,30 @@ async fn deploy_ecosystem(
}
};

let ecosystem_preexisting_configs_path =
ecosystem_config
.get_preexisting_configs_path()
.join(format!(
"{}.yaml",
ecosystem_config.l1_network.to_string().to_lowercase()
));

// currently there are not some preexisting ecosystem contracts in
// chains, so we need check if this file exists.
if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() {
anyhow::bail!(msg_ecosystem_no_found_preexisting_contract(
&ecosystem_config.l1_network.to_string()
))
}

let ecosystem_contracts_path =
ecosystem_contracts_path.unwrap_or_else(|| match ecosystem_config.l1_network {
L1Network::Localhost => {
ContractsConfig::get_path_with_base_path(&ecosystem_config.config)
}
L1Network::Sepolia | L1Network::Mainnet => ecosystem_config
.get_preexisting_configs_path()
.join(format!(
"{}.yaml",
ecosystem_config.l1_network.to_string().to_lowercase()
)),
L1Network::Sepolia | L1Network::Holesky | L1Network::Mainnet => {
ecosystem_preexisting_configs_path
}
});

ContractsConfig::read(shell, ecosystem_contracts_path)
Expand Down
4 changes: 4 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ pub(super) const MSG_ERA_OBSERVABILITY_ALREADY_SETUP: &str = "Era observability
pub(super) const MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER: &str =
"Downloading era observability...";

pub(super) fn msg_ecosystem_no_found_preexisting_contract(chains: &str) -> String {
format!("Not found preexisting ecosystem Contracts with chains {chains}")
}

pub(super) fn msg_initializing_chain(chain_name: &str) -> String {
format!("Initializing chain {chain_name}")
}
Expand Down

0 comments on commit d9266e5

Please sign in to comment.