Skip to content

Commit b47bc0c

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

File tree

6 files changed

+71
-4
lines changed

6 files changed

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

253+
let latest_processed_l1_batch_number = connection
254+
.interop_root_dal()
255+
.get_latest_processed_interop_root_l1_batch_number()
256+
.await?;
257+
258+
let wait_for_batches_to_be_committed = if let Some(latest_processed_l1_batch_number) =
259+
connection
260+
.interop_root_dal()
261+
.get_latest_processed_interop_root_l1_batch_number()
262+
.await?
263+
{
264+
if let Some(tx) = connection
265+
.eth_sender_dal()
266+
.get_last_sent_successfully_eth_tx_by_batch_and_op(
267+
L1BatchNumber::from(latest_processed_l1_batch_number),
268+
L1BatchAggregatedActionType::Commit,
269+
)
270+
.await
271+
{
272+
tx.eth_tx_finality_status == EthTxFinalityStatus::Finalized
273+
} else {
274+
false
275+
}
276+
} else {
277+
false
278+
};
251279
let state = GatewayMigrationState::from_sl_and_notification(
252280
self.state.api_config.settlement_layer,
253281
latest_notification,
@@ -257,6 +285,7 @@ impl UnstableNamespace {
257285
latest_notification,
258286
state,
259287
settlement_layer: self.state.api_config.settlement_layer,
288+
wait_for_batches_to_be_committed,
260289
})
261290
}
262291

core/tests/ts-integration/contracts/zkasm/invalid_pointer.zkasm

Whitespace-only changes.

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)