MultiNodeRaftSim

constructor(nodeIds: List<NodeId>, scope: CoroutineScope, nodeScope: CoroutineScope, baseConfig: RaftConfig = MULTI_NODE_SIM_BASE_CONFIG, baseSeed: Long = MULTI_NODE_SIM_SEED, maxPayloadBytes: Int? = null, nodeFactory: (NodeStart) -> RaftNode = defaultNodeFactory(nodeIds, baseConfig))

Parameters

nodeIds

The ordered list of voter NodeIds forming the initial cluster config.

scope

The test's TestScope — used for withTimeout bounds in the await helpers.

nodeScope

Scope for node coroutines — pass TestScope.backgroundScope so the infinite heartbeat/election loops are cancelled at test teardown without kotlinx.coroutines.test.UncompletedCoroutinesError.

baseConfig

Timing parameters for every node. RaftConfig.random is overridden per node and per start (Random(simNodeSeed(baseSeed, nodeIndex, start)), see below) to ensure distinct election timeouts and guarantee convergence. Must have RaftConfig.expectVirtualTime = true for tests running under a kotlinx.coroutines.test.TestDispatcher. Defaults to MULTI_NODE_SIM_BASE_CONFIG.

baseSeed

Seed from which per-node Randoms are derived. Change to explore different election orderings; the default MULTI_NODE_SIM_SEED is stable across runs.

maxPayloadBytes

Optional payload cap forwarded to MultiNodeRaftNetwork — forces InstallSnapshot chunking in tests that exercise the snapshot-transfer path.

nodeFactory

Override to wire a custom RaftNode implementation. It is called once per start of a node, at construction and again on every restart, with a NodeStart carrying the node's id, transport, storage and scope, the start count, and that start's seeded NodeStart.random. The default wires CoroutineScope.raftNode with baseConfig.copy(random = start.random); a custom factory seeds RaftConfig.random from NodeStart.random the same way, and then derives exactly as a default node would.

A restart is a new process, so it gets a new seed

The sim seeds a node's first start with baseSeed + nodeIndex, and its k-th restart with a seed that differs from every earlier one (simNodeSeed). It never reuses one, and it picks the seed itself, so no factory can pick a wrong one (#3659). A us.tractat.kuilt.raft.ClientIdentity.Auto node mints its client id from RaftConfig.random, and the library promises that id changes on restart; in production it does, because the process draws from fresh entropy. Reseeding a restart with its first seed brings the old id back, and the restarted node's first forward reuses the old incarnation's (clientId, requestId) with different bytes, which the leader refuses with us.tractat.kuilt.raft.RequestIdConflictException (#3425).

The seed stays a pure function of baseSeed, the node's index and its start count — no clock, no entropy — so one baseSeed replays the same run, restarts included, on every target.