fix(bifrost/solana): wait only the rest of the scan interval
🔎 Visual review of47362a1c: explainer, review flags and prompts to ask an AI about the change
Summary
When the unscanned slots span less than scan_interval, the Solana scanner slept a whole interval before checking again. So each scan cycle could add up to one extra interval (15 s by default) to SOL observation latency, and a full second interval whenever the slot-time constant read short. It now sleeps only interval − lag. A scan still starts only once the estimated lag reaches scan_interval, the same test as before, so scans run no more often than they did and the RPC call rate is unchanged.
The decision moves into a pure helper, scanCoalesceWait(lag, interval), which returns 0 once lag reaches the interval and otherwise the rest of the interval.
Risk: medium (Bifrost observation scanning; doesn't sign).
Not in this MR
A companion change cutting the default scan_interval from 15 s to 5 s was dropped. It would roughly triple Solana RPC calls per node.
A related observation, not addressed: lag is the slot count times common.SOLChain.ApproximateBlockMilliseconds(), which is 300 ms (its comment says 265–300 ms measured). If slots run faster than that, lag overstates the elapsed time, before and after this change alike. That constant is consensus-critical and out of scope here.
Tests and coverage
TestScanCoalesceWaitcovers lag of 0, part of the interval, exactly the interval, and beyond it.- Changed-line coverage: 3/8. The helper is fully covered. The 5 uncovered lines are its call site inside
SOLScanner.scan(), which no unit test drives: it needs a live RPC, a bridge and vaults. Those lines were uncovered before this change too.