Consensus Protocol
The consensus protocol implements the avalanche consensus algorithm.
Protocol ID
/ilx/<network>/consensus/1.0.0
Where <network> is either mainnet, testnet, or regtest depending on which
network is being used.
Network Messages
enum ErrorResponse {
None = 0;
NotFound = 1;
BadRequest = 2;
NotCurrent = 3;
}
message MsgConsensusRequest {
oneof msg {
MsgPollRequest poll_request = 1;
GetBlockReq get_block = 2;
}
}
message MsgPollRequest {
uint32 request_ID = 1;
repeated uint32 heights = 2;
}
message MsgPollResponse {
uint32 request_ID = 1;
repeated bytes votes = 2;
}
message GetBlockReq {
bytes block_ID = 1;
}
message MsgBlockResp {
Block block = 1;
ErrorResponse error = 2;
}
Protocol
- When a new block comes off the wire a node checks it against its local policy. If the block passes the local policy
check then it is marked as
Acceptable, otherwiseUnacceptable. - If an
Acceptableblock gets passed into the consensus engine it is assigned a preference ofPreferredif there are no other preferred blocks.Unacceptableblocks start asNotPreferred. - If a new block conflicts (same height) with another block that is
Preferredthe new block preference is set toNot Preferred. - Once per millisecond the consensus engine select a random peer to query from the validator set, weighted by the percentage of
total stake that validator has, and sends a
MsgAvaRequestto that peer requesting a vote on a block height. The peer responds with the ID of the block it prefers at that height. - We rate limit the number of inflight requests go out at any one time to the number of responses remaining needed to finalize the block. If the next 1 millisecond step occurs before any of the outstanding requests return, the step is skipped.
- When the
MsgAvaResponsereturns the votes are processed.- We record a
Yesvote for the block ID in the response and aNovote for all other block IDs. - If
>12out of the last16recorded votes for a block areYesthen we consider the vote conclusive. - If
>12out of the last16recorded votes for a block areNothen we consider the vote conclusive. - Unknown or unacceptable votes (zero ID) are included in the last 16 votes. They will prevent a block vote from being conclusive if there are enough of them.
- If the vote is conclusive, and it agrees with our current state, either
PreferredorNot Preferred, then we increment a confidence counter by 1.- If the confidence counter is >=
160and the current state isPreferred, then we mark the block asFinalizedand mark all conflicting blocks asRejected. - If the confidence counter is >=
160and the current state isNot Preferred, then we do nothing. Eventually a conflicting block will finalize resulting in this one being marked asRejected.
- If the confidence counter is >=
- If the vote is conclusive, and it does not agree with our current state, either
PreferredorNot Preferred, then we flip our current preference and reset our confidence counter to zero.- If the preference flipped from
Not PreferredtoPreferredthen all conflicting blocks must also flip toNotPreferredby virtue of the same number ofNovotes having been cast for them. - If the preference flipped from
PreferredtoNotPreferredand we have no other preferred blocks. We selected a newPreferredblock from the list ofAcceptableblocks. If no blocks areAcceptablethen have no preference and respond toMsgAvaRequests with a zero ID.
- If the preference flipped from
- We record a
- Simultaneously we work to finalize the leading bits of the block ID.
- We start with the most significant bit (MSB). When a block ID vote is recorded we examine the MSB of the block ID.
- If the MSB is a 0 we record a
Zerovote for the MSB. - If the MSB is a 1 we record a
Onevote for the MSB. - Unknown or unacceptable votes (zero ID) are included in the last 16 votes. They will prevent a bit vote from being conclusive if there are enough of them.
- If
>12out of the last16bit votes are the same we consider the vote conclusive.- We increment the confidence counter for that bit.
- If the current
Preferredblock does not start with the same MSB we flip our preference to a different block that does match the preferred MSB.
- If the confidence counter is >=
160we consider the MSB finalized and repeat the process for the remaining bits.
- If the MSB is a 0 we record a
- We start with the most significant bit (MSB). When a block ID vote is recorded we examine the MSB of the block ID.
In situations where there are more than two conflicting blocks at the same height, the bit finalization helps to coordinate preferences by reducing the candidate set until a block eventually finalizes.