What is the Forester?
The Forester processes two types of queues:State Tree Queues
Processes input (nullify) and output (append) queues for state Merkle trees that store compressed account data
Address Tree Queues
Processes address queues for indexed Merkle trees that ensure address uniqueness
Architecture
Core Components
RPC Pool Manages connections to Solana validators with retry logic, rate limiting, and health checks. Indexer ClientQueries the Photon indexer for queue status, Merkle proofs, and tree metadata. Prover Client Submits proof requests to the ZK prover server and polls for results. Epoch Manager Coordinates tree discovery, queue processing, and work reporting across epoch boundaries. V1 Processor Handles legacy trees using single-item transactions. V2 Processor Handles batched trees using zero-knowledge proofs for batch operations.
How It Works
The Forester operates in a continuous loop:Tree Versions
Light Protocol supports two tree versions:V1 Trees (Legacy)
- Processing: One item per transaction
- Proofs: No zero-knowledge proofs required
- Throughput: Limited by transaction rate (~50 items/sec)
- Use Case: Legacy support, gradual migration to V2
V2 Trees (Batched)
- Processing: Batches of up to 500 items per transaction
- Proofs: Zero-knowledge proofs for batch validity
- Throughput: High throughput (~1000+ items/sec)
- Use Case: Production workloads, high-volume applications
Queue Types
State Tree Queues
Input Queue (Nullify) Contains nullifier hashes for compressed accounts being spent.- Operation: Replace leaf with nullifier hash
- Circuit: Batch Update
- Use Case: Spending compressed tokens/accounts
- Operation: Append new leaves to tree
- Circuit: Batch Append
- Use Case: Creating compressed tokens/accounts
Address Tree Queues
Address Queue Contains new addresses that need to be inserted into indexed Merkle trees.- Operation: Insert address with low/high element proofs
- Circuit: Batch Address Append
- Use Case: Ensuring address uniqueness for new accounts
Processing Flow
V2 State Tree Processing
V2 Address Tree Processing
Performance Characteristics
Throughput
| Tree Type | Version | Items/Tx | Tx/Sec | Items/Sec |
|---|---|---|---|---|
| State | V1 | 1 | 50 | 50 |
| State | V2 | 100-500 | 2-5 | 200-2500 |
| Address | V1 | 1 | 50 | 50 |
| Address | V2 | 100-500 | 2-5 | 200-2500 |
Latency
| Operation | V1 | V2 |
|---|---|---|
| Proof Generation | N/A | 2-15s |
| Transaction Confirmation | 400ms-1s | 400ms-1s |
| End-to-End Latency | 1-2s | 3-16s |
V2 trees trade slightly higher latency for dramatically higher throughput. A single V2 transaction can process 500 items in ~10 seconds, compared to 500 separate V1 transactions taking ~10 seconds total but with much higher cost.
Processor Modes
The Forester can be configured to process specific tree versions:| Mode | Processes | Use Case |
|---|---|---|
v1 | V1 state and address trees | Legacy support only |
v2 | V2 batched trees | Production workloads |
all | Both V1 and V2 trees | Migration period |
Queue Polling Modes
Two methods for discovering pending queue items:Indexer Mode (Default)
Queries the Photon indexer API for queue status. Advantages:- Fast and efficient
- No RPC load
- Supports advanced queries
- Photon indexer access
- Indexer must be synced
On-Chain Mode
Reads queue accounts directly from Solana RPC. Advantages:- No indexer dependency
- Always accurate
- Works with any RPC
- Higher RPC load
- Slower polling
Epoch System
Foresters operate within epochs for work scheduling and rewards:Epoch Phases
| Phase | Duration | Forester Activity |
|---|---|---|
| Registration | 10% | Register for next epoch |
| Active | 80% | Process queues, submit work |
| Report Work | 10% | Report completed work |
Forester Slots
Each forester has assigned time slots within an epoch:- Slot Duration: Typically 60-120 seconds
- Trees per Slot: Assigned trees for processing
- Work Reporting: Required for reward eligibility
Metrics and Monitoring
The Forester exposes Prometheus metrics for monitoring:Key Metrics
Example Grafana Dashboard
Compressible Account Tracking
Optional feature to track and compress compressible accounts:- Compressed Token (cToken) accounts
- Compressed Mint accounts
- Compressed PDA accounts
- Monitors compressible accounts via WebSocket
- Tracks account changes and triggers compression
- Submits compression transactions automatically
Compressible account tracking requires a WebSocket RPC connection to receive real-time account updates.
Cost Considerations
Transaction Costs
| Operation | Version | Cost per Item | Cost per 1000 Items |
|---|---|---|---|
| State Append | V1 | 0.000005 SOL | 0.005 SOL |
| State Append | V2 | 0.000001 SOL | 0.001 SOL |
| State Nullify | V1 | 0.000005 SOL | 0.005 SOL |
| State Nullify | V2 | 0.000001 SOL | 0.001 SOL |
| Address Append | V1 | 0.000005 SOL | 0.005 SOL |
| Address Append | V2 | 0.000001 SOL | 0.001 SOL |
Operational Costs
- RPC Costs: ~$50-200/month depending on usage
- Prover Costs: Self-hosted or paid service
- Indexer Costs: Free (Photon) or self-hosted
- Monitoring: Free (Prometheus/Grafana)
Next Steps
Running a Forester
Learn how to set up and run a forester node
Queue Management
Deep dive into queue processing and liveness monitoring