This file implements the vote tracking and aggregation mechanisms used by the leader node in the Canopy blockchain’s Byzantine Fault Tolerance (BFT) consensus protocol. It enables the leader to collect, validate, and count votes from replica validators to reach consensus.
The vote tracking system is designed to handle:
The voting system uses a hierarchical structure to organize votes:
VotesForHeight is a map that organizes votes by round, phase, and payload hashVoteSet represents a collection of votes for the same proposal, tracking:
This structure allows the leader to efficiently track which validators have voted for which proposals and calculate when a majority has been reached.
The system provides mechanisms to determine when consensus has been reached:
GetMajorityVote() checks if any proposal has received votes representing at least 2/3 of the total voting powerGetLeadingVote() identifies the proposal with the most voting power behind itThese functions are crucial for the consensus process, as they allow the leader to determine when a decision can be finalized and communicated to all participants.
When a vote arrives from a replica validator, several steps occur:
This process ensures that each validator can only vote once per proposal and that their voting power is correctly accounted for.
During election votes, replicas may submit additional information:
The leader validates this information and updates its state accordingly, which helps maintain the security and liveness of the blockchain.
The voting system incorporates several security features to prevent attacks and ensure consensus integrity. These include signature verification to prevent vote forgery, duplicate vote detection to prevent double-voting, validation of high QCs to prevent long-range attacks, and collection of evidence of Byzantine behavior for potential validator punishment. The requirement for a 2/3 majority ensures that consensus can only be reached if a significant portion of honest validators agree.