Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing searches divergent branches #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

liamzebedee
Copy link
Collaborator

@liamzebedee liamzebedee commented Aug 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant