Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat(node): Port (most of) Node to the Node Framework (matter-labs#2196)
Browse files Browse the repository at this point in the history
## What ❔

Ports most of the EN parts to the framework, except:
- Reorg detector
- Genesis / snapshot recovery
- Unique metrics stuff

## Why ❔

This forms the "main" body of the framework-based EN. The binary can
already run, it can proxy and re-execute transactions, etc.
The remaining work may be somewhat complex, so I would like to ship it
separately -- so that it receives thorough review.

There are some TODOs without a task number in this PR, expect them
either to be fixed in the next one, or otherwise an issue to be added.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
popzxc authored Jun 19, 2024
1 parent cb6a6c8 commit 7842bc4
Show file tree
Hide file tree
Showing 38 changed files with 1,569 additions and 154 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ zksync_merkle_tree
TreeMetadata
delegator
decrement
whitelisted
Bbellman
Sbellman
DCMAKE
Expand Down
1 change: 1 addition & 0 deletions core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ zksync_metadata_calculator.workspace = true
zksync_node_sync.workspace = true
zksync_node_api_server.workspace = true
zksync_node_consensus.workspace = true
zksync_node_framework.workspace = true
vlog.workspace = true

zksync_concurrency.workspace = true
Expand Down
31 changes: 27 additions & 4 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::HashSet, net::Ipv4Addr, str::FromStr, sync::Arc, time::Du
use anyhow::Context as _;
use clap::Parser;
use metrics::EN_METRICS;
use node_builder::ExternalNodeBuilder;
use tokio::{
sync::{oneshot, watch, RwLock},
task::{self, JoinHandle},
Expand Down Expand Up @@ -63,6 +64,7 @@ mod config;
mod init;
mod metadata;
mod metrics;
mod node_builder;
#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -426,10 +428,11 @@ async fn run_api(
.build()
.await
.context("failed to build a proxy_cache_updater_pool")?;
task_handles.push(tokio::spawn(tx_proxy.run_account_nonce_sweeper(
proxy_cache_updater_pool.clone(),
stop_receiver.clone(),
)));
task_handles.push(tokio::spawn(
tx_proxy
.account_nonce_sweeper_task(proxy_cache_updater_pool.clone())
.run(stop_receiver.clone()),
));

let fee_params_fetcher_handle =
tokio::spawn(fee_params_fetcher.clone().run(stop_receiver.clone()));
Expand Down Expand Up @@ -701,6 +704,10 @@ struct Cli {
/// Comma-separated list of components to launch.
#[arg(long, default_value = "all")]
components: ComponentsToRun,

/// Run the node using the node framework.
#[arg(long)]
use_node_framework: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Hash, Eq)]
Expand Down Expand Up @@ -784,6 +791,22 @@ async fn main() -> anyhow::Result<()> {
.fetch_remote(main_node_client.as_ref())
.await
.context("failed fetching remote part of node config from main node")?;

// If the node framework is used, run the node.
if opt.use_node_framework {
// We run the node from a different thread, since the current thread is in tokio context.
std::thread::spawn(move || {
let node =
ExternalNodeBuilder::new(config).build(opt.components.0.into_iter().collect())?;
node.run()?;
anyhow::Ok(())
})
.join()
.expect("Failed to run the node")?;

return Ok(());
}

if let Some(threshold) = config.optional.slow_query_threshold() {
ConnectionPool::<Core>::global_config().set_slow_query_threshold(threshold)?;
}
Expand Down
Loading

0 comments on commit 7842bc4

Please sign in to comment.