/ node / sync / locators / README.md
README.md
 1  # alphaos-node-sync-locators
 2  
 3  [![Crates.io](https://img.shields.io/crates/v/alphaos-node-sync-locators.svg?color=neon)](https://crates.io/crates/alphaos-node-sync-locators)
 4  [![Authors](https://img.shields.io/badge/authors-Alpha-orange.svg)](https://alpha.org)
 5  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE.md)
 6  
 7  The `alphaos-node-sync-locators` crate provides _block locators_,
 8  which are data structures used by nodes to advertise to other nodes the blocks in their possession,
 9  which can be provided to other nodes to help the latter
10  sync their blockchain with the rest of the network.
11  
12  In general, a block is uniquely identified by its height,
13  i.e. its position in the blockchain,
14  starting with 0 for the genesis block,
15  up to $N-1$ for the latest block,
16  if $N$ is the number of blocks in the blockchain.
17  A single block locator consists of a block height and a block hash;
18  the hash is conceptually redundant,
19  but it is used by nodes to check some level of consistency
20  among the block locators from different nodes.
21  
22  The `BlockLocators` struct in this crate is a collection of block locators,
23  organized as two maps from block heights to block hashes:
24  a `checkpoints` map, and a `recents` map,
25  which can be illustrated as follows.
26  ![Block Locators](block-locators.png)
27  The rectangular bar represents the whole blockchain;
28  each circle represents a block locator.
29  See the documentation of `BlockLocators` for details.
30  
31  Besides the `BlockLocators` struct,  this crate provides operations
32  to construct block locators,
33  to check them for well-formedness and consistency,
34  and to serialize and deserialize them to and from bytes.