Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Features for an easier upgrade #3422

Merged
merged 12 commits into from
Jan 6, 2025
2 changes: 1 addition & 1 deletion core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FORGE_PATH_PREFIX: &str = "contracts/l1-contracts/out";
const BRIDGEHUB_CONTRACT_FILE: (&str, &str) = ("bridgehub", "IBridgehub.sol/IBridgehub.json");
const STATE_TRANSITION_CONTRACT_FILE: (&str, &str) = (
"state-transition",
"IStateTransitionManager.sol/IStateTransitionManager.json",
"StateTransitionManager.sol/StateTransitionManager.json",
);
const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: (&str, &str) = (
"state-transition/chain-interfaces",
Expand Down
4 changes: 4 additions & 0 deletions core/node/api_server/src/web3/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ impl BridgeAddressesHandle {
*self.0.write().await = bridge_addresses;
}

pub async fn update_l1_shared_bridge(&self, l1_shared_bridge: Address) {
self.0.write().await.l1_shared_default_bridge = Some(l1_shared_bridge);
}

pub async fn read(&self) -> api::BridgeAddresses {
self.0.read().await.clone()
}
Expand Down
4 changes: 4 additions & 0 deletions core/node/eth_sender/src/aggregated_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ impl AggregatedOperation {
self.get_action_type() == AggregatedActionType::PublishProofOnchain
|| self.get_action_type() == AggregatedActionType::Execute
}

pub fn is_execute(&self) -> bool {
self.get_action_type() == AggregatedActionType::Execute
}
}
85 changes: 71 additions & 14 deletions core/node/eth_sender/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,61 @@ pub struct Aggregator {
priority_tree_start_index: Option<usize>,
}

/// Denotes whether there are any restrictions on sending either
/// commit, prove or execute operations. If there is one, the reason for it
/// is stored to be logged.
#[derive(Debug, Default)]
pub(crate) struct OperationSkippingRestrictions {
pub(crate) commit_restriction: Option<&'static str>,
pub(crate) prove_restriction: Option<&'static str>,
pub(crate) execute_restriction: Option<&'static str>,
}

impl OperationSkippingRestrictions {
fn check_for_continuation(
&self,
agg_op: &AggregatedOperation,
reason: Option<&'static str>,
) -> bool {
if let Some(reason) = reason {
tracing::info!(
"Skipping sending commit operation of type {} for batches {}-{} \
since {}",
agg_op.get_action_type(),
agg_op.l1_batch_range().start(),
agg_op.l1_batch_range().end(),
reason
);
false
} else {
true
}
}

// Unlike other funcitons `filter_commit_op` accepts an already prepared `AggregatedOperation` for
// easier compatibility with other interfaces in the file.
fn filter_commit_op(
&self,
commit_op: Option<AggregatedOperation>,
) -> Option<AggregatedOperation> {
let commit_op = commit_op?;
self.check_for_continuation(&commit_op, self.commit_restriction)
.then_some(commit_op)
}

fn filter_prove_op(&self, prove_op: Option<ProveBatches>) -> Option<AggregatedOperation> {
let op = AggregatedOperation::PublishProofOnchain(prove_op?);
self.check_for_continuation(&op, self.commit_restriction)
.then_some(op)
}

fn filter_execute_op(&self, execute_op: Option<ExecuteBatches>) -> Option<AggregatedOperation> {
let op = AggregatedOperation::Execute(execute_op?);
self.check_for_continuation(&op, self.commit_restriction)
.then_some(op)
}
}

impl Aggregator {
pub async fn new(
config: SenderConfig,
Expand Down Expand Up @@ -153,12 +208,13 @@ impl Aggregator {
})
}

pub async fn get_next_ready_operation(
pub(crate) async fn get_next_ready_operation(
&mut self,
storage: &mut Connection<'_, Core>,
base_system_contracts_hashes: BaseSystemContractsHashes,
protocol_version_id: ProtocolVersionId,
l1_verifier_config: L1VerifierConfig,
restrictions: OperationSkippingRestrictions,
) -> Result<Option<AggregatedOperation>, EthSenderError> {
let Some(last_sealed_l1_batch_number) = storage
.blocks_dal()
Expand All @@ -169,30 +225,31 @@ impl Aggregator {
return Ok(None); // No L1 batches in Postgres; no operations are ready yet
};

if let Some(op) = self
.get_execute_operations(
if let Some(op) = restrictions.filter_execute_op(
self.get_execute_operations(
storage,
self.config.max_aggregated_blocks_to_execute as usize,
last_sealed_l1_batch_number,
)
.await?
{
Ok(Some(AggregatedOperation::Execute(op)))
} else if let Some(op) = self
.get_proof_operation(storage, last_sealed_l1_batch_number, l1_verifier_config)
.await
{
Ok(Some(AggregatedOperation::PublishProofOnchain(op)))
.await?,
) {
Ok(Some(op))
} else if let Some(op) = restrictions.filter_prove_op(
self.get_proof_operation(storage, last_sealed_l1_batch_number, l1_verifier_config)
.await,
) {
Ok(Some(op))
} else {
Ok(self
.get_commit_operation(
Ok(restrictions.filter_commit_op(
self.get_commit_operation(
storage,
self.config.max_aggregated_blocks_to_commit as usize,
last_sealed_l1_batch_number,
base_system_contracts_hashes,
protocol_version_id,
)
.await)
.await,
))
}
}

Expand Down
Loading
Loading