Module sui_network::state_sync

source ·
Expand description

Peer-to-peer data synchronization of checkpoints.

This StateSync module is responsible for the synchronization and dissemination of checkpoints and the transactions, and their effects, contained within. This module is not responsible for the execution of the transactions included in a checkpoint, that process is left to another component in the system.

§High-level Overview of StateSync

StateSync discovers new checkpoints via a few different sources:

  1. If this node is a Validator, checkpoints will be produced via consensus at which point consensus can notify state-sync of the new checkpoint via Handle::send_checkpoint.
  2. A peer notifies us of the latest checkpoint which they have synchronized. State-Sync will also periodically query its peers to discover what their latest checkpoint is.

We keep track of two different watermarks:

  • highest_verified_checkpoint - This is the highest checkpoint header that we’ve locally verified. This indicated that we have in our persistent store (and have verified) all checkpoint headers up to and including this value.
  • highest_synced_checkpoint - This is the highest checkpoint that we’ve fully synchronized, meaning we’ve downloaded and have in our persistent stores all of the transactions, and their effects (but not the objects), for all checkpoints up to and including this point. This is the watermark that is shared with other peers, either via notification or when they query for our latest checkpoint, and is intended to be used as a guarantee of data availability.

The PeerHeights struct is used to track the highest_synced_checkpoint watermark for all of our peers.

When a new checkpoint is discovered, and we’ve determined that it is higher than our highest_verified_checkpoint, then StateSync will kick off a task to synchronize and verify all checkpoints between our highest_synced_checkpoint and the newly discovered checkpoint. This process is done by querying one of our peers for the checkpoints we’re missing (using the PeerHeights struct as a way to intelligently select which peers have the data available for us to query) at which point we will locally verify the signatures on the checkpoint header with the appropriate committee (based on the epoch). As checkpoints are verified, the highest_synced_checkpoint watermark will be ratcheted up.

Once we’ve ratcheted up our highest_verified_checkpoint, and if it is higher than highest_synced_checkpoint, StateSync will then kick off a task to synchronize the contents of all of the checkpoints from highest_synced_checkpoint..=highest_verified_checkpoint. After the contents of each checkpoint is fully downloaded, StateSync will update our highest_synced_checkpoint watermark and send out a notification on a broadcast channel indicating that a new checkpoint has been fully downloaded. Notifications on this broadcast channel will always be made in order. StateSync will also send out a notification to its peers of the newly synchronized checkpoint so that it can help other peers synchronize.

Structs§

Enums§

Traits§

  • Generated trait containing RPC methods that should be implemented for use with StateSyncServer.