Status |
| ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Stakeholders | |||||||||||||||||
Outcome |
| ||||||||||||||||
Due date | |||||||||||||||||
Owner |
Background
...
Block synchronization is briefly discussed in whitepaper, nevertheless much more details are needed for this feature. Also several design decisions were taken during the implementation that influence other core modules. Therefore this document is meant to review in detail the current design of block synchronization and start a discussion of what changes are accepted by the core team and what needs to be corrected in the future.
...
Problem
Scenarios
The following are the scenarios for the block synchronization:
- New peer joins the validator network and needs to get the whole blockchain.
- The peer lost several commit messages due to poor internet connection and needs to get the latest blocks.
- The peer was stopped and restarted after some time and needs to get the latest blocks.
- ...
...
Solution
Gossip
For the peers to discover that they do not have latest blocks, peers send their latest block hashes to all other peers in the network every N seconds. If a peer discovers that it has a different latest block hash, it will request the missing blocks from other peers.
Sequence Diagram
The sequence diagram here represents a scenario where new peer has joined the peer network. The peers latest block hash will be `[0u8, 32]`, while other peers would have different latest block hash, assuming they committed several other blocks. Therefore the new peer will request missing blocks.
Activity Diagram
Activity diagram represents a synchronization process from the moment of receiving the latest block hash to the moment when all the new blocks are stored.
Block Validation
To validate the signatures of the block the peer needs to have:
...
With this design both the set of validating peers and their roles are known to the synchronizing peer for each new block.