-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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): Switch EN to use node framework #2427
Merged
+982
−528
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e257300
Make it possible to override health check time limits
popzxc b256197
Add EN metrics as a layer
popzxc b367bf2
Adapt tests to use framework & remove db health check
popzxc b20460a
Initialize rust metrics
popzxc 8f24c1d
Refactor tests
popzxc 2b76476
Add more tests for node builder
popzxc 806cb40
Add a way to still run the EN old way
popzxc e476b5d
zk fmt
popzxc ab2067d
Remove development artifact
popzxc 8b199ed
Initialize L1BatchParamsProvider explicitly
popzxc a00ed86
Rework eth_syncing integration test
popzxc c0440d8
Rework eth_syncing integration test
popzxc 7098e02
Add block reverter layer
popzxc a31b245
Set correct type for test sigint task
popzxc cb05111
Tests: Move building mock clients to utils
popzxc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::time::Duration; | ||
|
||
use zksync_dal::{ConnectionPool, Core, CoreDal as _}; | ||
use zksync_node_framework::{ | ||
implementations::resources::pools::{MasterPool, PoolResource}, | ||
FromContext, IntoContext, StopReceiver, Task, TaskId, WiringError, WiringLayer, | ||
}; | ||
use zksync_shared_metrics::rustc::RUST_METRICS; | ||
use zksync_types::{L1ChainId, L2ChainId}; | ||
|
||
use super::EN_METRICS; | ||
|
||
#[derive(Debug)] | ||
pub struct ExternalNodeMetricsLayer { | ||
popzxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub l1_chain_id: L1ChainId, | ||
pub l2_chain_id: L2ChainId, | ||
pub postgres_pool_size: u32, | ||
} | ||
|
||
#[derive(Debug, FromContext)] | ||
pub struct Input { | ||
pub master_pool: PoolResource<MasterPool>, | ||
} | ||
|
||
#[derive(Debug, IntoContext)] | ||
pub struct Output { | ||
#[context(task)] | ||
pub task: ProtocolVersionMetricsTask, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for ExternalNodeMetricsLayer { | ||
type Input = Input; | ||
type Output = Output; | ||
|
||
fn layer_name(&self) -> &'static str { | ||
"external_node_metrics" | ||
} | ||
|
||
async fn wire(self, input: Self::Input) -> Result<Self::Output, WiringError> { | ||
RUST_METRICS.initialize(); | ||
EN_METRICS.observe_config(self.l1_chain_id, self.l2_chain_id, self.postgres_pool_size); | ||
|
||
let pool = input.master_pool.get_singleton().await?; | ||
let task = ProtocolVersionMetricsTask { pool }; | ||
Ok(Output { task }) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ProtocolVersionMetricsTask { | ||
pool: ConnectionPool<Core>, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Task for ProtocolVersionMetricsTask { | ||
fn id(&self) -> TaskId { | ||
"en_protocol_version_metrics".into() | ||
} | ||
|
||
async fn run(self: Box<Self>, mut stop_receiver: StopReceiver) -> anyhow::Result<()> { | ||
const QUERY_INTERVAL: Duration = Duration::from_secs(10); | ||
|
||
while !*stop_receiver.0.borrow_and_update() { | ||
let maybe_protocol_version = self | ||
.pool | ||
.connection() | ||
.await? | ||
.protocol_versions_dal() | ||
.last_used_version_id() | ||
.await; | ||
if let Some(version) = maybe_protocol_version { | ||
EN_METRICS.protocol_version.set(version as u64); | ||
} | ||
|
||
tokio::time::timeout(QUERY_INTERVAL, stop_receiver.0.changed()) | ||
.await | ||
.ok(); | ||
} | ||
Ok(()) | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's incompatible, have you checked, that we don't use it in gitops ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. EN wasn't fully ported to the framework until this PR, it wouldn't have worked with it