Skip to content

[scanner] No jitter in MempoolMonitor reconnect backoff — thundering herd on RPC outage #236

@obchain

Description

@obchain

Refs #46

PR: feat/21-mempool-monitor
File: crates/charon-scanner/src/mempool.rs
Function: MempoolMonitor::run()

Problem

The reconnect backoff is:

backoff = (backoff * 2).min(Duration::from_secs(30));

This is the same deterministic doubling pattern flagged for BlockListener in PR #32 (open issue: no jitter). Multiple bot instances (e.g. Docker Compose replicas: 2) or a future where MempoolMonitor and BlockListener both reconnect after the same RPC outage will fire reconnection attempts at exactly the same moment, creating a thundering herd.

The fix is the same as that required for BlockListener and should share a utility function to avoid future divergence.

Required fix

Add jitter: after doubling, add a random offset in range [0, backoff/2] using rand::thread_rng() or the tokio-equivalent. Extract a shared backoff_with_jitter(current, max) utility in charon-scanner so BlockListener, MempoolMonitor, and any future subscribers all use the same implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)priority:p2-polishNice-to-have / polish

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions