> For the complete documentation index, see [llms.txt](https://docs.zetrix.com/zetrix-l2-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zetrix.com/zetrix-l2-documentation/architecture/system-components.md). Agents can also search and read this documentation through its [MCP server](https://docs.zetrix.com/zetrix-l2-documentation/~gitbook/mcp).

# System Components

Each component below documents its **Purpose, Responsibilities, Inputs, Outputs, Dependencies, Internal workflow, Interaction with other components, Deployment, HA, Scalability, Security, Monitoring, Failure scenarios, Recovery, Performance, and Best practices**, per the platform documentation standard.

***

## Z2 Node

### Purpose

The Z2 Node is the execution engine of the L2. It maintains the L2 ledger, runs the EVM, holds the mempool, serves JSON-RPC to clients, and participates in **QBFT** consensus for block production.

### Responsibilities

* Accept and validate incoming transactions; maintain the mempool.
* Execute transactions on the EVM and produce blocks.
* Participate in QBFT consensus with peer nodes.
* Serve JSON-RPC / WebSocket RPC to wallets, dApps, Explorer, and tooling.
* Maintain and serve chain state and historical data.

### Inputs / Outputs

| Inputs                                                                           | Outputs                                   |
| -------------------------------------------------------------------------------- | ----------------------------------------- |
| Signed transactions (RPC), peer blocks/consensus messages, deposits from Relayer | Blocks, state, RPC responses, events/logs |

### Dependencies

* Peer Z2 Nodes (QBFT quorum).
* Sequencers (each reads the blocks from its own Z2 Node and batches them).
* Relayer (L1→L2 deposit injection).

### Network Topology & Consensus (QBFT)

Z2 Nodes run **Hyperledger Besu with QBFT (Byzantine Fault Tolerant)** consensus and a **5-second block period** to produce the canonical block stream. Batches are re-executed independently by the **Z2 Reexecutor** to verify assertions (see [Z2 Reexecutor](#z2-reexecutor)). QBFT is a proof-of-authority BFT protocol tolerating up to `f` faulty nodes in a network of `3f + 1`.

**Current deployment: 5 Besu QBFT nodes** (`hyperledger/besu` 26.9.0 image; the genesis file's `qbft` section sets the 5-second block period). With `n = 5`, the network tolerates `f = 1` Byzantine/faulty node (`3(1)+1 = 4 ≤ 5`), requiring a quorum of `ceil(2n/3) = 4` nodes to finalize a block.

> \[!NOTE] **Sync-only nodes.** You can run a Z2 Node on its own to sync and serve the chain. A sync-only node needs no committee, validator or reexecutor. Only committee operators deploy the full bundle (Z2 Node + Z2 Validator).

```mermaid
flowchart LR
    N1[Besu Node 1] --- N2[Besu Node 2]
    N2 --- N3[Besu Node 3]
    N3 --- N4[Besu Node 4]
    N4 --- N5[Besu Node 5]
    N5 --- N1
    N1 --- N3
    N2 --- N4
    N3 --- N5
    N4 --- N1
    N5 --- N2
```

### Synchronization

* New nodes sync from peers (full sync of blocks and state).
* QBFT provides immediate finality per block (no probabilistic reorg under honest quorum).

### RPC Services

* `eth_*` JSON-RPC methods (EVM standard).
* WebSocket subscriptions (`eth_subscribe`) for new heads, logs, pending tx.
* Served behind the AWS NLB (see [Networking](https://docs.zetrix.com/zetrix-l2-documentation/network-and-deployment/networking.md#networking)).

### Deployment

* 5 Besu QBFT nodes (Testnet). Each committee bundle also runs a Z2 Node; sync-only nodes can be added by any operator.
* Each node exposes RPC and P2P ports (see [Appendix ports](https://docs.zetrix.com/zetrix-l2-documentation/reference/appendix.md#ports-reference)).

### High Availability

* 5-node QBFT quorum survives loss of 1 node with no downtime.
* RPC fronted by NLB with health checks; unhealthy nodes are removed from rotation.

### Scalability

* **Read scaling:** add non-validating RPC/full nodes behind the load balancer.
* **Write scaling:** bounded by QBFT quorum; vertical scaling of validator nodes and mempool tuning.

### Security

* P2P restricted to known validator peers.
* RPC exposure limited to safe method sets on public endpoints; admin/debug namespaces restricted to internal networks.

### Monitoring

* Block height, peer count, QBFT round changes, mempool size, RPC latency/error rate.

### Failure Scenarios & Recovery

| Failure         | Effect                      | Recovery                               |
| --------------- | --------------------------- | -------------------------------------- |
| 1 node down     | No downtime (quorum intact) | Restart / redeploy node; resync        |
| 2+ nodes down   | Consensus halts             | Restore quorum; investigate root cause |
| Corrupted state | Node cannot validate        | Resync from healthy peers / snapshot   |

### Performance Considerations

* I/O-bound on state DB — prefer NVMe SSD.
* Tune mempool and RPC worker pools for expected TPS.

### Best Practices

* Keep an odd, `3f+1`-shaped validator set.
* Separate public RPC nodes from consensus validators.
* Automate snapshot backups of chain data.

***

## Z2 Sequencer

### Purpose

The Sequencer does **not** order transactions or produce blocks — the **Z2 Nodes** (Hyperledger Besu, QBFT) do that. Each Sequencer **reads the L2 blocks from its own Z2 Node**, packs them into **batches**, sends the batch data to the committee's DA, and posts the commitment to the L1 **Sequencer Inbox** — with the batch data made available via the DAC (AnyTrust), or as L1 calldata on fallback.

### Responsibilities

* Read the canonical L2 blocks from its own Z2 Node (block ordering and production are done by the nodes under QBFT).
* Create batches (compress and package the blocks' transactions + metadata).
* Send each batch's data to the **five committee members** and collect their attestations.
* With **3 attestations**, build the **data certificate** and post the commitment to the **L1 Sequencer Inbox**.
* Make batch data available: the **DAC** attests it in the normal path; **fall back to posting full batch data as L1 calldata** if the committee can't reach its attestation threshold.
* **Self-healing batch posting** — retry/recover posting without manual intervention.

> \[!NOTE] AnyTrust: the Sequencer keeps data off-chain via the DAC in the normal path but **falls back to L1 calldata** so data is never silently lost. See [Data Availability Committee (DAC) — AnyTrust](https://docs.zetrix.com/zetrix-l2-documentation/architecture/trust-model.md#data-availability-committee-dac--anytrust).

### Deployment (clarification)

* **3 sequencers, each reading its own Z2 Node**, with active/standby failover and self-healing batch posting (matches the "3 servers" figure).
* All three run in **committee data-availability mode**: 5 members, threshold 3. Recent testnet batches carry certificates built from five attestations.

### Batch Creation

A batch bundles a contiguous range of L2 transactions with metadata (batch number, parent reference, state root, timestamp). Batching amortizes L1 posting cost across many transactions.

### Batch Submission & Interaction with L1

```mermaid
sequenceDiagram
    participant Seq as Sequencer
    participant DAC as Committee DA (5 members)
    participant L1 as Zetrix L1 (Sequencer Inbox)
    participant Prop as Proposer
    participant Agg as Aggregator
    Seq->>Seq: read own node, build batch
    Seq->>DAC: send batch data
    DAC-->>Seq: attestations (3 needed)
    Seq->>L1: post commitment + data certificate
    Prop->>Prop: replay batches with own reexecutor
    Prop->>L1: propose assertion (Rollup)
    Agg->>L1: soft confirmation at 3 of 5 (Rollup)
```

### Inputs / Outputs

| Inputs                              | Outputs                                         |
| ----------------------------------- | ----------------------------------------------- |
| L2 blocks read from its own Z2 Node | Batches, batch metadata, L1 submission payloads |

### Dependencies

* Z2 Nodes (transaction source).
* Committee (validation).
* Proposer / L1 (settlement).
* Refueler (gas top-up of the Sequencer EOAs).

### Deployment

* **Current deployment: 3 servers.** Active/standby configuration for HA; only one Sequencer is canonical at a time.

### High Availability

* 3 servers enable active + warm-standby.
* Leader election / failover promotes a standby if the active Sequencer fails.

> \[!WARNING] Two active Sequencers posting conflicting batches for the same blocks is a **split-brain** hazard. Failover must guarantee a single canonical batch poster at any time (fencing / lease-based leadership).

### Scalability

* Vertical scaling for ordering throughput.
* Batch size / frequency tuning to balance latency vs. L1 cost.

### Security

* Sequencer signing key must be protected (HSM / KMS).
* Restricted network access; only authenticated pipeline peers.

### Monitoring

* Batch production rate, batch size, submission latency, L1 posting success, Sequencer EOA balance.

### Failure Scenarios & Recovery

| Failure                | Effect           | Recovery                                |
| ---------------------- | ---------------- | --------------------------------------- |
| Active Sequencer crash | Ordering pauses  | Promote standby; resume from last batch |
| L1 submission failure  | Batches queue    | Retry with backoff; alert; drain queue  |
| Low gas on EOA         | Submissions fail | Refueler auto top-up; alert             |

### Performance Considerations

* Batch cadence directly affects soft-confirmation latency and L1 cost.

### Best Practices

* Idempotent batch submission with sequence numbers.
* Monitored, automated failover with fencing.

***

## Z2 Validator

### Purpose

Validators form the **Committee** that checks the Proposer's assertion, produces the signatures for **soft confirmation**, and — via the **Aggregator** role — submits the soft confirmation to the Rollup.

> \[!NOTE] Each committee member is a **bundle of a Z2 Node and a Z2 Validator** (committee and aggregator roles) with its own copy of the batch data. The five validators do **not** each run a reexecutor: they check every assertion with **one shared Z2 Reexecutor**. The Main Validator and every Watcher run their own reexecutor.

### Committee Role

* Have the **shared Reexecutor** replay the same batches the Proposer replayed.
* **Sign the Proposer's assertion only if the result matches** — ordering, execution, resulting state root.
* Share the signature **off-chain over the committee's gossip bus**; members do not send their own L1 transaction to sign.
* Require **3-of-5** signatures to soft-confirm.
* Hold a copy of the batch data and attest to it for the Sequencers (DA).

### Aggregator Role

* Collect the committee signatures from the gossip bus.
* Once **3 of 5** agree, **submit the soft confirmation to the Rollup** on L1.

### Deployment Note

* **5 committee bundles (Z2 Node + Z2 Validator), each on its own server; the shared Reexecutor runs alongside them. At least five servers are needed for the bundles. 3-of-5 required for voting.**

### Validation Process

```mermaid
flowchart TD
    A["Proposer proposes<br/>assertion"] --> B["Shared Reexecutor<br/>replays the batches"]
    B --> D{"State root matches<br/>assertion?"}
    D -->|Yes| E["Sign assertion<br/>(off-chain)"]
    D -->|No| F["Do not sign"]
    E --> G["Share signature<br/>over gossip bus"]
    G --> H{"3-of-5 collected?"}
    H -->|Yes| I["Aggregator submits<br/>soft confirmation to Rollup"]
    H -->|No| J["Wait for 3-of-5"]
```

### Signing the Assertion & Soft Confirmation

Each Validator signs the **Proposer's assertion** only after the shared Reexecutor has replayed the batches and the result matches. Signatures travel over the gossip bus; when **3 of 5** agree, the aggregator submits the **soft confirmation** to the Rollup. On the testnet one committee verification takes about 1.4 seconds.

### Inputs / Outputs

| Inputs                                         | Outputs                                                                            |
| ---------------------------------------------- | ---------------------------------------------------------------------------------- |
| Proposed assertion; batch data from Sequencers | Off-chain signatures (gossip bus); one soft-confirmation transaction on the Rollup |

### Dependencies

* Sequencers (batch data source).
* Shared Z2 Reexecutor (deterministic verification).
* Gossip bus (signature exchange).
* Refueler (gas top-up of the EOA that submits soft confirmations).

### Deployment

* **Current deployment: 5 servers**, each running a **Z2 Node + Z2 Validator** bundle in the **Committee and Aggregator** role, plus the **shared Z2 Reexecutor** alongside them.

### High Availability

* 5-member Committee tolerates member outages while retaining quorum.
* Every bundle carries the aggregator role, so another member can submit if one aggregator fails.
* The shared Reexecutor serves all five validators; if it is unavailable, no member can verify and soft confirmations pause until it returns. L1 final confirmation is unaffected.

### Scalability

* Add Committee members to increase decentralization (trade-off: signature/coordination overhead — mitigated by aggregation).

### Security

* Each Validator holds an independent signing key (HSM/KMS recommended).
* No blind co-signing: a validator signs only if the **shared Reexecutor's** replay matches the proposed assertion.
* The five validators share **one** Reexecutor, so their checks are **not independent** — a fault in the shared Reexecutor affects all five. The independent check is provided by the **Watchers**, each with its own Reexecutor, during the challenge window.

### Monitoring

* Signature participation rate, validation latency, disagreement/flag events, member liveness, EOA balances.

### Failure Scenarios & Recovery

| Failure                | Effect                                         | Recovery                                             |
| ---------------------- | ---------------------------------------------- | ---------------------------------------------------- |
| 1–2 members down       | Quorum may hold                                | Restart members; investigate                         |
| Quorum lost            | No soft confirmations                          | Restore members; fall back to L1 finality            |
| Aggregator down        | No soft-confirm transaction                    | Another bundle's validator takes the aggregator role |
| Shared Reexecutor down | No member can verify; soft confirmations pause | Restore the Reexecutor; L1 finality continues        |

### Performance Considerations

* Validation cost is dominated by re-execution in the shared Reexecutor (about 1.4 s per verification on the testnet).

### Best Practices

* Keep validation logic byte-for-byte identical to node execution.
* Diverse hosting to avoid correlated failure.

***

## Z2 Reexecutor

### Purpose

The Reexecutor deterministically replays the batched blocks to verify the resulting state, independently of the node that produced them. It underpins the Proposer, the Committee and the fraud-detection process.

> \[!NOTE] **Who runs a Reexecutor.** The **Committee shares one Reexecutor** across its five validators. The **Main Validator** and **every Watcher** run their own. Sync-only nodes need none.

### Responsibilities

* Replay each transaction in a batch against the prior state.
* Produce the resulting state root deterministically.
* Compare against the claimed/asserted state root.
* Report verification results to Validators.

### Transaction Replay & Deterministic Execution

Given identical batch data, prior state, and EVM rules, re-execution is deterministic — the same inputs must yield the same state root. This determinism is the foundation of fraud detection.

```mermaid
flowchart LR
    IN["Batch + prior state"] --> EXEC["Deterministic<br/>EVM replay"]
    EXEC --> ROOT["Computed<br/>state root"]
    ROOT --> CMP{"== claimed root?"}
    CMP -->|yes| OK["Verified"]
    CMP -->|no| BAD["Discrepancy —<br/>flag fraud"]
```

### Verification & Interaction with Validator

The Reexecutor is the "second opinion" for Validators. The Proposer replays the new batches with its own Reexecutor before proposing; the committee validators rely on the shared Reexecutor to sign with confidence; and Watchers run the same replay independently to detect fraud.

### Inputs / Outputs

| Inputs                  | Outputs                                   |
| ----------------------- | ----------------------------------------- |
| Batch data, prior state | Computed state root, verification verdict |

### Dependencies

* Batch/state data availability.
* Validators (consumer of verdicts).

### Deployment

* **Committee:** one shared Reexecutor runs alongside the five committee bundles.
* **Main Validator:** its own Reexecutor.
* **Watchers:** each its own Reexecutor; packaged as a standalone Docker image (`zetrixchain/z2-reexecutor:latest`).

### High Availability

* Stateless w\.r.t. long-term storage (recomputes from inputs).
* The committee's shared Reexecutor serves all five validators, so its availability gates soft confirmations; keep it monitored and quickly restartable.

### Scalability

* Scale horizontally: run many Reexecutor instances in parallel across batches.

### Security

* Must use the exact EVM ruleset/version as production nodes to avoid false positives/negatives.

### Monitoring

* Replay throughput, discrepancy count, replay latency, version/ruleset hash.

### Failure Scenarios & Recovery

| Failure                                   | Effect                                              | Recovery                          |
| ----------------------------------------- | --------------------------------------------------- | --------------------------------- |
| Committee's shared Reexecutor down        | No committee verification; soft confirmations pause | Restart it; L1 finality continues |
| Proposer's or a Watcher's Reexecutor down | That party cannot replay                            | Restart it                        |
| Ruleset mismatch                          | False discrepancies                                 | Pin exact EVM version; redeploy   |

### Performance Considerations

* CPU-bound; benefits from parallelism across batches.

### Best Practices

* Pin and verify the EVM ruleset hash across all Reexecutors.
* Run independent Reexecutors for Watchers (do not share infra with Validators).

***

## Main Proposer Validator

### Purpose

The Main Proposer Validator proposes and submits **assertions** (L2 state commitments) to Zetrix L1, bridging verified L2 state to L1 settlement. It runs as a **Z2 Validator + Z2 Reexecutor** pair operating in the **Proposer and Watcher** role.

> \[!NOTE] The Main Proposer node also runs the internal **Watcher** role: it independently re-executes (via its co-located Reexecutor) and can dispute mismatched data. This is the same role that external parties run (see [Watcher](#watcher)) — the internal Proposer is simply the first, always-on watcher. The 1-of-N safety assumption still depends on **independent external** watchers.

### Assertion Proposal & Submission

```mermaid
sequenceDiagram
    participant L1 as Zetrix L1
    participant DAC as Committee DA
    participant Prop as Main Proposer
    participant Rex as Own Reexecutor
    participant Agg as Committee aggregator
    Prop->>L1: read batch commitment (Sequencer Inbox)
    Prop->>DAC: read batch data
    Prop->>Rex: replay the new batches
    Rex-->>Prop: resulting state root
    Prop->>L1: propose assertion (Rollup)
    Agg->>L1: soft confirmation at 3 of 5 (Rollup)
    Note over L1: challenge window opens (120 s on testnet)
```

### Responsibilities

* Read the batch commitment (Sequencer Inbox) and data (DAC), and **replay the new batches with its own Reexecutor**.
* **Propose** the resulting state as an assertion on the **Rollup** (the Committee then soft-confirms it).
* Run an internal **Watcher** role (re-execute and dispute).
* Track challenge windows and finalization status.

### Inputs / Outputs

| Inputs                                 | Outputs                   |
| -------------------------------------- | ------------------------- |
| Verified state roots, batch references | L1 assertion transactions |

### Dependencies

* Reexecutors/Validators (verified input).
* Zetrix L1 (settlement target).
* Refueler (gas top-up of Proposer EOA).

### Deployment

* **Current deployment: 1 server** (Z2 Validator + Z2 Reexecutor, Proposer + Watcher role).

> \[!WARNING] A single Proposer is a **liveness** single point (assertions stall if it is down) but **not** a safety single point — an invalid assertion is caught by Watchers. Production should add standby Proposers with failover.

### High Availability

* Recommend warm standby Proposer with leader election for production.

### Scalability

* Single logical Proposer suffices; throughput bound by L1 posting cadence, not Proposer count.

### Security

* Proposer key is high-value — protect with HSM/KMS.
* Monitor Proposer EOA gas balance (Refueler-managed).

### Monitoring

* Assertion submission rate/success, L1 confirmation, challenge status, EOA balance.

### Failure Scenarios & Recovery

| Failure            | Effect                              | Recovery                     |
| ------------------ | ----------------------------------- | ---------------------------- |
| Proposer down      | Assertions stall (finality delayed) | Failover to standby; restart |
| L1 posting failure | Assertions queue                    | Retry/backoff; alert         |
| Low gas            | Submissions fail                    | Refueler top-up              |

### Best Practices

* Add standby Proposer before mainnet.
* Alert aggressively on assertion staleness.

***

## Watcher

### Purpose

Watchers provide the **safety** guarantee of the optimistic model: they independently re-execute batches, compare against on-chain assertions, and **dispute** invalid assertions during the challenge window.

### Independent Verification

A Watcher runs its own Validator + Reexecutor stack, reads the L1 assertion, **fetches the batch data from the DAC**, re-executes, and compares state roots — trusting nothing from the Sequencer, Committee, or Proposer.

### Incentive

External users can participate as Watchers to detect any mismatch posted by the main validator, and **earn a reward from a successful dispute** by being an honest validator. This reward is what makes the 1-of-N honest assumption economically self-sustaining.

### Dispute Process

```mermaid
flowchart TD
    A["Read L1 assertion"] --> B["Fetch batch data<br/>from DAC"]
    B --> C["Independently<br/>re-execute"]
    C --> D{"Root matches?"}
    D -->|yes| E["No action"]
    D -->|no| F["Open dispute on<br/>Challenger (L1)"]
    F --> G["L1 dispute<br/>game resolves"]
    G --> H["Honest watcher<br/>earns reward"]
```

### External / Third-Party Watcher Deployment

Anyone can operate a Watcher — this is by design and strengthens the network's safety. Third parties run the published Docker images with no need for permission.

### Docker Deployment

**Available images:**

* `zetrixchain/z2-validator:latest`
* `zetrixchain/z2-reexecutor:latest`

Example (illustrative) compose fragment:

```yaml
# docker-compose.watcher.yml
services:
  reexecutor:
    image: zetrixchain/z2-reexecutor:latest
    environment:
      - L1_RPC=https://<zetrix-l1-rpc>
      - L2_RPC=https://z2-test-node.zetrix.com   # production: https://z2-node.zetrix.com
      - MODE=watcher
    restart: unless-stopped

  validator:
    image: zetrixchain/z2-validator:latest
    environment:
      - L1_RPC=https://<zetrix-l1-rpc>
      - L2_RPC=https://z2-test-node.zetrix.com   # production: https://z2-node.zetrix.com
      - REEXECUTOR_URL=http://reexecutor:8547
      - ROLE=watcher            # verify-and-dispute only
    depends_on:
      - reexecutor
    restart: unless-stopped
```

```bash
docker pull zetrixchain/z2-validator:latest
docker pull zetrixchain/z2-reexecutor:latest
docker compose -f docker-compose.watcher.yml up -d
```

> \[!NOTE] Configuration keys above are illustrative placeholders. Consult the component's `--help` / environment reference in the image for the authoritative variable names before production use.

### How Third Parties Operate a Watcher

1. Pull the two images.
2. Configure L1 and L2 RPC endpoints and a dispute-capable L1 account (for gas to submit disputes).
3. Run in `watcher` mode (verify only; no batch signing authority required for safety).
4. Monitor discrepancy alerts; the stack disputes automatically or notifies operators to dispute.

### Inputs / Outputs

| Inputs                       | Outputs                                        |
| ---------------------------- | ---------------------------------------------- |
| L1 assertions, L2 batch data | Verification verdicts; disputes (fraud proofs) |

### Dependencies

* L1 RPC, L2 RPC (or batch data source), gas-funded L1 account for disputes.

### High Availability

* Run multiple independent Watchers (different operators, regions, infra) — the more, the safer.

### Security

* Watcher must use the exact EVM ruleset to avoid false disputes.
* Protect the dispute account key; keep it funded.

### Monitoring

* Assertions checked, discrepancies found, disputes submitted, lag behind chain head.

### Failure Scenarios & Recovery

| Failure           | Effect                    | Recovery                                |
| ----------------- | ------------------------- | --------------------------------------- |
| Watcher down      | Reduced safety redundancy | Restart; encourage more operators       |
| All Watchers down | Safety assumption at risk | Multiple independent operators mitigate |

### Best Practices

* **Decentralize Watchers** across independent parties.
* Keep dispute account funded and monitored.

***

## Z2 Refueler

### Purpose

The Refueler monitors critical operational **EOAs** (externally owned accounts) and automatically tops them up with gas so that the Sequencers, the Aggregator, and the Proposer never stall for lack of funds. (Committee members sign off-chain and do not need gas to sign; only the aggregator that submits the soft confirmation does.)

### EOA Monitoring & Automatic Top-Up

```mermaid
flowchart TD
    R[Refueler] -->|poll balance| S[Sequencer EOAs]
    R -->|poll balance| C[Aggregator EOAs<br/>committee bundles]
    R -->|poll balance| P[Proposer EOA]
    R -->|balance < threshold| T[Send top-up tx]
    T --> S
    T --> C
    T --> P
```

### Accounts Monitored

* Sequencer
* Committee
* Main Proposer Validator

### Inputs / Outputs

| Inputs                   | Outputs             |
| ------------------------ | ------------------- |
| EOA balances, thresholds | Top-up transactions |

### Dependencies

* A funded treasury/source account.
* Chain RPC to read balances and send top-ups.

### Deployment

* **Current deployment: 1 server.**

### High Availability

* Warm standby recommended; monitored source balance.

### Scalability

* Trivial (low request volume); polling interval tunable.

### Security

* Holds a funded source key — protect with HSM/KMS.
* Enforce per-tx and per-interval caps to limit blast radius if compromised.

> \[!WARNING] The Refueler's source key can move funds. Apply strict spend limits, allowlisted destinations (only the monitored EOAs), and alerting on anomalous top-ups.

### Monitoring

* Source balance, top-up frequency/amount per EOA, failed top-ups.

### Failure Scenarios & Recovery

| Failure         | Effect                             | Recovery                        |
| --------------- | ---------------------------------- | ------------------------------- |
| Refueler down   | EOAs may deplete → pipeline stalls | Standby; manual top-up; alert   |
| Source depleted | Cannot top up                      | Replenish treasury; alert early |

### Best Practices

* Alert on source balance well before depletion.
* Allowlist destinations; cap amounts.

***

## Z2 Explorer

### Purpose

The Explorer is the public block explorer for Z2 — a web UI and API for inspecting blocks, transactions, accounts, tokens, and smart contracts.

### Architecture

```mermaid
flowchart LR
    NODE[Z2 Node RPC] --> IDX[Indexer]
    IDX --> DB[(Explorer DB)]
    DB --> API[Explorer API]
    API --> UI[Explorer Web UI]
    UI --> USER([Users])
```

### Features

| Feature         | Description                                   |
| --------------- | --------------------------------------------- |
| Search          | By block, tx hash, address, token, contract   |
| Blocks          | Height, timestamp, proposer, tx count, gas    |
| Transactions    | Status, from/to, value, gas, logs, receipts   |
| Accounts        | Balances, nonce, tx history                   |
| Tokens          | ZTP20/token metadata, holders, transfers      |
| Smart contracts | Bytecode, verified source, read/write methods |

### Inputs / Outputs

| Inputs                 | Outputs                            |
| ---------------------- | ---------------------------------- |
| Node RPC, chain events | Indexed data, web UI, explorer API |

### Dependencies

* Z2 Nodes (RPC), indexer, database.

### Deployment

* Indexer + database + API + UI tier; can be scaled independently of nodes.

### High Availability

* Redundant API/UI instances behind a load balancer; replicated database.

### Scalability

* Read-heavy — scale API/UI horizontally; use read replicas and caching.

### Security

* Read-only against the chain; sanitize inputs; rate-limit API.

### Monitoring

* Indexer lag behind chain head, query latency, error rate.

### Failure Scenarios & Recovery

| Failure     | Effect               | Recovery                         |
| ----------- | -------------------- | -------------------------------- |
| Indexer lag | Stale explorer data  | Scale indexer; catch up          |
| DB down     | Explorer unavailable | Failover replica; restore backup |

### Best Practices

* Alert on indexer lag; cache hot queries; verify contract source publicly.

***

## Z2 Monitoring

### Purpose

Provide platform-wide observability: metrics, logs, health monitoring, performance analysis, alerting, and dashboards across all Z2 components.

### Architecture

```mermaid
flowchart LR
    subgraph Targets
        N[Nodes]
        S[Sequencer]
        V[Validators]
        P[Proposer]
        R[Refueler/Relayer]
    end
    Targets -->|/metrics| PROM[Prometheus]
    Targets -->|logs| LOKI[Log store]
    PROM --> GRAF[Grafana Dashboards]
    LOKI --> GRAF
    PROM --> ALERT[Alertmanager]
    ALERT --> NOTIFY[Email / Slack / PagerDuty]
```

### Capabilities

| Capability           | Description                               |
| -------------------- | ----------------------------------------- |
| Metrics              | Prometheus time-series for all components |
| Logs                 | Centralized aggregation and search        |
| Health monitoring    | Liveness/readiness of every service       |
| Performance analysis | Latency, throughput, resource trends      |
| Alerting             | Threshold- and rate-based alerts          |
| Dashboards           | Grafana per-component and platform views  |

### Inputs / Outputs

| Inputs                  | Outputs                     |
| ----------------------- | --------------------------- |
| Metrics endpoints, logs | Dashboards, alerts, reports |

### Dependencies

* All components exporting `/metrics` and logs.

### Deployment

* Prometheus + Grafana + Alertmanager + log store.

### High Availability

* Redundant Prometheus (HA pairs / remote-write), replicated Grafana, durable alerting.

### Scalability

* Federation / remote-write for large fleets; retention tiers.

### Security

* Protect dashboards behind auth (`z2-admin.zetrix.com`); restrict scrape endpoints.

### Failure Scenarios & Recovery

| Failure           | Effect            | Recovery             |
| ----------------- | ----------------- | -------------------- |
| Prometheus down   | No metrics/alerts | HA pair; restore     |
| Alertmanager down | Missed alerts     | Redundant AM cluster |

### Best Practices

* Alert on the alerting pipeline itself (dead-man's-switch).
* Version-control dashboards and alert rules.

*(Detailed alert thresholds are in* [*Monitoring*](#monitoring)*.)*

***

## Z2 Relayer

### Purpose

The Relayer synchronizes state from L1 to L2, primarily driving the **deposit** workflow: assets locked/registered on Zetrix L1 are relayed to L2 so users receive their L2 balance.

### Deposit Workflow (L1 → L2)

```mermaid
sequenceDiagram
    participant User
    participant L1 as Zetrix L1 (Bridge)
    participant Rel as Relayer
    participant N as Z2 Node
    User->>L1: deposit ZETRIX / ZTP-20 / ZTP-721 (lock)
    L1-->>Rel: enqueue delayed message
    Rel->>Rel: observe & confirm
    Rel->>N: deliver → credit on L2
    N-->>User: L2 balance available (seconds)
```

### Supported Assets

* **Native ZETRIX** (bridged to L2 as Wrapped Zetrix — see [Asset Flow](https://docs.zetrix.com/zetrix-l2-documentation/usage/asset-flow.md#asset-flow)).
* **ZTP20** tokens.

### Inputs / Outputs

| Inputs            | Outputs                |
| ----------------- | ---------------------- |
| L1 deposit events | L2 credit transactions |

### Dependencies

* L1 RPC / bridge contract events; Z2 Nodes.

### Deployment

* Runs as an operational service (co-located with infra services in Testnet).

### High Availability

* Redundant Relayer instances with idempotent event processing (dedupe by L1 event id).

### Scalability

* Event-driven; scales with L1 event volume; parallelize by asset/queue.

### Security

* Must not double-credit — enforce exactly-once processing keyed on L1 event.
* Wait for sufficient L1 confirmations before crediting.

> \[!WARNING] Deposit relaying is trust-sensitive: replay or double-processing of L1 events would mint unbacked L2 balances. Enforce idempotency and confirmation thresholds.

### Monitoring

* Deposit lag, events processed, failed/duplicate events, confirmation depth.

### Failure Scenarios & Recovery

| Failure      | Effect           | Recovery                                    |
| ------------ | ---------------- | ------------------------------------------- |
| Relayer down | Deposits delayed | Standby; catch up from last processed event |
| Missed event | Deposit stuck    | Reprocess from L1 event log                 |

### Best Practices

* Idempotent, checkpointed event processing.
* Confirmation-depth threshold before crediting.

***

## Faucet

### Purpose

The Faucet distributes **test gas** on Testnet so developers and users can obtain funds to exercise the network without real value.

### Gas Distribution & Rate Limiting

```mermaid
flowchart TD
    U([User]) -->|request| F[Faucet]
    F --> RL{Rate limit OK?}
    RL -->|no| REJ[Reject / retry-after]
    RL -->|yes| CHK{Anti-abuse checks}
    CHK -->|fail| REJ
    CHK -->|pass| SEND[Send test gas]
    SEND --> U
```

### Security & Anti-Abuse

* Rate limiting per address / IP.
* Optional captcha or auth (see prohibited actions caveat: automated captcha solving is not a platform feature).
* Caps on amount per request and per period.

### Current Implementation

* Web-based faucet served at `https://z2-test-faucet.zetrix.com`; production at `https://z2-faucet.zetrix.com`.
* Distributes the L2 native gas unit (`ZETRIX2` symbol) so users can pay for transactions on Z2.
* Fixed gas amount per request with per-address/IP rate limits.

### Future Improvements

* Stronger anti-Sybil (proof-of-work, social auth).
* Dynamic amounts based on demand.
* Abuse analytics and dynamic blocklists.

### Inputs / Outputs

| Inputs            | Outputs           |
| ----------------- | ----------------- |
| Address + request | Test-gas transfer |

### Dependencies

* Funded faucet EOA; Z2 RPC.

### Deployment

* Web service + faucet EOA (Testnet only).

### Security Considerations

* Protect the faucet EOA key; monitor drain rate.

### Failure Scenarios & Recovery

| Failure        | Effect      | Recovery                       |
| -------------- | ----------- | ------------------------------ |
| Faucet drained | No test gas | Replenish; tighten limits      |
| Abuse spike    | Rapid drain | Rate-limit; blocklist; captcha |

### Best Practices

* Conservative default limits; monitor drain; alert on anomalies.

> \[!NOTE] The Faucet is a **Testnet-only** convenience and has no role on Mainnet.

***

[← Trust Model](https://docs.zetrix.com/zetrix-l2-documentation/architecture/trust-model.md) · [Index](https://docs.zetrix.com/zetrix-l2-documentation/readme.md) · [Z2 Zetrix MCP →](https://docs.zetrix.com/zetrix-l2-documentation/integration/zetrix-mcp.md)
