This one is overdue: detailing what exactly system messages ("IMsg") do. These are the missing links that tie the functionality of the channel diagrams I've posted together. Combining both of them should give you a pretty good overview of how the factomd node works internally.
All IMsgs, from now on referred to as "messages", are defined by the IMsg interface in common/interfaces/msg.go. A complete list of messages is defined in common/constants/constants.go. Those are the ones I'll cover. (This includes both regular messages and election messages, but election messages will come later)
The important functions that distinguish messages are:
Notes:
There is also a message type IElectionMsg that extends IMsg with the following functions:
There are three broad categories of messages: Normal messages, ProcessList messages, and Election messages. A single message can be more than one at once and will be passed around between different systems using channels. Hence I'll be referencing those channels a lot, particularly Consensus and Elections.
Format:
Message Name
There are a few generic functions called for messages, which I don't want to repeat over and over: state.LeaderExecute(IMsg) and state.FollowerExecuteMsg(IMsg).
All IMsgs, from now on referred to as "messages", are defined by the IMsg interface in common/interfaces/msg.go. A complete list of messages is defined in common/constants/constants.go. Those are the ones I'll cover. (This includes both regular messages and election messages, but election messages will come later)
The important functions that distinguish messages are:
- Network Functions: Messages can be local, meant for a specific peer, or full broadcast. Local messages are never sent over the network even if given to the network controller
- Various Hashes: These are used for identification for ACKs, keeping track of messages, as well as ChainID which is the identity chain
- Validate(State) int: All messages are validated before anything else happens and all validation functions return -1 for messages that are not usable, 0 for messages that may be usable in the future, and 1 for valid messages.
- LeaderExecute(State): This is the functionality that only leaders perform. It is sometimes the same as FollowerExecute, which just calls the other function.
- FollowerExecute(State): This is the functionality that non-leaders perform
- Process(height, State) bool: Messages that land in the ProcessList will have this called when it's their turn. For this it's very important to know that each processlist is processed in order ("Height" from 0 to n) and this function has a return value. If it returns "false" then the processing of that VM halts, resuming at same Height the next time around. This means that messages are called repeatedly until finished and this behavior is used as small state machines. I'm going to use the term "waiting" for this which indicates a "return false", not a sleep().
Notes:
- When a message is "added to the processlist", this will broadcast the message and an ack to the network, as well as remove the message from Holding.
- When a message is sent out it means it's added to the NetworkOutMsgQueue queue, which will eventually send the message to the specified nodes in the network. It can be directed (single peer), broadcast (up to 8 random peers), or full broadcast (everyone the node is connected to).
There is also a message type IElectionMsg that extends IMsg with the following functions:
- ElectionValidate(Election): This works similar to the above Validate(), returning -1, 0, and 1, but in the context of an election.
- ElectionProcess(State, Election): Messages inside the election process will have this function called during the election process, running their functionality
There are three broad categories of messages: Normal messages, ProcessList messages, and Election messages. A single message can be more than one at once and will be passed around between different systems using channels. Hence I'll be referencing those channels a lot, particularly Consensus and Elections.
Format:
Message Name
- Origin: Which area generated it (vaguely)
- Function:Verbal explanation of what the function does
There are a few generic functions called for messages, which I don't want to repeat over and over: state.LeaderExecute(IMsg) and state.FollowerExecuteMsg(IMsg).
- Generic state.LeaderExecute: If the message is not a Replay, it adds it to the ProcessList.
- Generic state.FollowerExecuteMsg: This adds the message to Holding. If there already is an Ack for this message, it adds it to the ProcessList.