Skip to content

Commit 867cfa5

Browse files
feat(gateway): Requirement to stop L1->L2 transactions before v26 upgrade (#3707)
## What ❔ A way to disable the addition of new L1->L2 transactions completely before the start of the upgrade. The chains will be expected to firstly set the new config value to `true` (and wait until all the older txs are processed) and after the end of the upgrade return it back to `false` (or remove completely) ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- The `Why` has to be clear to non-Matter Labs entities running their own ZK Chain --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Is this a breaking change? This is a breaking change for zkstack_cli functionality for gateway upgrade as new server version would be required for it to work. - [x] Yes - [ ] 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). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent 75a2b73 commit 867cfa5

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

zkstack_cli/crates/zkstack/src/commands/dev/commands/events_gatherer.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ pub(crate) async fn get_logs_for_events(
144144
// Sleep for 1 second before each JSON-RPC request to avoid hitting rate limits
145145
sleep(Duration::from_secs(1)).await;
146146

147-
let logs = match provider.get_logs(&filter).await {
148-
Ok(ls) => ls,
149-
Err(e) => {
150-
eprintln!(
151-
"Failed to fetch logs for event signature {event_sig} at {contract_address:?}: {e}"
152-
);
153-
continue;
147+
let logs = loop {
148+
match provider.get_logs(&filter).await {
149+
Ok(ls) => break ls,
150+
Err(e) => {
151+
eprintln!(
152+
"Failed to fetch logs for event signature {event_sig} at {contract_address:?}: {e}"
153+
);
154+
continue;
155+
}
154156
}
155157
};
156158

zkstack_cli/crates/zkstack/src/commands/dev/commands/gateway.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,37 @@ pub fn get_admin_call_builder(
926926
admin_calls_finalize
927927
}
928928

929+
async fn check_no_l1_txs_absence(l2_rpc_url: &str, l2_chain_id: u64) -> anyhow::Result<()> {
930+
let client = get_zk_client(l2_rpc_url, l2_chain_id)?;
931+
932+
let status = match client.l1_to_l2_txs_status().await {
933+
Ok(x) => x,
934+
Err(e) => {
935+
anyhow::bail!("Failed to query the status for L1->L2 transactions. The error {:#?}. Please ensure that you run the correct server version and `unstable` namespace is enabled.", e)
936+
}
937+
};
938+
939+
anyhow::ensure!(
940+
status.l1_to_l2_txs_paused,
941+
"L1->L2 transactions have not been paused"
942+
);
943+
anyhow::ensure!(
944+
status.l1_to_l2_txs_in_mempool == 0,
945+
"There are still L1->L2 transactions present in the mempool"
946+
);
947+
948+
Ok(())
949+
}
950+
951+
fn print_error(err: anyhow::Error) {
952+
println!(
953+
"Chain is not ready to finalize the upgrade due to the reason:\n{:#?}",
954+
err
955+
);
956+
println!("Once the chain is ready, you can re-run this command to obtain the calls to finalize the upgrade");
957+
println!("If you want to display finalization params anyway, pass `--force-display-finalization-params=true`.");
958+
}
959+
929960
pub(crate) async fn run(shell: &Shell, args: GatewayUpgradeCalldataArgs) -> anyhow::Result<()> {
930961
// 0. Read the GatewayUpgradeInfo
931962

@@ -939,6 +970,15 @@ pub(crate) async fn run(shell: &Shell, args: GatewayUpgradeCalldataArgs) -> anyh
939970

940971
// 2. Generate calldata
941972

973+
if !args.force_display_finalization_params.unwrap_or_default() {
974+
println!("Checking whether L1->L2 transactions are disabled...");
975+
if let Err(e) = check_no_l1_txs_absence(&args.l2_rpc_url, args.chain_id).await {
976+
print_error(e);
977+
return Ok(());
978+
}
979+
println!("All the L1->L2 have been paused. We can safely proceed with v26 upgrade.");
980+
}
981+
942982
let schedule_calldata = set_upgrade_timestamp_calldata(
943983
upgrade_info.new_protocol_version,
944984
args.server_upgrade_timestamp,
@@ -963,12 +1003,7 @@ pub(crate) async fn run(shell: &Shell, args: GatewayUpgradeCalldataArgs) -> anyh
9631003
.await;
9641004

9651005
if let Err(err) = chain_readiness {
966-
println!(
967-
"Chain is not ready to finalize the upgrade due to the reason:\n{:#?}",
968-
err
969-
);
970-
println!("Once the chain is ready, you can re-run this command to obtain the calls to finalize the upgrade");
971-
println!("If you want to display finalization params anyway, pass `--force-display-finalization-params=true`.");
1006+
print_error(err);
9721007
return Ok(());
9731008
};
9741009
}

0 commit comments

Comments
 (0)