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: Unify and port node storage initialization #2363

Merged
merged 26 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
876c488
Snapshot
popzxc Jul 1, 2024
3362cd2
Implement node storage initializer
popzxc Jul 1, 2024
d55ee1c
Make snapshot applier aware of stop signals
popzxc Jul 1, 2024
5356453
Implement unified initializer
popzxc Jul 1, 2024
ce0d27a
Rework node role to be a trait
popzxc Jul 1, 2024
6739f80
Implement node storage init layer
popzxc Jul 1, 2024
3e9941f
Rework reorg detector layer
popzxc Jul 1, 2024
f960c57
Improve framework integration
popzxc Jul 1, 2024
3ed1ab9
Port main node genesis to the framework
popzxc Jul 2, 2024
2373118
Port external node storage init to the framework
popzxc Jul 2, 2024
c2b88e3
zk fmt
popzxc Jul 2, 2024
a5ffc3e
Merge branch 'main' into popzxc-init-en-storage
popzxc Jul 2, 2024
2d869cd
Polishing
popzxc Jul 2, 2024
68c4e0d
Merge branch 'main' into popzxc-init-en-storage
popzxc Jul 2, 2024
376bed7
Rework initialization
popzxc Jul 3, 2024
d6274cc
Change box to arc
popzxc Jul 4, 2024
3a91b25
Rename revert to reverter
popzxc Jul 4, 2024
0be4309
Use connection_tagged
popzxc Jul 4, 2024
e5f4ed7
Explicitly use unit type
popzxc Jul 4, 2024
dba8892
is_revert_needed -> last_correct_batch_for_reorg
popzxc Jul 4, 2024
6c2faae
Pass stop receiver to revert check
popzxc Jul 4, 2024
e76a601
Any way to initialize db is fine
popzxc Jul 4, 2024
a40fb89
Merge branch 'main' into popzxc-init-en-storage
popzxc Jul 4, 2024
f13f317
Merge branch 'main' into popzxc-init-en-storage
popzxc Jul 9, 2024
ef7dca2
Adapt to new wiring layer interface
popzxc Jul 9, 2024
3224251
Remove commented code
popzxc Jul 9, 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
Prev Previous commit
Next Next commit
Change box to arc
popzxc committed Jul 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d6274cc6fa48634ae50c11d0e12e36616c96830b
Original file line number Diff line number Diff line change
@@ -64,33 +64,33 @@ impl WiringLayer for ExternalNodeInitStrategyLayer {
Err(err) => return Err(err),
};

let genesis = Box::new(ExternalNodeGenesis {
let genesis = Arc::new(ExternalNodeGenesis {
l2_chain_id: self.l2_chain_id,
client: client.clone(),
pool: pool.clone(),
});
let snapshot_recovery = self.snapshot_recovery_config.map(|recovery_config| {
Box::new(ExternalNodeSnapshotRecovery {
Arc::new(ExternalNodeSnapshotRecovery {
client: client.clone(),
pool: pool.clone(),
recovery_config,
app_health,
}) as Box<dyn InitializeStorage>
}) as Arc<dyn InitializeStorage>
});
let block_reverter = block_reverter.map(|block_reverter| {
Box::new(ExternalNodeRevert {
Arc::new(ExternalNodeRevert {
client,
pool: pool.clone(),
reverter: block_reverter,
}) as Box<dyn RevertStorage>
}) as Arc<dyn RevertStorage>
});
let strategy = NodeInitializationStrategy {
genesis,
snapshot_recovery,
block_reverter,
};

context.insert_resource(NodeInitializationStrategyResource(Arc::new(strategy)))?;
context.insert_resource(NodeInitializationStrategyResource(strategy))?;
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ impl WiringLayer for MainNodeInitStrategyLayer {
.get()
.await?;
let EthInterfaceResource(l1_client) = context.get_resource()?;
let genesis = Box::new(MainNodeGenesis {
let genesis = Arc::new(MainNodeGenesis {
contracts: self.contracts,
genesis: self.genesis,
l1_client,
@@ -53,7 +53,7 @@ impl WiringLayer for MainNodeInitStrategyLayer {
block_reverter: None,
};

context.insert_resource(NodeInitializationStrategyResource(Arc::new(strategy)))?;
context.insert_resource(NodeInitializationStrategyResource(strategy))?;
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use zksync_node_storage_init::{NodeInitializationStrategy, NodeStorageInitializer};

use crate::{
@@ -112,7 +110,7 @@ impl Task for NodeStorageInitializerPrecondition {
// moving the implementations out of the framework soon.
/// Resource representing the node initialization strategy.
#[derive(Debug, Clone)]
pub struct NodeInitializationStrategyResource(Arc<NodeInitializationStrategy>);
pub struct NodeInitializationStrategyResource(NodeInitializationStrategy);

impl Resource for NodeInitializationStrategyResource {
fn name() -> String {
12 changes: 6 additions & 6 deletions core/node/node_storage_init/src/lib.rs
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ enum InitDecision {
SnapshotRecovery,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct NodeInitializationStrategy {
pub genesis: Box<dyn InitializeStorage>,
pub snapshot_recovery: Option<Box<dyn InitializeStorage>>,
pub block_reverter: Option<Box<dyn RevertStorage>>,
pub genesis: Arc<dyn InitializeStorage>,
pub snapshot_recovery: Option<Arc<dyn InitializeStorage>>,
pub block_reverter: Option<Arc<dyn RevertStorage>>,
}

/// Node storage initializer.
@@ -44,12 +44,12 @@ pub struct NodeInitializationStrategy {
/// for the whole system.
#[derive(Debug)]
pub struct NodeStorageInitializer {
strategy: Arc<NodeInitializationStrategy>,
strategy: NodeInitializationStrategy,
pool: ConnectionPool<Core>,
}

impl NodeStorageInitializer {
pub fn new(strategy: Arc<NodeInitializationStrategy>, pool: ConnectionPool<Core>) -> Self {
pub fn new(strategy: NodeInitializationStrategy, pool: ConnectionPool<Core>) -> Self {
Self { strategy, pool }
}