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(en): Make state keeper work with pruned data #900

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
615b43f
Generalize `FetcherCursor` for all I/O impls
slowli Jan 17, 2024
2ae2c2a
Track prev miniblock params locally
slowli Jan 17, 2024
50dfccf
Add extra fields to `snapshot_recovery` table
slowli Jan 17, 2024
6bbb072
Account for snapshots in `IoCursor::new()`
slowli Jan 17, 2024
7c6bb29
Test `IoCursor::new()`
slowli Jan 17, 2024
d308d10
Sketch `L1BatchParamsProvider`
slowli Jan 18, 2024
dfa26df
Adapt `get_miniblocks_to_reexecute()` for snapshot recovery
slowli Jan 18, 2024
f5d6db9
Move `common` tests to separate file
slowli Jan 18, 2024
edb4ad0
Recreate DB state more accurately in SK tests
slowli Jan 18, 2024
07c693b
Add (non-working) test for `MempoolIO`
slowli Jan 18, 2024
65134f4
Update from upstream
slowli Jan 18, 2024
d9914ce
Adapt `load_previous_batch_version_id()`
slowli Jan 19, 2024
ef8bbc2
Update from upstream
slowli Jan 19, 2024
a632f1c
Update from upstream
slowli Jan 25, 2024
100d49a
Refactor `prepare_recovery_snapshot()` util
slowli Jan 25, 2024
65c791d
Test miniblock processing after snapshot recovery
slowli Jan 26, 2024
8f8de9b
Fix `sync_block()` DB query
slowli Jan 26, 2024
2bf0b58
Remove unused file
slowli Jan 26, 2024
bc6de97
Fix fee account retrieval after snapshot recovery
slowli Jan 26, 2024
a2375f7
Test `ExternalIO` after snapshot recovery
slowli Jan 26, 2024
b694b39
Generalize `prepare_recovery_snapshot()`
slowli Jan 26, 2024
fd319c4
Set real hash for `Execute` transactions
slowli Jan 29, 2024
b748885
Test snapshot recovery for L1 batch executor
slowli Jan 29, 2024
62fb131
Update from upstream
slowli Jan 29, 2024
ff30660
Refactor fetcher initialization for EN
slowli Jan 29, 2024
bc791e0
Update from upstream
slowli Jan 30, 2024
763accb
Make DB migration backward-compatible
slowli Jan 30, 2024
9ff43a4
Update from upstream
slowli Jan 31, 2024
96f10d3
Merge branch 'main' into aov-pla-703-snapshot-recovery-make-state-kee…
slowli Feb 1, 2024
915a872
Test missing protocol version in `ExternalIO`
slowli Feb 1, 2024
849b76b
Rename `wait_for_previous_l1_batch_hash()` methods
slowli Feb 1, 2024
b947d02
Simplify `wait_for_new_miniblock_params()` method
slowli Feb 1, 2024
211a42d
Update from upstream
slowli Feb 5, 2024
aafa6f1
Update from upstream (again)
slowli Feb 5, 2024
7d05846
Fix snapshot applier test
slowli Feb 5, 2024
fac593f
Move `wait_for_previous_l1_batch_hash()` invocation
slowli Feb 5, 2024
5a89927
Update from upstream
slowli Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 53 additions & 56 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ use zksync_core::{
MiniblockSealer, MiniblockSealerHandle, ZkSyncStateKeeper,
},
sync_layer::{
batch_status_updater::BatchStatusUpdater, external_io::ExternalIO, fetcher::FetcherCursor,
genesis::perform_genesis_if_needed, ActionQueue, MainNodeClient, SyncState,
batch_status_updater::BatchStatusUpdater, external_io::ExternalIO,
fetcher::MainNodeFetcher, genesis::perform_genesis_if_needed, ActionQueue, MainNodeClient,
SyncState,
},
};
use zksync_dal::{healthcheck::ConnectionPoolHealthCheck, ConnectionPool};
Expand Down Expand Up @@ -58,7 +59,7 @@ async fn build_state_keeper(
miniblock_sealer_handle: MiniblockSealerHandle,
stop_receiver: watch::Receiver<bool>,
chain_id: L2ChainId,
) -> ZkSyncStateKeeper {
) -> anyhow::Result<ZkSyncStateKeeper> {
// These config values are used on the main node, and depending on these values certain transactions can
// be *rejected* (that is, not included into the block). However, external node only mirrors what the main
// node has already executed, so we can safely set these values to the maximum possible values - if the main
Expand All @@ -79,9 +80,9 @@ async fn build_state_keeper(
true,
));

let main_node_url = config.required.main_node_url().unwrap();
let main_node_url = config.required.main_node_url()?;
let main_node_client = <dyn MainNodeClient>::json_rpc(&main_node_url)
.expect("Failed creating JSON-RPC client for main node");
.context("Failed creating JSON-RPC client for main node")?;
let io = ExternalIO::new(
miniblock_sealer_handle,
connection_pool,
Expand All @@ -92,14 +93,15 @@ async fn build_state_keeper(
validation_computational_gas_limit,
chain_id,
)
.await;
.await
.context("Failed initializing I/O for external node state keeper")?;

ZkSyncStateKeeper::new(
Ok(ZkSyncStateKeeper::new(
stop_receiver,
Box::new(io),
batch_executor_base,
Box::new(NoopSealer),
)
))
}

async fn init_tasks(
Expand Down Expand Up @@ -166,61 +168,56 @@ async fn init_tasks(
stop_receiver.clone(),
config.remote.l2_chain_id,
)
.await;
.await?;

let main_node_client = <dyn MainNodeClient>::json_rpc(&main_node_url)
.context("Failed creating JSON-RPC client for main node")?;
let singleton_pool_builder = ConnectionPool::singleton(&config.postgres.database_url);

let fetcher_handle = match config.consensus.clone() {
None => {
let fetcher_cursor = {
let pool = singleton_pool_builder
.build()
.await
.context("failed to build a connection pool for `MainNodeFetcher`")?;
let mut storage = pool.access_storage_tagged("sync_layer").await?;
FetcherCursor::new(&mut storage)
.await
.context("failed to load `MainNodeFetcher` cursor from Postgres")?
};
let fetcher = fetcher_cursor.into_fetcher(
Box::new(main_node_client),
action_queue_sender,
sync_state.clone(),
stop_receiver.clone(),
);
tokio::spawn(fetcher.run())
}
Some(cfg) => {
let pool = connection_pool.clone();
let mut stop_receiver = stop_receiver.clone();
let sync_state = sync_state.clone();
#[allow(clippy::redundant_locals)]
tokio::spawn(async move {
let sync_state = sync_state;
let main_node_client = main_node_client;
scope::run!(&ctx::root(), |ctx, s| async {
s.spawn_bg(async {
let res = cfg.run(ctx, pool, action_queue_sender).await;
tracing::info!("Consensus actor stopped");
res
});
// TODO: information about the head block of the validators
// (currently just the main node)
// should also be provided over the gossip network.
s.spawn_bg(async {
consensus::run_main_node_state_fetcher(ctx, &main_node_client, &sync_state)
.await?;
Ok(())
});
ctx.wait(stop_receiver.wait_for(|stop| *stop)).await??;
let fetcher_handle = if let Some(cfg) = config.consensus.clone() {
let pool = connection_pool.clone();
let mut stop_receiver = stop_receiver.clone();
let sync_state = sync_state.clone();

#[allow(clippy::redundant_locals)]
tokio::spawn(async move {
let sync_state = sync_state;
let main_node_client = main_node_client;
scope::run!(&ctx::root(), |ctx, s| async {
s.spawn_bg(async {
let res = cfg.run(ctx, pool, action_queue_sender).await;
tracing::info!("Consensus actor stopped");
res
});
// TODO: information about the head block of the validators (currently just the main node)
// should also be provided over the gossip network.
s.spawn_bg(async {
consensus::run_main_node_state_fetcher(ctx, &main_node_client, &sync_state)
.await?;
Ok(())
})
.await
.context("consensus actor")
});
ctx.wait(stop_receiver.wait_for(|stop| *stop)).await??;
Ok(())
})
}
.await
.context("consensus actor")
})
} else {
let pool = singleton_pool_builder
.build()
.await
.context("failed to build a connection pool for `MainNodeFetcher`")?;
let mut storage = pool.access_storage_tagged("sync_layer").await?;
let fetcher = MainNodeFetcher::new(
&mut storage,
Box::new(main_node_client),
action_queue_sender,
sync_state.clone(),
stop_receiver.clone(),
)
.await
.context("failed initializing main node fetcher")?;
tokio::spawn(fetcher.run())
};

let metadata_calculator_config = MetadataCalculatorConfig {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading