This file contains the high-level functionality for maintaining agreement on blocks in the Canopy blockchain. It handles synchronization with peers and manages consensus messaging between validators.
The consensus.go file is responsible for:
The synchronization system allows nodes to catch up with the current blockchain state. When a node falls behind or joins the network, it:
The system includes safeguards against malicious peers by tracking reputation and validating VDF iterations to prevent unsafe forks.
This component handles the routing of consensus messages between validators in a committee. It:
The system distinguishes between sending to self (internal routing) and sending to peers (via P2P network).
This component manages block requests from syncing peers:
It includes reputation management to penalize peers that exceed rate limits or send invalid requests.
The system maintains connections with committee members:
Provides detailed information about the current consensus state:
This information is useful for monitoring and debugging the consensus process.
flowchart TD
A[Start Sync] --> B{Single Node Network?}
B -->|Yes| C[Finish Syncing]
B -->|No| D[Poll Max Height]
D --> E{Syncing Done?}
E -->|Yes| C
E -->|No| F[Request Block]
F --> G{Block Received?}
G -->|Yes| H[Handle Peer Block]
G -->|No| I[Timeout]
H --> J{Block Valid?}
J -->|Yes| K[Update Height]
J -->|No| L[Slash Reputation]
K --> E
L --> D
I --> D
flowchart LR
A[Receive Consensus Message] --> B{Node Syncing?}
B -->|Yes| C[Discard Message]
B -->|No| D[Unmarshal Message]
D --> E[Route to Consensus Module]
E --> F{Error?}
F -->|Yes| G[Slash Reputation]
F -->|No| H[Process Message]
The file implements several security measures:
These security features help maintain the integrity of the blockchain by protecting against various attack vectors and ensuring that only valid blocks are added to the chain.