Skip to content

db synchronization #19

@dabasov

Description

@dabasov

When starting node we must synchronize our local DB and download new blocks.
Further algorithm will describe this process in details:

  1. We discover current blockchain height

  2. We optionally discover top blockchain height from the network (via hello message)

  3. We send
    BlockHeadersRequest {
    low: m
    high: m + d
    }
    Receive
    BlockHeadersResponse{
    headers []*BlockHeader
    }

    We can receive chunk less than m +d height, it's normal. The only requirement here that we must receive correct subchain without block absence, orphans will be filtered.
    If chunk is incorrect, we add ban score and retry request (next)

  • We can receive chunk without head on height m, it is normal, since previous responser could not have this exact fork. In this case we start requesting block headers of potential fork sequentially, until we find parent in current blockchain or hit depthLimit.
  • If we received correct chunk and we are able to add it to existing chain and new chain is correct, we start to download block bodies in parallel.
  • It is possible not to receive arbitrary block. In this case we simply drop chunk till this height and request blocks on next height again (go to start)
  • When we receive all blocks, request next blocks.
    For each request we have peer group (f + 1), we send query to first one and expect to receive correct request in time. If we can't, we go to next peer in group. If we asked every peer, we report error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions