canopy

vote.go - Leader Vote Tracking and Aggregation

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.

Overview

The vote tracking system is designed to handle:

Core Components

VotesForHeight and VoteSet

The voting system uses a hierarchical structure to organize votes:

This structure allows the leader to efficiently track which validators have voted for which proposals and calculate when a majority has been reached.

Majority Vote Determination

The system provides mechanisms to determine when consensus has been reached:

These 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.

Vote Processing

When a vote arrives from a replica validator, several steps occur:

  1. The appropriate vote set is located or created
  2. The vote is validated to ensure it comes from a legitimate validator
  3. The validator’s voting power is added to the total for that proposal
  4. The validator’s signature is added to the aggregate signature

This process ensures that each validator can only vote once per proposal and that their voting power is correctly accounted for.

High QC and Evidence Handling

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.

Security Mechanisms

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.