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:

Process:
-
Get the latest block height of remotenode through PingPong messages.
-
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.
-
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.
-
Blockchain verifies the block and persists it, then tell the index of the persisted block to SyncManager.
-
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:
-
The Timer will check the task timeout, and if the task is timed out, the corresponding task will be re-assigned to other nodes.
-
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
Where in the software does this update applies to?
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
SyncManagerclass that manages synchronization, whileTaskManagerhandlesInvmessages. The overall mechanism process is as follows:Process:
Get the latest block height of remotenode through
PingPongmessages.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.
Each task maintains a
BitArrayto 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.Blockchainverifies the block and persists it, then tell the index of the persisted block toSyncManager.SyncManagerchecks the index of the persisted block. If the index reaches theendIndexof 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:
startIndexis theendIndexof the previous task + 1;EndIndexis the height that is greater than and nearest tostartIndexand divisible by 50.Exception handling:
The Timer will check the task timeout, and if the task is timed out, the corresponding task will be re-assigned to other nodes.
If blockchain receives a invalid block, tell to
SyncManagerand reassign the task to other node.(the node sending the invalid block can be marked as a bad node)Neo Version
Where in the software does this update applies to?