ReorgDetectorImpl

class ReorgDetectorImpl(config: ReorgConfig = ReorgConfig()) : ReorgDetector

Implementation of ReorgDetector using in-memory block history.

Thread Safety: Uses Mutex for coroutine-safe operations.

Algorithm:

  1. Maintain sliding window of recent blocks (map: height → BlockInfo)

  2. When new block arrives, check if parent hash matches previous block

  3. If mismatch, walk backwards to find common ancestor

  4. Emit ReorgEvent with old and new branches

  5. Update block history with new canonical blocks

Constructors

Link copied to clipboard
constructor(config: ReorgConfig = ReorgConfig())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun getChainTip(): BlockInfo?

Get current canonical chain tip.

Link copied to clipboard
open override fun observeReorgs(): Flow<ReorgEvent>

Observe reorg events as they occur.

Link copied to clipboard
open suspend override fun recordBlock(block: BlockInfo, parentHash: String): ReorgEvent?

Record a new block in the chain.

Link copied to clipboard
open suspend override fun reset(): <Error class: unknown class>

Reset detector state (for testing or recovery).