Skip to content

Commit

Permalink
some renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Jan 29, 2025
1 parent 886abf3 commit d50917c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
16 changes: 9 additions & 7 deletions core/node/state_keeper/src/io/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct MempoolIO {
chain_id: L2ChainId,
l2_da_validator_address: Option<Address>,
pubdata_type: PubdataType,
pub next_l2_block_param: L2BlockParams,
}

impl IoSealCriteria for MempoolIO {
Expand Down Expand Up @@ -283,22 +284,22 @@ impl StateKeeperIO for MempoolIO {
return Ok(None);
};

Ok(Some(L2BlockParams {
let params = L2BlockParams {
timestamp,
// This value is effectively ignored by the protocol.
virtual_blocks: 1,
}))
};
self.next_l2_block_param = params;
Ok(Some(params))
}

async fn get_updated_l2_block_params(&mut self) -> anyhow::Result<Option<L2BlockParams>> {
let current_timestamp_millis = millis_since_epoch();
let current_timestamp = (current_timestamp_millis / 1_000) as u64;

Ok(Some(L2BlockParams {
timestamp: current_timestamp,
// This value is effectively ignored by the protocol.
virtual_blocks: 1,
}))
let mut updated_params = self.next_l2_block_param;
updated_params.timestamp = current_timestamp;
Ok(Some(updated_params))
}

async fn wait_for_next_tx(
Expand Down Expand Up @@ -523,6 +524,7 @@ impl MempoolIO {
chain_id,
l2_da_validator_address,
pubdata_type,
next_l2_block_param: L2BlockParams::default(),
})
}

Expand Down
8 changes: 4 additions & 4 deletions core/node/state_keeper/src/io/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ mod tests {
vec![],
);
output_handler.handle_l2_block(&updates).await.unwrap();
updates.update_next_l2_block_parameters(L2BlockParams {
updates.set_next_l2_block_parameters(L2BlockParams {
timestamp: 1,
virtual_blocks: 1,
});
Expand Down Expand Up @@ -624,7 +624,7 @@ mod tests {
persistence.submit_l2_block(seal_command).await;

// The second command should lead to blocking
updates_manager.update_next_l2_block_parameters(L2BlockParams {
updates_manager.set_next_l2_block_parameters(L2BlockParams {
timestamp: 2,
virtual_blocks: 1,
});
Expand Down Expand Up @@ -653,7 +653,7 @@ mod tests {
// Check that `wait_for_all_commands()` state is reset after use.
persistence.wait_for_all_commands().await;

updates_manager.update_next_l2_block_parameters(L2BlockParams {
updates_manager.set_next_l2_block_parameters(L2BlockParams {
timestamp: 3,
virtual_blocks: 1,
});
Expand All @@ -678,7 +678,7 @@ mod tests {
for i in 1..=5 {
let seal_command =
updates_manager.seal_l2_block_command(Some(Address::default()), false);
updates_manager.update_next_l2_block_parameters(L2BlockParams {
updates_manager.set_next_l2_block_parameters(L2BlockParams {
timestamp: i,
virtual_blocks: 1,
});
Expand Down
32 changes: 16 additions & 16 deletions core/node/state_keeper/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl ZkSyncStateKeeper {
self.seal_l2_block(&updates_manager).await?;
// We've sealed the L2 block that we had, but we still need to set up the timestamp
// for the fictive L2 block.
self.set_new_l2_block_params(&mut updates_manager, &stop_receiver)
self.get_and_set_new_l2_block_params(&mut updates_manager, &stop_receiver)
.await?;
Self::start_next_l2_block(&mut updates_manager, &mut *batch_executor).await?;
}
Expand Down Expand Up @@ -381,7 +381,7 @@ impl ZkSyncStateKeeper {
l2_block = %updates.l2_block.number,
)
)]
async fn set_new_l2_block_params(
async fn get_and_set_new_l2_block_params(
&mut self,
updates: &mut UpdatesManager,
stop_receiver: &watch::Receiver<bool>,
Expand All @@ -397,7 +397,7 @@ impl ZkSyncStateKeeper {
{
self.health_updater
.update(StateKeeperHealthDetails::from(&cursor).into());
updates.update_next_l2_block_parameters(params);
updates.set_next_l2_block_parameters(params);
latency.observe();
return Ok(());
}
Expand All @@ -412,7 +412,7 @@ impl ZkSyncStateKeeper {
l2_block = %updates.l2_block.number,
)
)]
async fn update_new_l2_block_params(
async fn update_l2_block_params(
&mut self,
updates: &mut UpdatesManager,
stop_receiver: &watch::Receiver<bool>,
Expand All @@ -424,7 +424,7 @@ impl ZkSyncStateKeeper {
.await
.context("error getting the updated L2 block params")?
{
updates.update_next_l2_block_parameters(params);
updates.set_next_l2_block_parameters(params);
return Ok(());
}
}
Expand All @@ -438,11 +438,11 @@ impl ZkSyncStateKeeper {
l2_block = %updates_manager.l2_block.number,
)
)]
async fn set_next_l2_block_parameters(
async fn set_l2_block_params(
updates_manager: &mut UpdatesManager,
l2_block_param: L2BlockParams,
) {
updates_manager.update_next_l2_block_parameters(l2_block_param);
updates_manager.set_next_l2_block_parameters(l2_block_param);
}

#[tracing::instrument(
Expand Down Expand Up @@ -508,7 +508,7 @@ impl ZkSyncStateKeeper {
for (index, l2_block) in l2_blocks_to_reexecute.into_iter().enumerate() {
// Push any non-first L2 block to updates manager. The first one was pushed when `updates_manager` was initialized.
if index > 0 {
Self::set_next_l2_block_parameters(
Self::set_l2_block_params(
updates_manager,
L2BlockParams {
timestamp: l2_block.timestamp,
Expand Down Expand Up @@ -582,9 +582,9 @@ impl ZkSyncStateKeeper {
);

// We've processed all the L2 blocks, and right now we're preparing the next *actual* L2 block.
self.set_new_l2_block_params(updates_manager, stop_receiver)
self.get_and_set_new_l2_block_params(updates_manager, stop_receiver)
.await
.map_err(|e| e.context("set_new_l2_block_params"))?;
.map_err(|e| e.context("get_and_set_new_l2_block_params"))?;
Ok(true)
}

Expand Down Expand Up @@ -620,9 +620,9 @@ impl ZkSyncStateKeeper {

// Push the current block if it has not been done yet
if is_last_block_sealed {
self.update_new_l2_block_params(updates_manager, stop_receiver)
self.update_l2_block_params(updates_manager, stop_receiver)
.await
.map_err(|e| e.context("update_new_l2_block_params"))?;
.map_err(|e| e.context("update_l2_block_params"))?;
tracing::debug!(
"Initialized new L2 block #{} (L1 batch #{}) with timestamp {}",
updates_manager.l2_block.number + 1,
Expand All @@ -643,18 +643,18 @@ impl ZkSyncStateKeeper {
self.seal_l2_block(updates_manager).await?;
is_last_block_sealed = true;

// Get a tentative new l2 block parameters
self.set_new_l2_block_params(updates_manager, stop_receiver)
// Set a tentative new l2 block parameters
self.get_and_set_new_l2_block_params(updates_manager, stop_receiver)
.await
.map_err(|e| e.context("set_new_l2_block_params"))?;
}
let waiting_latency = KEEPER_METRICS.waiting_for_tx.start();

if is_last_block_sealed {
// The next block has not started yet, we keep updating the next l2 block parameters with correct timestamp
self.update_new_l2_block_params(updates_manager, stop_receiver)
self.update_l2_block_params(updates_manager, stop_receiver)
.await
.map_err(|e| e.context("update_new_l2_block_params"))?;
.map_err(|e| e.context("update_l2_block_params"))?;
}
let Some(tx) = self
.io
Expand Down
4 changes: 2 additions & 2 deletions core/node/state_keeper/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl UpdatesManager {
.extend_from_sealed_l2_block(old_l2_block_updates);
}

pub fn update_next_l2_block_parameters(&mut self, l2_block_param: L2BlockParams) {
pub fn set_next_l2_block_parameters(&mut self, l2_block_param: L2BlockParams) {
self.next_l2_block_param = l2_block_param
}

Expand Down Expand Up @@ -256,7 +256,7 @@ mod tests {
assert_eq!(updates_manager.l1_batch.executed_transactions.len(), 0);

// Seal an L2 block.
updates_manager.update_next_l2_block_parameters(L2BlockParams {
updates_manager.set_next_l2_block_parameters(L2BlockParams {
timestamp: 2,
virtual_blocks: 1,
});
Expand Down

0 comments on commit d50917c

Please sign in to comment.