Skip to content

validateLoadQuorumConfig

validateLoadQuorumConfig(config): void

Defined in: packages/core/src/load-quorum.ts:275

Validate the load-quorum tuning knobs from PeerborneConfig.

Call this before using load-quorum settings so a misconfigured value is surfaced loudly rather than silently degrading a subsequent load(). For example, loadQuorumK: 1.5 previously slipped through Math.min(configuredK, peersLen) to produce peers.slice(0, 1.5) which probes only 1 peer (silent single-peer load); loadQuorumQ: NaN made bestPeers.length < NaN evaluate as false (silent single-peer quorum pass). Both classes of misconfig are now rejected here with a clear operator-visible error.

loadQuorumTimeoutMs is also validated here because the value flows directly into setTimeout(...) inside a security-advertisement probe race. NaN/Infinity/0/negative values are coerced to immediate-fire or overflow behaviour by the timer queue. We require a finite positive integer no greater than LOAD_QUORUM_TIMEOUT_MS_MAX so an operator typo or a misplaced decimal is caught at startup.

loadQuorumEnabled and loadQuorumAllowSinglePeer MUST be booleans when provided. loadQuorumK and loadQuorumQ MUST be finite positive integers (Number.isInteger(x) && x >= 1). loadQuorumTimeoutMs MUST be a finite positive integer in the closed range [1, LOAD_QUORUM_TIMEOUT_MS_MAX].

Rejects:

  • non-boolean values for loadQuorumEnabled / loadQuorumAllowSinglePeer
  • NaN / Infinity / -Infinity (all knobs)
  • non-integers (e.g. 1.5, 2.7) (all knobs)
  • zero and negative values (0, -1) (all knobs)
  • loadQuorumTimeoutMs > LOAD_QUORUM_TIMEOUT_MS_MAX
  • loadQuorumQ greater than loadQuorumK (or DEFAULT_LOAD_QUORUM_K when K is not configured) Accepts:
  • undefined (operator did not override; the orchestrator’s defaults apply)
  • any positive integer (1, 2, 3, …) for K/Q
  • integers in [1, LOAD_QUORUM_TIMEOUT_MS_MAX] for loadQuorumTimeoutMs

Throws LoadQuorumFailedError with reason: 'invalid-config' so the existing instanceof-based error handling in PeerborneDocument.load() continues to work and operators see a structured failure with the offending value.

The PeerborneConfig (or its load-quorum subset) to validate. Boolean policy switches are validated exactly when this function is invoked. Dormant K/Q knobs are ignored when quorum is explicitly disabled; the timeout is validated on every invocation.

boolean

boolean

number

number

number

void