Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NodeHealthTracker

Hierarchy

  • NodeHealthTracker

Index

Constructors

constructor

Properties

Private apiCooldownMs

apiCooldownMs: number

Private bestKnownHeadBlock

bestKnownHeadBlock: number = 0

Private bestKnownHeadBlockTime

bestKnownHeadBlockTime: number = 0

Private headBlockTtlMs

headBlockTtlMs: number

Private health

health: Map<string, NodeState> = new Map()

Private maxApiFailuresBeforeCooldown

maxApiFailuresBeforeCooldown: number

Private maxFailuresBeforeCooldown

maxFailuresBeforeCooldown: number

Private nodeCooldownMs

nodeCooldownMs: number

Private staleBlockThreshold

staleBlockThreshold: number

Methods

getHealthSnapshot

  • getHealthSnapshot(): Map<string, { apiFailures: Record<string, { count: number }>; consecutiveFailures: number; headBlock: number; healthy: boolean }>
  • Get a snapshot of current health state for diagnostics.

    Returns Map<string, { apiFailures: Record<string, { count: number }>; consecutiveFailures: number; headBlock: number; healthy: boolean }>

Private getOrCreate

  • Parameters

    • node: string

    Returns NodeState

getOrderedNodes

  • getOrderedNodes(allNodes: string[], api?: undefined | string): string[]
  • Return nodes ordered by health for a specific API call. Healthy nodes come first (preserving original order), then unhealthy nodes as fallback.

    Parameters

    • allNodes: string[]
    • Optional api: undefined | string

    Returns string[]

Private incrementApiFailure

  • incrementApiFailure(state: NodeState, api: string): void
  • Parameters

    Returns void

isNodeHealthy

  • isNodeHealthy(node: string, api?: undefined | string): boolean
  • Check if a node is considered healthy for a given API.

    Parameters

    • node: string
    • Optional api: undefined | string

    Returns boolean

recordApiFailure

  • recordApiFailure(node: string, api: string): void
  • Record an API/plugin-specific failure (e.g. "method not found", "plugin not enabled"). Only increments the per-API counter, NOT the global consecutive failure counter. This prevents a node with a disabled plugin from being penalized for all APIs.

    Parameters

    • node: string
    • api: string

    Returns void

recordFailure

  • recordFailure(node: string, api: string): void
  • Record a network-level failure (timeout, connection refused, HTTP error). Increments both the global consecutive failure counter and the API-specific counter.

    Parameters

    • node: string
    • api: string

    Returns void

recordSuccess

  • recordSuccess(node: string, api: string): void
  • Record a successful call to a node for a specific API. Clears consecutive failure counter and API-specific failures for this API.

    Parameters

    • node: string
    • api: string

    Returns void

reset

  • reset(): void
  • Reset all health tracking data.

    Returns void

updateHeadBlock

  • updateHeadBlock(node: string, headBlock: number): void
  • Update head block number for a node. Called passively when get_dynamic_global_properties responses are observed.

    Parameters

    • node: string
    • headBlock: number

    Returns void

Generated using TypeDoc