Skip to content

Commit 3037ee6

Browse files
feat: Features for an easier upgrade (#3422)
## What ❔ Sending `execute` operations is stopped when gateway upgrade is ongoing Also, validator timelock is fetched from state transition manager Also, l1 shared bridge is updated from bridgehub ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] 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. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent 36559cd commit 3037ee6

File tree

11 files changed

+456
-125
lines changed

11 files changed

+456
-125
lines changed

core/lib/contracts/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const FORGE_PATH_PREFIX: &str = "contracts/l1-contracts/out";
3737
const BRIDGEHUB_CONTRACT_FILE: (&str, &str) = ("bridgehub", "IBridgehub.sol/IBridgehub.json");
3838
const STATE_TRANSITION_CONTRACT_FILE: (&str, &str) = (
3939
"state-transition",
40-
"IStateTransitionManager.sol/IStateTransitionManager.json",
40+
"StateTransitionManager.sol/StateTransitionManager.json",
4141
);
4242
const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: (&str, &str) = (
4343
"state-transition/chain-interfaces",

core/node/api_server/src/web3/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ impl BridgeAddressesHandle {
232232
*self.0.write().await = bridge_addresses;
233233
}
234234

235+
pub async fn update_l1_shared_bridge(&self, l1_shared_bridge: Address) {
236+
self.0.write().await.l1_shared_default_bridge = Some(l1_shared_bridge);
237+
}
238+
235239
pub async fn read(&self) -> api::BridgeAddresses {
236240
self.0.read().await.clone()
237241
}

core/node/eth_sender/src/aggregated_operations.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ impl AggregatedOperation {
6262
self.get_action_type() == AggregatedActionType::PublishProofOnchain
6363
|| self.get_action_type() == AggregatedActionType::Execute
6464
}
65+
66+
pub fn is_execute(&self) -> bool {
67+
self.get_action_type() == AggregatedActionType::Execute
68+
}
6569
}

core/node/eth_sender/src/aggregator.rs

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,61 @@ pub struct Aggregator {
5151
priority_tree_start_index: Option<usize>,
5252
}
5353

54+
/// Denotes whether there are any restrictions on sending either
55+
/// commit, prove or execute operations. If there is one, the reason for it
56+
/// is stored to be logged.
57+
#[derive(Debug, Default)]
58+
pub(crate) struct OperationSkippingRestrictions {
59+
pub(crate) commit_restriction: Option<&'static str>,
60+
pub(crate) prove_restriction: Option<&'static str>,
61+
pub(crate) execute_restriction: Option<&'static str>,
62+
}
63+
64+
impl OperationSkippingRestrictions {
65+
fn check_for_continuation(
66+
&self,
67+
agg_op: &AggregatedOperation,
68+
reason: Option<&'static str>,
69+
) -> bool {
70+
if let Some(reason) = reason {
71+
tracing::info!(
72+
"Skipping sending commit operation of type {} for batches {}-{} \
73+
since {}",
74+
agg_op.get_action_type(),
75+
agg_op.l1_batch_range().start(),
76+
agg_op.l1_batch_range().end(),
77+
reason
78+
);
79+
false
80+
} else {
81+
true
82+
}
83+
}
84+
85+
// Unlike other funcitons `filter_commit_op` accepts an already prepared `AggregatedOperation` for
86+
// easier compatibility with other interfaces in the file.
87+
fn filter_commit_op(
88+
&self,
89+
commit_op: Option<AggregatedOperation>,
90+
) -> Option<AggregatedOperation> {
91+
let commit_op = commit_op?;
92+
self.check_for_continuation(&commit_op, self.commit_restriction)
93+
.then_some(commit_op)
94+
}
95+
96+
fn filter_prove_op(&self, prove_op: Option<ProveBatches>) -> Option<AggregatedOperation> {
97+
let op = AggregatedOperation::PublishProofOnchain(prove_op?);
98+
self.check_for_continuation(&op, self.commit_restriction)
99+
.then_some(op)
100+
}
101+
102+
fn filter_execute_op(&self, execute_op: Option<ExecuteBatches>) -> Option<AggregatedOperation> {
103+
let op = AggregatedOperation::Execute(execute_op?);
104+
self.check_for_continuation(&op, self.commit_restriction)
105+
.then_some(op)
106+
}
107+
}
108+
54109
impl Aggregator {
55110
pub async fn new(
56111
config: SenderConfig,
@@ -153,12 +208,13 @@ impl Aggregator {
153208
})
154209
}
155210

156-
pub async fn get_next_ready_operation(
211+
pub(crate) async fn get_next_ready_operation(
157212
&mut self,
158213
storage: &mut Connection<'_, Core>,
159214
base_system_contracts_hashes: BaseSystemContractsHashes,
160215
protocol_version_id: ProtocolVersionId,
161216
l1_verifier_config: L1VerifierConfig,
217+
restrictions: OperationSkippingRestrictions,
162218
) -> Result<Option<AggregatedOperation>, EthSenderError> {
163219
let Some(last_sealed_l1_batch_number) = storage
164220
.blocks_dal()
@@ -169,30 +225,31 @@ impl Aggregator {
169225
return Ok(None); // No L1 batches in Postgres; no operations are ready yet
170226
};
171227

172-
if let Some(op) = self
173-
.get_execute_operations(
228+
if let Some(op) = restrictions.filter_execute_op(
229+
self.get_execute_operations(
174230
storage,
175231
self.config.max_aggregated_blocks_to_execute as usize,
176232
last_sealed_l1_batch_number,
177233
)
178-
.await?
179-
{
180-
Ok(Some(AggregatedOperation::Execute(op)))
181-
} else if let Some(op) = self
182-
.get_proof_operation(storage, last_sealed_l1_batch_number, l1_verifier_config)
183-
.await
184-
{
185-
Ok(Some(AggregatedOperation::PublishProofOnchain(op)))
234+
.await?,
235+
) {
236+
Ok(Some(op))
237+
} else if let Some(op) = restrictions.filter_prove_op(
238+
self.get_proof_operation(storage, last_sealed_l1_batch_number, l1_verifier_config)
239+
.await,
240+
) {
241+
Ok(Some(op))
186242
} else {
187-
Ok(self
188-
.get_commit_operation(
243+
Ok(restrictions.filter_commit_op(
244+
self.get_commit_operation(
189245
storage,
190246
self.config.max_aggregated_blocks_to_commit as usize,
191247
last_sealed_l1_batch_number,
192248
base_system_contracts_hashes,
193249
protocol_version_id,
194250
)
195-
.await)
251+
.await,
252+
))
196253
}
197254
}
198255

0 commit comments

Comments
 (0)