Skip to content

The new mechanism of block synchronization using Index. #1378

@ShawnYun

Description

@ShawnYun

Background

Thanks to @ixje @erikzhang @vncoelho @jsolman @shargon for the discussion in #522, #1138, #781, and added a new p2p message for GetBlockData.
Now, we will discuss the new mechanism of block synchronization using Index.

Do you have any solution you want to propose?

We recommend creating a new SyncManager class that manages synchronization, while TaskManager handles Inv messages. The overall mechanism process is as follows:

1

Process:

  1. Get the latest block height of remotenode through PingPong messages.

  2. Calculate the block segments to be synchronized based on the current local block height and remotenode block height. According to the task interval rule (for example, each task can synchronize a maximum of 50 blocks), the block segment is divided into several synchronous tasks. Select a suitable node according to the task assignment rule and assign synchronous task to it. Save the startIndex, endIndex, task time and other information of the synchronization task. Send the GetBlockdata request.

  3. Each task maintains a BitArray to record the received blocks’ index. Find the corresponding task for each received block, and set the bit corresponding to the index of the received block to true. Then, tell the received block to Blockchain.

  4. Blockchain verifies the block and persists it, then tell the index of the persisted block to SyncManager.

  5. SyncManager checks the index of the persisted block. If the index reaches the endIndex of a task, check the list of all tasks, delete the corresponding completed task, and assign a new task to the node.

Task assignment rule:
Assign task to the node with the lowest number of tasks.

Task interval rule:
startIndex is the endIndex of the previous task + 1; EndIndex is the height that is greater than and nearest to startIndex and divisible by 50.

Exception handling:

  1. The Timer will check the task timeout, and if the task is timed out, the corresponding task will be re-assigned to other nodes.

  2. If blockchain receives a invalid block, tell to SyncManager and reassign the task to other node.(the node sending the invalid block can be marked as a bad node)

Neo Version

  • Neo 3

Where in the software does this update applies to?

  • Ledger
  • P2P (TCP)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionInitial issue state - proposed but not yet accepted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions