Skip to content

effectiveK

effectiveK(configuredK, knownPeersCount): number

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

Compute the effective K (number of peers to query) given a configured upper bound and the number of currently-known peers. Pulled out so the loader and the quorum decision can share a single source of truth and so the clamp is unit-testable.

Defensive against non-finite or fractional inputs as a second line of defence behind validateLoadQuorumConfig (which runs at Peerborne.initialize() time). A misconfigured loadQuorumK: 1.5 that bypassed startup validation would otherwise produce peers.slice(0, 1.5) — slicing only one peer and silently degrading the gate to a single-peer probe even though the k === 1 && !allowSinglePeer guard would not fire (1.5 !== 1). NaN/Infinity similarly would produce Math.min(NaN, 3) === NaN and a peers.slice(0, NaN) === [] silent skip. Floor + finiteness guards collapse both classes to 0, which the orchestrator surfaces as LoadQuorumFailedError(invalid-config).

number

number

number