forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-framework): Add circuit breaker checker layer to framework (m…
…atter-labs#1452) Key thing to note - no more circuit breaker channel for signalling about check failure. Instead, make the circuit breaker a part of the other tasks and return an error instead of a signal throw channel. Motivation - framework design requires it. ## What ❔ Port circuit breaker checker to the framework ## Why ❔ these changes is a part of the system porting process to the framework ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `zk spellcheck`. - [x] Linkcheck has been run via `zk linkcheck`.
- Loading branch information
1 parent
8c26a7a
commit 2c7a6bf
Showing
14 changed files
with
202 additions
and
64 deletions.
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
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
56 changes: 56 additions & 0 deletions
56
core/node/node_framework/src/implementations/layers/circuit_breaker_checker.rs
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,56 @@ | ||
use zksync_circuit_breaker::CircuitBreakerChecker; | ||
use zksync_config::configs::chain::CircuitBreakerConfig; | ||
|
||
use crate::{ | ||
implementations::resources::circuit_breakers::CircuitBreakersResource, | ||
service::{ServiceContext, StopReceiver}, | ||
task::UnconstrainedTask, | ||
wiring_layer::{WiringError, WiringLayer}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct CircuitBreakerCheckerLayer(pub CircuitBreakerConfig); | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for CircuitBreakerCheckerLayer { | ||
fn layer_name(&self) -> &'static str { | ||
"circuit_breaker_checker_layer" | ||
} | ||
|
||
async fn wire(self: Box<Self>, mut node: ServiceContext<'_>) -> Result<(), WiringError> { | ||
// Get resources. | ||
let circuit_breaker_resource = node | ||
.get_resource_or_default::<CircuitBreakersResource>() | ||
.await; | ||
|
||
let circuit_breaker_checker = | ||
CircuitBreakerChecker::new(circuit_breaker_resource.breakers, self.0.sync_interval()); | ||
|
||
// Create and insert task. | ||
let task = CircuitBreakerCheckerTask { | ||
circuit_breaker_checker, | ||
}; | ||
|
||
node.add_unconstrained_task(Box::new(task)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
struct CircuitBreakerCheckerTask { | ||
circuit_breaker_checker: CircuitBreakerChecker, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl UnconstrainedTask for CircuitBreakerCheckerTask { | ||
fn name(&self) -> &'static str { | ||
"circuit_breaker_checker" | ||
} | ||
|
||
async fn run_unconstrained( | ||
mut self: Box<Self>, | ||
stop_receiver: StopReceiver, | ||
) -> anyhow::Result<()> { | ||
self.circuit_breaker_checker.run(stop_receiver.0).await | ||
} | ||
} |
Oops, something went wrong.