-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Split the rest of the zksync_core (#1940)
Extracts remaining (strategically meaningful) parts of `zksync_core`. This was a hell of a feat to de-entangle all of these interdependencies (especially in tests, oh boy). The following crates were extracted: - zksync_node_test_utils - zksync_state_keeper - zksync_reorg_detector - zksync_consistency_checker - zksync_metadata_calculator - zksync_node_sync - zksync_node_consensus - zksync_contract_verification_server - zksync_node_api_server - zksync_tee_verifier_input_producer Contents of `zksync_core::utils` were moved to other places. `zksync_core` was renamed to `zksync_core_leftovers` (and will be removed when we migrate to the framework).⚠️ this is not a perfect PR. In some places, moving stuff to another location may not be fully idiomatic. In other places, the visibility of many items could've been reduced. However, it was TOUGH to get this PR even to this form, so let's focus on major issues. All the minor things are to be polished later. Once this is merged, I'll also update settings for infra to enable logs for new crates.
- Loading branch information
Showing
194 changed files
with
1,807 additions
and
987 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//! Various helpers for using DAL methods. | ||
|
||
use std::time::Duration; | ||
|
||
use tokio::sync::watch; | ||
use zksync_types::L1BatchNumber; | ||
|
||
use crate::{ConnectionPool, Core, CoreDal}; | ||
|
||
/// Repeatedly polls the DB until there is an L1 batch. We may not have such a batch initially | ||
/// if the DB is recovered from an application-level snapshot. | ||
/// | ||
/// Returns the number of the *earliest* L1 batch, or `None` if the stop signal is received. | ||
pub async fn wait_for_l1_batch( | ||
pool: &ConnectionPool<Core>, | ||
poll_interval: Duration, | ||
stop_receiver: &mut watch::Receiver<bool>, | ||
) -> anyhow::Result<Option<L1BatchNumber>> { | ||
tracing::debug!("Waiting for at least one L1 batch in db in DB"); | ||
loop { | ||
if *stop_receiver.borrow() { | ||
return Ok(None); | ||
} | ||
|
||
let mut storage = pool.connection().await?; | ||
let sealed_l1_batch_number = storage.blocks_dal().get_earliest_l1_batch_number().await?; | ||
drop(storage); | ||
|
||
if let Some(number) = sealed_l1_batch_number { | ||
return Ok(Some(number)); | ||
} | ||
|
||
// We don't check the result: if a stop signal is received, we'll return at the start | ||
// of the next iteration. | ||
tokio::time::timeout(poll_interval, stop_receiver.changed()) | ||
.await | ||
.ok(); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use zksync_contracts::BaseSystemContractsHashes; | ||
use zksync_types::{block::L1BatchHeader, ProtocolVersion, ProtocolVersionId, H256}; | ||
|
||
use super::*; | ||
use crate::{ConnectionPool, Core, CoreDal}; | ||
|
||
#[tokio::test] | ||
async fn waiting_for_l1_batch_success() { | ||
let pool = ConnectionPool::<Core>::test_pool().await; | ||
let (_stop_sender, mut stop_receiver) = watch::channel(false); | ||
|
||
let pool_copy = pool.clone(); | ||
tokio::spawn(async move { | ||
tokio::time::sleep(Duration::from_millis(25)).await; | ||
let mut conn = pool_copy.connection().await.unwrap(); | ||
conn.protocol_versions_dal() | ||
.save_protocol_version_with_tx(&ProtocolVersion::default()) | ||
.await | ||
.unwrap(); | ||
let header = L1BatchHeader::new( | ||
L1BatchNumber(0), | ||
100, | ||
BaseSystemContractsHashes { | ||
bootloader: H256::repeat_byte(1), | ||
default_aa: H256::repeat_byte(42), | ||
}, | ||
ProtocolVersionId::latest(), | ||
); | ||
conn.blocks_dal() | ||
.insert_mock_l1_batch(&header) | ||
.await | ||
.unwrap(); | ||
}); | ||
|
||
let l1_batch = wait_for_l1_batch(&pool, Duration::from_millis(10), &mut stop_receiver) | ||
.await | ||
.unwrap(); | ||
assert_eq!(l1_batch, Some(L1BatchNumber(0))); | ||
} | ||
|
||
#[tokio::test] | ||
async fn waiting_for_l1_batch_cancellation() { | ||
let pool = ConnectionPool::<Core>::test_pool().await; | ||
let (stop_sender, mut stop_receiver) = watch::channel(false); | ||
|
||
tokio::spawn(async move { | ||
tokio::time::sleep(Duration::from_millis(25)).await; | ||
stop_sender.send_replace(true); | ||
}); | ||
|
||
let l1_batch = wait_for_l1_batch(&pool, Duration::from_secs(30), &mut stop_receiver) | ||
.await | ||
.unwrap(); | ||
assert_eq!(l1_batch, None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.