AleoNet / snarkOS

A Decentralized Operating System for ZK Applications
http://snarkos.org
Apache License 2.0
4.31k stars 2.62k forks source link

[Fix] Add grace period before starting block sync #3249

Closed raychu86 closed 4 months ago

raychu86 commented 5 months ago

Motivation

This PR simply adds an additional grace period for the nodes to wait before attempting to call try_block_sync.

Ideally, try_block_sync isn't called until the first PrimaryPing message is received, however in the initial bootup of validators, the nodes need to consider themselves synced to send the PrimaryPing in the first place. Hence, the heuristic wait approach.

This is needed because we've observed that during bootup, nodes were (occasionally) incorrectly setting themselves as synced and when they were in fact much further behind than the other validators. This caused them to incorrectly start processing proposals and certificates from the other validators instead of actually syncing.

Here is an example of an observed sequence of logs that should not happen:

DEBUG Skipping batch proposal (node is syncing)
INFO No connected validators
DEBUG Fetched {} missing previous certificates for round {} from '{}'
DEBUG Primary is not ready to propose the next round
DEBUG Primary is safely skipping a batch proposal (please connect to more validators)

Upon further debugging, this seems to happen when the validator node call try_block_sync before receiving block locators from peers via a Event::PrimaryPing. The call to try_block_sync makes the node think it's synced since there are no block locators to sync from, and thus starts processing proposals/certificates from peers.