Skip to content

Commit 28d4d00

Browse files
committed
Merge remote-tracking branch 'origin/draft-v31' into sma/refactor-tests
2 parents 5279176 + ea3c161 commit 28d4d00

File tree

18 files changed

+310
-101
lines changed

18 files changed

+310
-101
lines changed

.github/workflows/ci-core-lint-reusable.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ jobs:
8282
ci_run zkstack dev lint -t js --check
8383
ci_run zkstack dev lint -t ts --check
8484
ci_run zkstack dev lint -t rs --check
85-
ci_run zkstack dev lint -t rust-toolchain
8685
ci_run zkstack dev lint -t autocompletion
8786
8887
- name: Check Database

core/lib/eth_client/src/contracts_loader.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,21 @@ pub async fn get_zk_chain_on_chain_params(
186186
diamond_proxy_addr: Address,
187187
) -> Result<ZkChainOnChainConfig, ContractCallError> {
188188
let abi = getters_facet_contract();
189-
let l2_da_commitment_scheme: Token = CallFunctionArgs::new("getDAValidatorPair", ())
189+
let token: Token = CallFunctionArgs::new("getDAValidatorPair", ())
190190
.for_contract(diamond_proxy_addr, &abi)
191191
.call(eth_client)
192192
.await?;
193-
let l2_da_commitment_scheme =
194-
if let Token::Tuple(l2_da_commitment_scheme) = l2_da_commitment_scheme {
195-
if let [Token::Address(_), Token::Uint(l2_da_commitment_scheme)] =
196-
l2_da_commitment_scheme.as_slice()
197-
{
198-
Some(
199-
L2DACommitmentScheme::try_from(l2_da_commitment_scheme.as_u64() as u8)
200-
.expect("wrong l2_da_commitment_scheme"),
201-
)
202-
} else {
203-
None
204-
}
205-
} else {
206-
None
207-
};
193+
194+
let l2_da_commitment_scheme = match token {
195+
Token::Tuple(tuple) if tuple.len() == 2 => match tuple.as_slice() {
196+
[Token::Address(_), Token::Uint(value)] if *value <= U256::from(u8::MAX) => Some(
197+
L2DACommitmentScheme::try_from(value.as_u64() as u8)
198+
.expect("Wrong L2DACommitmentScheme"),
199+
),
200+
_ => None,
201+
},
202+
_ => None,
203+
};
208204

209205
Ok(ZkChainOnChainConfig {
210206
l2_da_commitment_scheme,

core/lib/types/src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ pub struct GatewayMigrationStatus {
11121112
pub latest_notification: Option<GatewayMigrationNotification>,
11131113
pub state: GatewayMigrationState,
11141114
pub settlement_layer: Option<SettlementLayer>,
1115+
pub wait_for_batches_to_be_committed: bool,
11151116
}
11161117

11171118
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]

core/node/api_server/src/web3/namespaces/unstable/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use zksync_dal::{Connection, Core, CoreDal, DalError};
88
use zksync_mini_merkle_tree::MiniMerkleTree;
99
use zksync_multivm::{interface::VmEvent, zk_evm_latest::ethereum_types::U64};
1010
use zksync_types::{
11+
aggregated_operations::L1BatchAggregatedActionType,
1112
api,
1213
api::{
1314
ChainAggProof, DataAvailabilityDetails, GatewayMigrationStatus, L1ToL2TxsStatus, TeeProof,
1415
TransactionDetailedResult, TransactionExecutionInfo,
1516
},
17+
eth_sender::EthTxFinalityStatus,
1618
server_notification::GatewayMigrationState,
1719
tee_types::TeeType,
1820
web3,
@@ -248,6 +250,27 @@ impl UnstableNamespace {
248250
.await
249251
.map_err(DalError::generalize)?;
250252

253+
let all_batches_with_interop_roots_committed = match connection
254+
.interop_root_dal()
255+
.get_latest_processed_interop_root_l1_batch_number()
256+
.await
257+
.map_err(DalError::generalize)?
258+
{
259+
None => true,
260+
Some(latest_processed_l1_batch_number) => {
261+
match connection
262+
.eth_sender_dal()
263+
.get_last_sent_successfully_eth_tx_by_batch_and_op(
264+
L1BatchNumber::from(latest_processed_l1_batch_number),
265+
L1BatchAggregatedActionType::Commit,
266+
)
267+
.await
268+
{
269+
Some(tx) => tx.eth_tx_finality_status == EthTxFinalityStatus::Finalized,
270+
None => false,
271+
}
272+
}
273+
};
251274
let state = GatewayMigrationState::from_sl_and_notification(
252275
self.state
253276
.api_config
@@ -264,6 +287,7 @@ impl UnstableNamespace {
264287
.api_config
265288
.settlement_layer
266289
.settlement_layer_for_sending_txs(),
290+
wait_for_batches_to_be_committed: !all_batches_with_interop_roots_committed,
267291
})
268292
}
269293

core/node/eth_sender/src/eth_tx_aggregator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,13 @@ impl EthTxAggregator {
857857
op_restrictions.precommit_restriction = reason;
858858
// From V31 when migrating to or from gateway, we need to wait for all blocks to be executed,
859859
// so there is no restriction for prove and execute operations
860-
if let Some(SettlementLayer::Gateway(_)) = self.settlement_layer {
861-
// For the migration from gateway to L1, we need we need to ensure all batches containing interop roots get committed and executed.
862-
if !self
860+
if matches!(self.settlement_layer, Some(SettlementLayer::Gateway(_))) {
861+
if self
863862
.is_waiting_for_batches_with_interop_roots_to_be_committed(storage)
864863
.await?
865864
{
865+
// For the migration from gateway to L1, we need to ensure all batches containing interop roots
866+
// get committed and executed. Once this happens, we can re-enable commit & precommit.
866867
op_restrictions.commit_restriction = None;
867868
op_restrictions.precommit_restriction = None;
868869
}

core/tests/gateway-migration-test/tests/migration.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,23 @@ describe('Migration from gateway test', function () {
226226
}
227227
}
228228
} else {
229-
await utils.spawn(
230-
`zkstack chain gateway migrate-from-gateway --chain ${fileConfig.chain} --gateway-chain-name ${gatewayChain}`
231-
);
229+
let migrationSucceeded = false;
230+
for (let i = 0; i < 60; i++) {
231+
try {
232+
await utils.spawn(
233+
`zkstack chain gateway migrate-from-gateway --chain ${fileConfig.chain} --gateway-chain-name ${gatewayChain}`
234+
);
235+
migrationSucceeded = true;
236+
break;
237+
} catch (e) {
238+
console.log(`Migration attempt ${i} failed with error: ${e}`);
239+
await utils.sleep(2);
240+
}
241+
}
242+
243+
if (!migrationSucceeded) {
244+
throw new Error('Migration from gateway did not succeed after 60 attempts');
245+
}
232246
}
233247
await mainNodeSpawner.mainNode?.waitForShutdown();
234248
// Node is already killed, so we simply start the new server

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::str::FromStr;
2-
31
use ethers::types::{Address, H256, U256};
42
use serde::{Deserialize, Serialize};
53

64
use crate::{
75
forge_interface::deploy_ecosystem::input::InitialDeploymentConfig, traits::FileConfigTrait,
8-
ContractsConfig, ContractsGenesisConfig,
6+
ContractsConfig,
97
};
108

119
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -16,13 +14,6 @@ pub struct GatewayContractsConfig {
1614
pub create2_factory_salt: H256,
1715
pub create2_factory_addr: Option<Address>,
1816
pub validator_timelock_execution_delay: U256,
19-
pub genesis_root: H256,
20-
pub genesis_rollup_leaf_index: U256,
21-
pub genesis_batch_commitment: H256,
22-
pub latest_protocol_version: U256,
23-
pub default_aa_hash: H256,
24-
pub bootloader_hash: H256,
25-
pub evm_emulator_hash: Option<H256>,
2617
pub avail_l1_da_validator: Option<Address>,
2718
pub bridgehub_proxy_address: Address,
2819
}
@@ -52,15 +43,14 @@ impl GatewayVotePreparationConfig {
5243
#[allow(clippy::too_many_arguments)]
5344
pub fn new(
5445
initial_deployment_config: &InitialDeploymentConfig,
55-
genesis_input: &ContractsGenesisConfig,
56-
external_contracts_config: &ContractsConfig, // from external context
46+
external_contracts_config: &ContractsConfig,
5747
era_chain_id: U256,
5848
gateway_chain_id: U256,
5949
owner_address: Address,
6050
testnet_verifier: bool,
6151
is_zk_sync_os: bool,
6252
refund_recipient: Address,
63-
) -> anyhow::Result<Self> {
53+
) -> Self {
6454
let contracts = GatewayContractsConfig {
6555
governance_security_council_address: Address::zero(),
6656
governance_min_delay: U256::from(initial_deployment_config.governance_min_delay),
@@ -70,17 +60,6 @@ impl GatewayVotePreparationConfig {
7060
validator_timelock_execution_delay: U256::from(
7161
initial_deployment_config.validator_timelock_execution_delay,
7262
),
73-
genesis_root: H256::from_str(&genesis_input.genesis_root_hash()?)?,
74-
genesis_rollup_leaf_index: U256::from(genesis_input.rollup_last_leaf_index()?),
75-
genesis_batch_commitment: H256::from_str(&genesis_input.genesis_commitment()?)?,
76-
latest_protocol_version: genesis_input.protocol_semantic_version()?.pack(),
77-
default_aa_hash: H256::from_str(&genesis_input.default_aa_hash()?)?,
78-
bootloader_hash: H256::from_str(&genesis_input.bootloader_hash()?)?,
79-
evm_emulator_hash: genesis_input
80-
.evm_emulator_hash()?
81-
.as_ref()
82-
.map(|hash| H256::from_str(&hash.to_string()))
83-
.transpose()?,
8463
avail_l1_da_validator: external_contracts_config.l1.avail_l1_da_validator_addr,
8564
bridgehub_proxy_address: external_contracts_config
8665
.ecosystem_contracts
@@ -91,7 +70,7 @@ impl GatewayVotePreparationConfig {
9170
token_weth_address: initial_deployment_config.token_weth_address,
9271
};
9372

94-
Ok(Self {
73+
Self {
9574
era_chain_id,
9675
owner_address,
9776
testnet_verifier,
@@ -107,6 +86,6 @@ impl GatewayVotePreparationConfig {
10786
.force_deployments_data
10887
.clone()
10988
.unwrap_or_default(),
110-
})
89+
}
11190
}
11291
}

zkstack_cli/crates/zkstack/src/commands/chain/args/init/da_configs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub enum ValidiumTypeInternal {
3131
EigenDA,
3232
}
3333

34+
impl ValidiumTypeInternal {
35+
pub fn as_str(&self) -> &str {
36+
match self {
37+
ValidiumTypeInternal::NoDA => "NoDA",
38+
ValidiumTypeInternal::Avail => "Avail",
39+
ValidiumTypeInternal::EigenDA => "EigenDA",
40+
}
41+
}
42+
}
43+
3444
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, EnumIter, Display, ValueEnum)]
3545
pub enum AvailClientTypeInternal {
3646
FullClient,

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ pub struct ConvertToGatewayArgs {
5050

5151
#[clap(long, default_value_t = false)]
5252
pub only_save_calldata: bool,
53+
54+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
55+
#[clap(long)]
56+
pub l1_rpc_url: Option<String>,
57+
58+
/// Skip applying gateway config overrides (overrides/gateway.yaml).
59+
/// By default, the gateway.yaml file is required.
60+
#[clap(long, default_value_t = false)]
61+
pub no_gateway_overrides: bool,
5362
}
5463

5564
fn parse_decimal_u256(s: &str) -> Result<U256, String> {
@@ -60,21 +69,26 @@ fn parse_decimal_u256(s: &str) -> Result<U256, String> {
6069
}
6170

6271
pub async fn run(convert_to_gw_args: ConvertToGatewayArgs, shell: &Shell) -> anyhow::Result<()> {
63-
let args = convert_to_gw_args.forge_args;
72+
let args = convert_to_gw_args.forge_args.clone();
6473
let ecosystem_config = ZkStackConfig::ecosystem(shell)?;
6574
let chain_config = ecosystem_config
6675
.load_current_chain()
6776
.context(MSG_CHAIN_NOT_INITIALIZED)?;
68-
let l1_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
77+
let l1_url = match convert_to_gw_args.l1_rpc_url {
78+
Some(url) => url,
79+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
80+
};
6981
let chain_contracts_config = chain_config.get_contracts_config()?;
70-
let contracts_config = chain_config.get_contracts_genesis_config().await?;
71-
override_config(
72-
shell,
73-
&ecosystem_config
74-
.default_configs_path_for_ctm(chain_config.vm_option)
75-
.join(PATH_TO_GATEWAY_OVERRIDE_CONFIG),
76-
&chain_config,
77-
)?;
82+
83+
if !convert_to_gw_args.no_gateway_overrides {
84+
override_config(
85+
shell,
86+
&ecosystem_config
87+
.default_configs_path_for_ctm(chain_config.vm_option)
88+
.join(PATH_TO_GATEWAY_OVERRIDE_CONFIG),
89+
&chain_config,
90+
)?;
91+
}
7892

7993
let chain_deployer_wallet = chain_config
8094
.get_wallets_config()?
@@ -141,15 +155,14 @@ pub async fn run(convert_to_gw_args: ConvertToGatewayArgs, shell: &Shell) -> any
141155
&chain_deployer_wallet,
142156
GatewayVotePreparationConfig::new(
143157
&ecosystem_config.get_initial_deployment_config().unwrap(),
144-
&contracts_config,
145158
&chain_contracts_config,
146159
ecosystem_config.era_chain_id.as_u64().into(),
147160
chain_config.chain_id.as_u64().into(),
148161
ecosystem_config.get_contracts_config()?.l1.governance_addr,
149162
ecosystem_config.prover_version == ProverMode::NoProofs,
150163
chain_config.vm_option.is_zksync_os(),
151164
chain_deployer_wallet.address,
152-
)?,
165+
),
153166
l1_url.clone(),
154167
convert_to_gw_args
155168
.ctm_chain_id

zkstack_cli/crates/zkstack/src/commands/chain/gateway/create_tx_filterer.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::Context;
2+
use clap::Parser;
23
use ethers::contract::BaseContract;
34
use lazy_static::lazy_static;
5+
use serde::{Deserialize, Serialize};
46
use xshell::Shell;
57
use zkstack_cli_common::{
68
config::global_config,
@@ -28,13 +30,28 @@ lazy_static! {
2830
BaseContract::from(DEPLOYGATEWAYTRANSACTIONFILTERERABI_ABI.clone());
2931
}
3032

31-
pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
33+
#[derive(Debug, Serialize, Deserialize, Parser)]
34+
pub struct CreateTxFiltererArgs {
35+
/// All ethereum environment related arguments
36+
#[clap(flatten)]
37+
#[serde(flatten)]
38+
pub forge_args: ForgeScriptArgs,
39+
40+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
41+
#[clap(long)]
42+
pub l1_rpc_url: Option<String>,
43+
}
44+
45+
pub async fn run(args: CreateTxFiltererArgs, shell: &Shell) -> anyhow::Result<()> {
3246
let chain_name = global_config().chain_name.clone();
3347
let ecosystem_config = ZkStackConfig::ecosystem(shell)?;
3448
let chain_config = ecosystem_config
3549
.load_chain(chain_name)
3650
.context(MSG_CHAIN_NOT_INITIALIZED)?;
37-
let l1_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
51+
let l1_url = match args.l1_rpc_url {
52+
Some(url) => url,
53+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
54+
};
3855
let mut chain_contracts_config = chain_config.get_contracts_config()?;
3956

4057
let chain_deployer_wallet = chain_config
@@ -44,7 +61,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
4461

4562
let output: GatewayTxFiltererOutput = deploy_gateway_tx_filterer(
4663
shell,
47-
args.clone(),
64+
args.forge_args.clone(),
4865
&chain_config,
4966
&chain_deployer_wallet,
5067
&chain_contracts_config,
@@ -54,7 +71,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
5471

5572
set_transaction_filterer(
5673
shell,
57-
&args,
74+
&args.forge_args,
5875
&chain_config.path_to_foundry_scripts(),
5976
AdminScriptMode::Broadcast(chain_config.get_wallets_config()?.governor),
6077
chain_config.chain_id.as_u64(),

0 commit comments

Comments
 (0)