Skip to content

Commit 319e221

Browse files
committed
fix(gateway_migration): Add wait for starting migration
Signed-off-by: Danil <[email protected]>
1 parent 198dd4d commit 319e221

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

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: 25 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,28 @@ impl UnstableNamespace {
248250
.await
249251
.map_err(DalError::generalize)?;
250252

253+
let wait_for_batches_to_be_committed = if let Some(latest_processed_l1_batch_number) =
254+
connection
255+
.interop_root_dal()
256+
.get_latest_processed_interop_root_l1_batch_number()
257+
.await
258+
.map_err(DalError::generalize)?
259+
{
260+
if let Some(tx) = connection
261+
.eth_sender_dal()
262+
.get_last_sent_successfully_eth_tx_by_batch_and_op(
263+
L1BatchNumber::from(latest_processed_l1_batch_number),
264+
L1BatchAggregatedActionType::Commit,
265+
)
266+
.await
267+
{
268+
tx.eth_tx_finality_status == EthTxFinalityStatus::Finalized
269+
} else {
270+
false
271+
}
272+
} else {
273+
false
274+
};
251275
let state = GatewayMigrationState::from_sl_and_notification(
252276
self.state.api_config.settlement_layer,
253277
latest_notification,
@@ -257,6 +281,7 @@ impl UnstableNamespace {
257281
latest_notification,
258282
state,
259283
settlement_layer: self.state.api_config.settlement_layer,
284+
wait_for_batches_to_be_committed,
260285
})
261286
}
262287

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl MigrationDirection {
5252

5353
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
5454
pub enum NotificationReceivedState {
55+
NotAllBatchesCommitted,
5556
NotAllBatchesExecuted(U256, U256),
5657
UnconfirmedTxs(usize),
5758
}
@@ -71,6 +72,9 @@ impl std::fmt::Display for NotificationReceivedState {
7172
"There are some unconfirmed transactions: {unconfirmed_txs}"
7273
)
7374
}
75+
NotificationReceivedState::NotAllBatchesCommitted => {
76+
write!(f, "Not all batches have been committed yet")
77+
}
7478
}
7579
}
7680
}
@@ -309,6 +313,12 @@ pub(crate) async fn get_gateway_migration_state(
309313
),
310314
));
311315
}
316+
317+
if gateway_migration_status.wait_for_batches_to_be_committed {
318+
return Ok(GatewayMigrationProgressState::NotificationReceived(
319+
NotificationReceivedState::NotAllBatchesCommitted,
320+
));
321+
}
312322
}
313323

314324
let unconfirmed_txs = zk_client.get_unconfirmed_txs_count().await?;

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ use crate::{
3838
admin_call_builder::AdminCallBuilder,
3939
gateway::{
4040
constants::DEFAULT_MAX_L1_GAS_PRICE_FOR_PRIORITY_TXS,
41-
gateway_common::extract_and_wait_for_priority_ops,
41+
gateway_common::{
42+
extract_and_wait_for_priority_ops, get_gateway_migration_state,
43+
GatewayMigrationProgressState, MigrationDirection,
44+
},
4245
},
4346
init::get_l1_da_validator,
4447
utils::send_tx,
@@ -88,6 +91,32 @@ pub async fn run(args: MigrateFromGatewayArgs, shell: &Shell) -> anyhow::Result<
8891
.ctm
8992
.diamond_cut_data;
9093

94+
let gateway_general_config = gateway_chain_config.get_general_config().await?;
95+
let gw_rpc_url = gateway_general_config.l2_http_url()?;
96+
97+
let state = get_gateway_migration_state(
98+
l1_url.clone(),
99+
chain_contracts_config
100+
.ecosystem_contracts
101+
.bridgehub_proxy_addr,
102+
chain_config.chain_id.as_u64(),
103+
chain_config
104+
.get_general_config()
105+
.await?
106+
.l2_http_url()
107+
.context("L2 RPC URL must be provided for cross checking")?,
108+
gw_rpc_url.clone(),
109+
MigrationDirection::FromGateway,
110+
)
111+
.await?;
112+
113+
if state != GatewayMigrationProgressState::ServerReady {
114+
anyhow::bail!(
115+
"Chain is not ready for starting the migration from Gateway. Current state: {:?}",
116+
state
117+
);
118+
}
119+
91120
let start_migrate_from_gateway_call = start_migrate_chain_from_gateway(
92121
shell,
93122
&args.forge_args,
@@ -111,8 +140,6 @@ pub async fn run(args: MigrateFromGatewayArgs, shell: &Shell) -> anyhow::Result<
111140
let (calldata, value) =
112141
AdminCallBuilder::new(start_migrate_from_gateway_call.calls).compile_full_calldata();
113142

114-
let general_config = gateway_chain_config.get_general_config().await?;
115-
let gw_rpc_url = general_config.l2_http_url()?;
116143
let gateway_provider = get_ethers_provider(&gw_rpc_url)?;
117144
let gateway_zk_client = get_zk_client(&gw_rpc_url, chain_config.chain_id.as_u64())?;
118145

zkstack_cli/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "nightly-2025-03-19"
2+
channel = "nightly-2025-09-19"

0 commit comments

Comments
 (0)