Skip to content

Commit c861ce1

Browse files
authored
feat(gateway): Migration to Gateway (#3654)
## What ❔ Support migration to Gateway. That will be done through restart. There are few major changes in server 1. Contracats config now splitted to 3 configs: a. L1SpecificConfig - Stuff that exists only on l1 and will never be migrated to gateway b. L2Contracts - Contracts that were deployed on l2 c. ChainSpecificContracts - Contracts that deployed on l1 and on gateway 2. L1 specific contracts and L2 contracts, for now, should be specified in contracts config, manually. In a future we will be able to load them as well 3. ChainSpecificContracts, are loading from the Settlement Layer, no need to specify 4. There are no configuration for settlement layer. The settlement layer known during the start of the node and the source of truth is contracts both on l1 and settlement layer. 5. Server constantly checks that settlement layer has not changed. If it chaged, server will wait until all processed transaction are sent and confirmed and the necessary contracts are deployed to l1. After that server will be killed. We assume that kubernetes will restart the server 6. During the start server checks the settlement layer and download the necessary contracts config, later on almost all components of the system are manipulating only with settlement layer client and config. Only eth watcher knows about both layers. External Node: 1. During the sync with the server External node verifies the transaction on l1 for consistency. Once consistency checker is panicking, external node crashes 2. During the start External node checks the latest eth txs in db and depends on it setup the system to work either on Gateway or on L1 Migration process 1. Operator call the server notifier contract and this contract will send the message to server, that all commit operations, should be stopped 2. Server stops the commit operations, but continue to work in all other parts 3. Operator call the migrate to gateway function on contracts 4. Once the migration is executed both on l1 and gateway, server will crash 5. During the next start server will load all necessary contracts and continue to work ## Why ❔ The migration to settlement layer should be smooth. Without necessary of manual restarts and setting the contracts, it will drastically increase the mistakes, especially with multiple chains in operation. ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## 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 `zkstack dev fmt` and `zkstack dev lint`. --------- Signed-off-by: Danil <deniallugo@gmail.com>
1 parent 83470b4 commit c861ce1

File tree

24 files changed

+307
-197
lines changed

24 files changed

+307
-197
lines changed

zkstack_cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zkstack_cli/crates/common/src/server.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl Server {
5353
general_path: P,
5454
secrets_path: P,
5555
contracts_path: P,
56-
gateway_contracts_config_path: Option<P>,
5756
mut additional_args: Vec<String>,
5857
) -> anyhow::Result<()>
5958
where
@@ -94,27 +93,23 @@ impl Server {
9493

9594
let (command, args) = server_command.split_at_mut(1);
9695

97-
let mut cmd = shell
98-
.cmd(command[0])
99-
.args(args)
100-
.arg("--genesis-path")
101-
.arg(genesis_path)
102-
.arg("--config-path")
103-
.arg(general_path)
104-
.arg("--wallets-path")
105-
.arg(wallets_path)
106-
.arg("--secrets-path")
107-
.arg(secrets_path)
108-
.arg("--contracts-config-path")
109-
.arg(contracts_path);
110-
111-
if let Some(gateway_config_param) = gateway_contracts_config_path {
112-
cmd = cmd
113-
.arg("--gateway-contracts-config-path")
114-
.arg(gateway_config_param)
115-
};
116-
117-
let mut cmd = Cmd::new(cmd.args(additional_args).env_remove("RUSTUP_TOOLCHAIN"));
96+
let mut cmd = Cmd::new(
97+
shell
98+
.cmd(command[0])
99+
.args(args)
100+
.arg("--genesis-path")
101+
.arg(genesis_path)
102+
.arg("--config-path")
103+
.arg(general_path)
104+
.arg("--wallets-path")
105+
.arg(wallets_path)
106+
.arg("--secrets-path")
107+
.arg(secrets_path)
108+
.arg("--contracts-config-path")
109+
.arg(contracts_path)
110+
.args(additional_args)
111+
.env_remove("RUSTUP_TOOLCHAIN"),
112+
);
118113

119114
// If we are running server in normal mode
120115
// we need to get the output to the console

zkstack_cli/crates/config/src/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize, Serializer};
77
use xshell::Shell;
88
use zkstack_cli_types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation};
99
use zksync_basic_types::L2ChainId;
10-
use zksync_config::configs::{gateway::GatewayChainConfig, GatewayConfig};
10+
use zksync_config::configs::{contracts::gateway::GatewayConfig, gateway::GatewayChainConfig};
1111

1212
use crate::{
1313
consts::{

zkstack_cli/crates/config/src/forge_interface/gateway_preparation/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ethers::utils::hex;
22
use serde::{Deserialize, Serialize};
33
use zksync_basic_types::{web3::Bytes, Address};
4-
use zksync_config::configs::GatewayConfig;
4+
use zksync_config::configs::contracts::gateway::GatewayConfig;
55

66
use crate::{traits::ZkStackConfig, ChainConfig, ContractsConfig};
77

zkstack_cli/crates/config/src/gateway.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ethers::utils::hex;
2-
use zksync_config::configs::{gateway::GatewayChainConfig, GatewayConfig};
2+
use zksync_config::configs::{contracts::gateway::GatewayConfig, gateway::GatewayChainConfig};
33

44
use crate::{
55
forge_interface::deploy_gateway_ctm::output::DeployGatewayCTMOutput,

zkstack_cli/crates/zkstack/src/commands/args/wait.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use tokio::time::MissedTickBehavior;
88
use zkstack_cli_common::logger;
99

1010
use crate::messages::{
11-
msg_wait_connect_err, msg_wait_non_successful_response, msg_wait_not_healthy,
12-
msg_wait_starting_polling, msg_wait_timeout, MSG_WAIT_POLL_INTERVAL_HELP,
13-
MSG_WAIT_TIMEOUT_HELP,
11+
msg_wait_non_successful_response, msg_wait_not_healthy, msg_wait_starting_polling,
12+
msg_wait_timeout, MSG_WAIT_POLL_INTERVAL_HELP, MSG_WAIT_TIMEOUT_HELP,
1413
};
1514

1615
#[derive(Debug, Clone, Copy)]
@@ -92,14 +91,9 @@ impl WaitArgs {
9291

9392
let response = match client.get(url).send().await {
9493
Ok(response) => response,
95-
Err(err) if err.is_connect() || err.is_timeout() => {
94+
Err(_) => {
9695
continue;
9796
}
98-
Err(err) => {
99-
return Err(
100-
anyhow::Error::new(err).context(msg_wait_connect_err(&component, url))
101-
)
102-
}
10397
};
10498

10599
match component {

zkstack_cli/crates/zkstack/src/commands/chain/convert_to_gateway.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use xshell::Shell;
55
use zkstack_cli_common::{
66
config::global_config,
77
forge::{Forge, ForgeScriptArgs},
8+
logger,
89
wallets::Wallet,
910
};
1011
use zkstack_cli_config::{
@@ -18,7 +19,7 @@ use zkstack_cli_config::{
1819
ChainConfig, EcosystemConfig,
1920
};
2021
use zksync_basic_types::H256;
21-
use zksync_config::configs::GatewayConfig;
22+
use zksync_config::configs::gateway::GatewayConfig;
2223

2324
use crate::{
2425
messages::MSG_CHAIN_NOT_INITIALIZED,
@@ -284,10 +285,10 @@ pub async fn gateway_governance_whitelisting(
284285
)?;
285286
}
286287

287-
println!(
288+
logger::info(format!(
288289
"Gateway registered as a settlement layer with L2 hash: {}",
289290
hash
290-
);
291+
));
291292

292293
let hash = call_script(
293294
shell,
@@ -317,10 +318,10 @@ pub async fn gateway_governance_whitelisting(
317318
}
318319

319320
// Just in case, the L2 tx may or may not fail depending on whether it was executed previously,
320-
println!(
321+
logger::info(format!(
321322
"Gateway STM whitelisted L2 hash: {}",
322323
hex::encode(hash.as_bytes())
323-
);
324+
));
324325

325326
let hash = call_script(
326327
shell,
@@ -347,10 +348,10 @@ pub async fn gateway_governance_whitelisting(
347348
}
348349

349350
// Just in case, the L2 tx may or may not fail depending on whether it was executed previously,
350-
println!(
351+
logger::info(format!(
351352
"Gateway STM asset handler is set L2 hash: {}",
352353
hex::encode(hash.as_bytes())
353-
);
354+
));
354355

355356
let hash = call_script(
356357
shell,
@@ -380,10 +381,10 @@ pub async fn gateway_governance_whitelisting(
380381
}
381382

382383
// Just in case, the L2 tx may or may not fail depending on whether it was executed previously,
383-
println!(
384+
logger::info(format!(
384385
"Asset Id is registered in L2 bridgehub. L2 hash: {}",
385386
hex::encode(hash.as_bytes())
386-
);
387+
));
387388

388389
Ok(())
389390
}

0 commit comments

Comments
 (0)