Expand description
Snapshot cache for monitoring data
This module provides a cache layer that decouples monitoring API requests
from the business logic locks (e.g., ChannelManagerData).
§Problem
Without caching, every monitoring request acquires the same lock used by share validation and job distribution. An attacker can spam monitoring endpoints to cause lock contention, degrading mining performance.
§Solution
The SnapshotCache periodically copies monitoring data from the source
(via the monitoring traits) into a cache. API requests read from the cache
without acquiring the business logic lock.
Business Logic Monitoring
────────────── ──────────
│ │
│ (holds lock for │
│ share validation) │
│ │
└──────────────────────────────────┤
│
┌─────────▼─────────┐
│ SnapshotCache │
│ (RwLock, fast) │
└─────────┬─────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
│ /metrics │ │ /api/v1/* │ │ /health │
└───────────┘ └───────────┘ └───────────┘Structs§
- Monitoring
Snapshot - Cached snapshot of monitoring data.
- Snapshot
Cache - A cache that holds monitoring snapshots and refreshes them periodically.