mirror of
https://github.com/status-im/nim-raft.git
synced 2025-02-17 23:57:19 +00:00
Fix
This commit is contained in:
parent
ebfa89b0a7
commit
40c8ac80c1
@ -13,8 +13,8 @@ import types
|
|||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
EventType = enum
|
|
||||||
# Node events
|
# Node events
|
||||||
|
EventType = enum
|
||||||
NodeStart, NodeStop, NodeTick, NodeStepDown, NodeStepDownToCandidate, NodeStepDownToFollower, NodeStepDownToLeader,
|
NodeStart, NodeStop, NodeTick, NodeStepDown, NodeStepDownToCandidate, NodeStepDownToFollower, NodeStepDownToLeader,
|
||||||
NodeStepDownToShutdown, VotingTimeout, ElectionTimeout, HeartbeatTimeout, HeartbeatReceived, HeartbeatSent, AppendEntriesReceived,
|
NodeStepDownToShutdown, VotingTimeout, ElectionTimeout, HeartbeatTimeout, HeartbeatReceived, HeartbeatSent, AppendEntriesReceived,
|
||||||
AppendEntriesSent, RequestVoteReceived, RequestVoteSent, RequestVoteGranted, RequestVoteDenied, ClientRequestReceived,
|
AppendEntriesSent, RequestVoteReceived, RequestVoteSent, RequestVoteGranted, RequestVoteDenied, ClientRequestReceived,
|
||||||
@ -23,15 +23,19 @@ type
|
|||||||
|
|
||||||
# Define callback to use with Terminals. Node states are updated/read in-place in the node object
|
# Define callback to use with Terminals. Node states are updated/read in-place in the node object
|
||||||
ConsensusFSMCallbackType*[NodeType] = proc(node: NodeType) {.gcsafe.}
|
ConsensusFSMCallbackType*[NodeType] = proc(node: NodeType) {.gcsafe.}
|
||||||
|
|
||||||
# Define Non-Terminals as a (unique) tuples of the internal state and a sequence of callbacks
|
# Define Non-Terminals as a (unique) tuples of the internal state and a sequence of callbacks
|
||||||
NonTerminalSymbol*[NodeType] = (NodeType, seq[ConsensusFSMCallbackType[NodeType]])
|
NonTerminalSymbol*[NodeType] = (NodeType, seq[ConsensusFSMCallbackType[NodeType]])
|
||||||
|
|
||||||
# Define logical functions (conditions) computed from our NodeType etc. (Truth Table)
|
# Define logical functions (conditions) computed from our NodeType etc. (Truth Table)
|
||||||
LogicalFunctionConditionValueType* = bool
|
LogicalFunctionConditionValueType* = bool
|
||||||
LogicalFunctionCondition*[EventType, NodeTytpe, RaftMessageBase] = proc(e: EventType, n: NodeTytpe, msg: Option[RaftMessageBase]): bool
|
LogicalFunctionCondition*[EventType, NodeTytpe, RaftMessageBase] = proc(e: EventType, n: NodeTytpe, msg: Option[RaftMessageBase]): bool
|
||||||
LogicalFunctionConditionsLUT*[EventType, NodeType, RaftMessageBase] = Table[(EventType, NodeType), LogicalFunctionCondition[EventType, NodeType, Option[RaftMessageBase]]]
|
LogicalFunctionConditionsLUT*[EventType, NodeType, RaftMessageBase] = Table[(EventType, NodeType), LogicalFunctionCondition[EventType, NodeType, Option[RaftMessageBase]]]
|
||||||
|
|
||||||
# Define Terminals as a tuple of a Event and a sequence of logical functions (conditions) and their respective values computed from NodeType, NodeTytpe and RaftMessageBase
|
# Define Terminals as a tuple of a Event and a sequence of logical functions (conditions) and their respective values computed from NodeType, NodeTytpe and RaftMessageBase
|
||||||
# (kind of Truth Table)
|
# (kind of Truth Table)
|
||||||
TerminalSymbol*[EventType, NodeType, RaftMessageBase] = (EventType, seq[LogicalFunctionConditionValueType])
|
TerminalSymbol*[EventType, NodeType, RaftMessageBase] = (EventType, seq[LogicalFunctionConditionValueType])
|
||||||
|
|
||||||
# Define State Transition Rules LUT of the form ( NonTerminal -> Terminal ) -> NonTerminal )
|
# Define State Transition Rules LUT of the form ( NonTerminal -> Terminal ) -> NonTerminal )
|
||||||
StateTransitionsRulesLUT*[NodeType, EventType, RaftMessageBase] = Table[
|
StateTransitionsRulesLUT*[NodeType, EventType, RaftMessageBase] = Table[
|
||||||
(NonTerminalSymbol[NodeType], TerminalSymbol[NodeType, EventType, RaftMessageBase]),
|
(NonTerminalSymbol[NodeType], TerminalSymbol[NodeType, EventType, RaftMessageBase]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user