Raft Consensus Simulator - Problem
Implement a Raft consensus protocol simulator that handles the three core components of the algorithm:
1. Leader Election: When nodes start or detect leader failure, they transition through states (Follower → Candidate → Leader) using randomized timeouts and majority voting.
2. Log Replication: The leader receives client requests, appends entries to its log, and replicates them to followers using AppendEntries RPCs with consistency checks.
3. Commit Handling: Once a majority of nodes have replicated an entry, the leader commits it and notifies followers to apply it to their state machines.
Your simulator should process a sequence of events ('election', 'append', 'commit') and return the final state of all nodes including their roles, terms, logs, and commit indices.
Input & Output
Constraints
- 1 ≤ numNodes ≤ 10
- 1 ≤ events.length ≤ 50
- Event types: 'election', 'append', 'commit'
- Entry strings have length ≤ 20