tinychain icon indicating copy to clipboard operation
tinychain copied to clipboard

Syncing searches divergent branches

Open liamzebedee opened this issue 6 months ago • 0 comments

Right now, in testnet1, the network behaves in a single-producer many-follower consensus mode. While the block DAG correctly determines the heaviest chain from a history of blocks, the sync algorithm does not yet search divergent branch histories (ie forks) from nodes.

Sync is implemented as a greedy search, which starts from a base tip and requests windows of 2048 blocks. The tip we start at is our local headers tip:

https://github.com/tinychainorg/tinychain/blob/main/core/nakamoto/sync.go#L301

As such, the node when it hears of a block on an alternative branch does not download it. And so testnet1 can support proper nakamoto POW branching, once it starts downloading alternative branches too.

The improvement proposed in this PR is to search on divergent branches and download history.

The way this will work:

  1. Interactive binary search to find common ancestor when we hear of a new block we don't know. a. First check this remote tip has more accumulated work than the current local tip.
  2. Perform the search algorithm from this common ancestor.
  3. Download blocks.

liamzebedee avatar Aug 06 '24 06:08 liamzebedee