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

[master-2.x] Force sync state root from all peers #1854

Merged
merged 6 commits into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions neo/Network/P2P/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private class Timer { }
private readonly UInt256 StateRootTaskHash = UInt256.Parse("0x0000000000000000000000000000000000000000000000000000000000000001");
private bool HasHeaderTask => globalTasks.ContainsKey(HeaderTaskHash);
private bool HasStateRootTask => globalTasks.ContainsKey(StateRootTaskHash);
private DateTime StateRootSyncTime;

public TaskManager(NeoSystem system)
{
Expand Down Expand Up @@ -212,6 +213,10 @@ private void OnTimer()
if (session.Tasks.Remove(task.Key))
DecrementGlobalTask(task.Key);
}

if (HasStateRootTask && DateTime.UtcNow - StateRootSyncTime > TaskTimeout)
DecrementGlobalTask(StateRootTaskHash);

foreach (TaskSession session in sessions.Values)
RequestTasks(session);
}
Expand Down Expand Up @@ -279,15 +284,11 @@ private void RequestTasks(TaskSession session)
{
if (Blockchain.Singleton.ExpectStateRootIndex < Blockchain.Singleton.Height)
{
var state = Blockchain.Singleton.GetStateRoot(Blockchain.Singleton.ExpectStateRootIndex);
if (state is null || state.Flag == StateRootVerifyFlag.Unverified)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After every block persisted, local state root will be calculated and persist into StateRoots with Unverified flag. Only check the block height is enough.

PersistLocalStateRoot();

{
var start_index = Blockchain.Singleton.ExpectStateRootIndex;
var count = Math.Min(Blockchain.Singleton.Height - start_index, StateRootsPayload.MaxStateRootsCount);
session.Tasks[StateRootTaskHash] = DateTime.UtcNow;
IncrementGlobalTask(StateRootTaskHash);
session.RemoteNode.Tell(Message.Create("getroots", GetStateRootsPayload.Create(start_index, count)));
}
var start_index = Blockchain.Singleton.ExpectStateRootIndex;
var count = Math.Min(Blockchain.Singleton.Height - start_index, StateRootsPayload.MaxStateRootsCount);
StateRootSyncTime = DateTime.UtcNow;
IncrementGlobalTask(StateRootTaskHash);
system.LocalNode.Tell(Message.Create("getroots", GetStateRootsPayload.Create(start_index, count)));
}
}
}
Expand Down