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(node_framework): Document implementations #2319

Merged
merged 29 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dd04241
Document state keeper layers
popzxc Jun 24, 2024
a4a5d46
Document ProtectiveReadsWriterLayer
popzxc Jun 24, 2024
2e56437
Document API layers
popzxc Jun 24, 2024
ffda008
Document batch status updater layer
popzxc Jun 24, 2024
911cfa9
Adjust previously added docs
popzxc Jun 24, 2024
ec66e9e
Document consensus layer
popzxc Jun 24, 2024
d15d938
Document consistency checker layer
popzxc Jun 24, 2024
f627577
Document house keeper layer
popzxc Jun 24, 2024
6def5af
Merge branch 'main' into popzxc-framework-docs
popzxc Jun 24, 2024
cd79165
Document a layer with an awfully long name
popzxc Jun 24, 2024
5e17987
Document sequencer l1 gas layer
popzxc Jun 25, 2024
bd840bf
Document main node client layer
popzxc Jun 25, 2024
d05f211
Document main node fee params fetcher layer
popzxc Jun 25, 2024
83615b3
Document metadata calculator layer
popzxc Jun 25, 2024
24de043
Document object store layer
popzxc Jun 25, 2024
e343472
Document PK signing eth client layer
popzxc Jun 25, 2024
71cb945
Document pools layer
popzxc Jun 25, 2024
8845878
Document postgres metrics layer
popzxc Jun 25, 2024
6ef78d1
Document prometheus exporter layer
popzxc Jun 25, 2024
0685c39
Document proof data handler layer
popzxc Jun 25, 2024
bc0b13d
Document pruning layer
popzxc Jun 25, 2024
c50f1f6
Document query eth client layer
popzxc Jun 25, 2024
c8dbe3d
Document reorg detector layer
popzxc Jun 25, 2024
4aa4b80
Document sigint layer
popzxc Jun 25, 2024
54f7690
Document sync state updater layer
popzxc Jun 25, 2024
b0c7c8c
Document tee verifier input producer layer
popzxc Jun 25, 2024
b497d86
Document tree data fetcher layer
popzxc Jun 25, 2024
3b64e98
Document validate chain ids layer
popzxc Jun 25, 2024
641c334
Document resources
popzxc Jun 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for `BatchStatusUpdater`, part of the external node.
///
/// ## Requests resources
///
/// - `PoolResource<MasterPool>`
/// - `MainNodeClientResource`
/// - `AppHealthCheckResource` (adds a health check)
///
/// ## Adds tasks
///
/// - `BatchStatusUpdater`
#[derive(Debug)]
pub struct BatchStatusUpdaterLayer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ use crate::{
/// [`zksync_circuit_breaker::CircuitBreakers`] collection using [`CircuitBreakersResource`].
/// The added task periodically runs checks for all inserted circuit breakers.
///
/// ## Adds resources
/// - [`CircuitBreakersResource`]
/// ## Requests resources
///
/// - `CircuitBreakersResource`
///
/// ## Adds tasks
/// - [`CircuitBreakerCheckerTask`] (as [`UnconstrainedTask`])
///
/// - `CircuitBreakerCheckerTask`
#[derive(Debug)]
pub struct CircuitBreakerCheckerLayer(pub CircuitBreakerConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ use crate::{
/// Responsible for initialization and running [`CommitmentGenerator`].
///
/// ## Requests resources
/// - [`PoolResource`] for [`MasterPool`]
/// - [`AppHealthCheckResource`] (to add new health check)
///
/// - `PoolResource<MasterPool>`
/// - `AppHealthCheckResource` (adds a health check)
///
/// ## Adds tasks
/// - [`CommitmentGeneratorTask`] (as [`Task`])
///
/// - `CommitmentGeneratorTask`
#[derive(Debug)]
pub struct CommitmentGeneratorLayer {
mode: L1BatchCommitmentMode,
Expand Down
14 changes: 14 additions & 0 deletions core/node/node_framework/src/implementations/layers/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ pub enum Mode {
External,
}

/// Wiring layer for consensus component.
/// Can work in either "main" or "external" mode.
///
/// ## Requests resources
///
/// - `PoolResource<MasterPool>`
/// - `MainNodeClientResource` (if `Mode::External`)
/// - `SyncStateResource` (if `Mode::External`)
/// - `ActionQueueSenderResource` (if `Mode::External`)
///
/// ## Adds tasks
///
/// - `MainNodeConsensusTask` (if `Mode::Main`)
/// - `FetcherTask` (if `Mode::External`)
#[derive(Debug)]
pub struct ConsensusLayer {
pub mode: Mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for the `ConsistencyChecker` (used by the external node).
///
/// ## Requests resources
///
/// - `EthInterfaceResource`
/// - `PoolResource<MasterPool>`
/// - `AppHealthCheckResource` (adds a health check)
///
/// ## Adds tasks
///
/// - `ConsistencyChecker`
#[derive(Debug)]
pub struct ConsistencyCheckerLayer {
diamond_proxy_addr: Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ use crate::{
/// Responsible for initialization of the contract verification server.
///
/// ## Requests resources
/// - [`PoolResource`] for [`MasterPool`]
/// - [`PoolResource`] for [`ReplicaPool`]
///
/// - `PoolResource<MasterPool>`
/// - `PoolResource<ReplicaPool>`
///
/// ## Adds tasks
/// - [`ContractVerificationApiTask`] (as [`Task`])
///
/// - `ContractVerificationApiTask`
#[derive(Debug)]
pub struct ContractVerificationApiLayer(pub ContractVerifierConfig);

Expand Down
58 changes: 24 additions & 34 deletions core/node/node_framework/src/implementations/layers/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ use crate::{
/// of `eth_txs`(such as `CommitBlocks`, `PublishProofBlocksOnchain` or `ExecuteBlock` ) to L1.
///
/// ## Requests resources
/// - [`PoolResource`] for [`MasterPool`]
/// - [`PoolResource`] for [`ReplicaPool`]
/// - [`BoundEthInterfaceResource`]
/// - [`BoundEthInterfaceForBlobsResource`]
/// - [`L1TxParamsResource`]
/// - [`CircuitBreakersResource`] (to add new circuit breaker)
///
/// - `PoolResource<MasterPool>`
/// - `PoolResource<ReplicaPool>`
/// - `BoundEthInterfaceResource`
/// - `BoundEthInterfaceForBlobsResource` (optional)
/// - `L1TxParamsResource`
/// - `CircuitBreakersResource` (adds a circuit breaker)
///
/// ## Adds tasks
/// - [`EthTxManagerTask`] (as [`Task`])
///
/// - `EthTxManager`
#[derive(Debug)]
pub struct EthTxManagerLayer {
eth_sender_config: EthConfig,
Expand Down Expand Up @@ -79,9 +81,7 @@ impl WiringLayer for EthTxManagerLayer {
eth_client_blobs,
);

context.add_task(Box::new(EthTxManagerTask {
eth_tx_manager_actor,
}));
context.add_task(Box::new(eth_tx_manager_actor));

// Insert circuit breaker.
let CircuitBreakersResource { breakers } = context.get_resource_or_default().await;
Expand All @@ -100,15 +100,17 @@ impl WiringLayer for EthTxManagerLayer {
/// These `eth_txs` will be used as a queue for generating signed txs and will be sent later on L1.
///
/// ## Requests resources
/// - [`PoolResource`] for [`MasterPool`]
/// - [`PoolResource`] for [`ReplicaPool`]
/// - [`BoundEthInterfaceResource`]
/// - [`BoundEthInterfaceForBlobsResource`]
/// - [`ObjectStoreResource`]
/// - [`CircuitBreakersResource`] (to add new circuit breaker)
///
/// - `PoolResource<MasterPool>`
/// - `PoolResource<ReplicaPool>`
/// - `BoundEthInterfaceResource`
/// - `BoundEthInterfaceForBlobsResource` (optional)
/// - `ObjectStoreResource`
/// - `CircuitBreakersResource` (adds a circuit breaker)
///
/// ## Adds tasks
/// - [`EthTxAggregatorTask`] (as [`Task`])
///
/// - `EthTxAggregator`
#[derive(Debug)]
pub struct EthTxAggregatorLayer {
eth_sender_config: EthConfig,
Expand Down Expand Up @@ -183,9 +185,7 @@ impl WiringLayer for EthTxAggregatorLayer {
)
.await;

context.add_task(Box::new(EthTxAggregatorTask {
eth_tx_aggregator_actor,
}));
context.add_task(Box::new(eth_tx_aggregator_actor));

// Insert circuit breaker.
let CircuitBreakersResource { breakers } = context.get_resource_or_default().await;
Expand All @@ -197,34 +197,24 @@ impl WiringLayer for EthTxAggregatorLayer {
}
}

#[derive(Debug)]
struct EthTxAggregatorTask {
eth_tx_aggregator_actor: EthTxAggregator,
}

#[async_trait::async_trait]
impl Task for EthTxAggregatorTask {
impl Task for EthTxAggregator {
fn id(&self) -> TaskId {
"eth_tx_aggregator".into()
}

async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> {
self.eth_tx_aggregator_actor.run(stop_receiver.0).await
(*self).run(stop_receiver.0).await
}
}

#[derive(Debug)]
struct EthTxManagerTask {
eth_tx_manager_actor: EthTxManager,
}

#[async_trait::async_trait]
impl Task for EthTxManagerTask {
impl Task for EthTxManager {
fn id(&self) -> TaskId {
"eth_tx_manager".into()
}

async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> {
self.eth_tx_manager_actor.run(stop_receiver.0).await
(*self).run(stop_receiver.0).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ use crate::{
/// such as priority operations (aka L1 transactions), protocol upgrades etc.
///
/// ## Requests resources
/// - [`PoolResource`] for [`MasterPool`]
/// - [`EthInterfaceResource`]
///
/// - `PoolResource<MasterPool>`
/// - `EthInterfaceResource`
///
/// ## Adds tasks
/// - [`EthWatchTask`] (as [`Task`])
///
/// - `EthWatchTask`
#[derive(Debug)]
pub struct EthWatchLayer {
eth_watch_config: EthWatchConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use crate::{
/// into [`AppHealthCheck`] aggregating heath using [`AppHealthCheckResource`].
/// The added task spawns a health check server that only exposes the state provided by other tasks.
///
/// ## Adds resources
/// - [`AppHealthCheckResource`]
/// ## Requests resources
///
/// - `AppHealthCheckResource`
///
/// ## Adds tasks
/// - [`HealthCheckTask`] (as [`UnconstrainedTask`])
///
/// - `HealthCheckTask`
#[derive(Debug)]
pub struct HealthCheckLayer(pub HealthCheckConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for `HouseKeeper` - a component responsible for managing prover jobs
/// and auxiliary server activities.
///
/// ## Requests resources
///
/// - `PoolResource<ReplicaPool>`
/// - `PoolResource<ProverPool>`
///
/// ## Adds tasks
///
/// - `L1BatchMetricsReporterTask`
/// - `FriProverJobRetryManagerTask`
/// - `FriWitnessGeneratorJobRetryManagerTask`
/// - `WaitingToQueuedFriWitnessJobMoverTask`
/// - `FriProverJobArchiverTask`
/// - `FriProverGpuArchiverTask`
/// - `FriWitnessGeneratorStatsReporterTask`
/// - `FriProverStatsReporterTask`
/// - `FriProofCompressorStatsReporterTask`
/// - `FriProofCompressorJobRetryManagerTask`
#[derive(Debug)]
pub struct HouseKeeperLayer {
house_keeper_config: HouseKeeperConfig,
Expand Down Expand Up @@ -54,14 +74,14 @@ impl WiringLayer for HouseKeeperLayer {
}

async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> {
// initialize resources
// Initialize resources
let replica_pool_resource = context.get_resource::<PoolResource<ReplicaPool>>().await?;
let replica_pool = replica_pool_resource.get().await?;

let prover_pool_resource = context.get_resource::<PoolResource<ProverPool>>().await?;
let prover_pool = prover_pool_resource.get().await?;

// initialize and add tasks
// Initialize and add tasks
let l1_batch_metrics_reporter = L1BatchMetricsReporter::new(
self.house_keeper_config
.l1_batch_metrics_reporting_interval_ms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for a prerequisite that checks if the L1 batch commitment mode is valid
/// against L1.
///
/// ## Requests resources
///
/// - `EthInterfaceResource`
///
/// ## Adds preconditions
///
/// - `L1BatchCommitmentModeValidationTask`
#[derive(Debug)]
pub struct L1BatchCommitmentModeValidationLayer {
diamond_proxy_addr: Address,
Expand Down
15 changes: 15 additions & 0 deletions core/node/node_framework/src/implementations/layers/l1_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for sequencer L1 gas interfaces.
/// Adds several resources that depend on L1 gas price.
///
/// ## Requests resources
///
/// - `EthInterfaceResource`
///
/// ## Adds resources
///
/// - `FeeInputResource`
/// - `L1TxParamsResource`
///
/// ## Adds tasks
///
/// - `GasAdjusterTask` (only runs if someone uses the resourced listed above).
#[derive(Debug)]
pub struct SequencerL1GasLayer {
gas_adjuster_config: GasAdjusterConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for main node client.
///
/// ## Requests resources
///
/// - `AppHealthCheckResource` (adds a health check)
///
/// ## Adds resources
///
/// - `MainNodeClientResource`
#[derive(Debug)]
pub struct MainNodeClientLayer {
url: SensitiveUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ use crate::{
wiring_layer::{WiringError, WiringLayer},
};

/// Wiring layer for main node fee params fetcher -- a fee input resource used on
/// the external node.
///
/// ## Requests resources
///
/// - `MainNodeClientResource`
///
/// ## Adds resources
///
/// - `FeeInputResource`
///
/// ## Adds tasks
///
/// - `MainNodeFeeParamsFetcherTask`
#[derive(Debug)]
pub struct MainNodeFeeParamsFetcherLayer;

Expand Down
Loading
Loading