diff --git a/neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs b/neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs index fca280d1eb..860166ff86 100644 --- a/neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs +++ b/neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs @@ -34,7 +34,7 @@ public void TaskManager_Test_IsHighPriority() { // high priority uut.IsHighPriority(new TaskManager.Register()).Should().Be(true); - uut.IsHighPriority(new TaskManager.RestartTasks()).Should().Be(true); + uut.IsHighPriority(new TaskManager.ConsensusTxsTask()).Should().Be(true); // low priority // -> NewTasks: generic InvPayload diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index 9d0bd5a343..13e4eb6a3b 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -464,7 +464,7 @@ private void OnPrepareRequestReceived(ConsensusPayload payload, PrepareRequest m if (context.Transactions.Count < context.TransactionHashes.Length) { UInt256[] hashes = context.TransactionHashes.Where(i => !context.Transactions.ContainsKey(i)).ToArray(); - taskManager.Tell(new TaskManager.RestartTasks + taskManager.Tell(new TaskManager.ConsensusTxsTask { Payload = InvPayload.Create(InventoryType.TX, hashes) }); diff --git a/neo/Network/P2P/TaskManager.cs b/neo/Network/P2P/TaskManager.cs index 82e2e9b87a..4b649084d5 100644 --- a/neo/Network/P2P/TaskManager.cs +++ b/neo/Network/P2P/TaskManager.cs @@ -17,7 +17,7 @@ public class Register { public VersionPayload Version; } public class NewTasks { public InvPayload Payload; } public class TaskCompleted { public UInt256 Hash; } public class HeaderTaskCompleted { } - public class RestartTasks { public InvPayload Payload; } + public class ConsensusTxsTask { public InvPayload Payload; } private class Timer { } private static readonly TimeSpan TimerInterval = TimeSpan.FromSeconds(30); @@ -60,7 +60,7 @@ private void OnNewTasks(InvPayload payload) HashSet hashes = new HashSet(payload.Hashes); hashes.Remove(knownHashes); if (payload.Type == InventoryType.Block) - session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); + session.InvBlockPendingTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p))); hashes.Remove(globalTasks); if (hashes.Count == 0) @@ -95,8 +95,8 @@ protected override void OnReceive(object message) case HeaderTaskCompleted _: OnHeaderTaskCompleted(); break; - case RestartTasks restart: - OnRestartTasks(restart.Payload); + case ConsensusTxsTask consensusTask: + OnConsensusTxsTask(consensusTask.Payload); break; case Timer _: OnTimer(); @@ -115,7 +115,11 @@ private void OnRegister(VersionPayload version) RequestTasks(session); } - private void OnRestartTasks(InvPayload payload) + /// + /// Receives the InvPayload of ConsensusService actors and cleans txs hashes in order to ensure new requests + /// + /// An InvPayload payload that contains transactions that are missing in order to check a Block proposed by current Speaker + private void OnConsensusTxsTask(InvPayload payload) { knownHashes.ExceptWith(payload.Hashes); foreach (UInt256 hash in payload.Hashes) @@ -129,7 +133,7 @@ private void OnTaskCompleted(UInt256 hash) knownHashes.Add(hash); globalTasks.Remove(hash); foreach (TaskSession ms in sessions.Values) - ms.AvailableTasks.Remove(hash); + ms.InvBlockPendingTasks.Remove(hash); if (sessions.TryGetValue(Sender, out TaskSession session)) { session.Tasks.Remove(hash); @@ -201,11 +205,11 @@ public static Props Props(NeoSystem system) private void RequestTasks(TaskSession session) { if (session.HasTask) return; - if (session.AvailableTasks.Count > 0) + if (session.InvBlockPendingTasks.Count > 0) { - session.AvailableTasks.Remove(knownHashes); - session.AvailableTasks.RemoveWhere(p => Blockchain.Singleton.ContainsBlock(p)); - HashSet hashes = new HashSet(session.AvailableTasks); + session.InvBlockPendingTasks.Remove(knownHashes); + session.InvBlockPendingTasks.RemoveWhere(p => Blockchain.Singleton.ContainsBlock(p)); + HashSet hashes = new HashSet(session.InvBlockPendingTasks); if (hashes.Count > 0) { foreach (UInt256 hash in hashes.ToArray()) @@ -213,7 +217,7 @@ private void RequestTasks(TaskSession session) if (!IncrementGlobalTask(hash)) hashes.Remove(hash); } - session.AvailableTasks.Remove(hashes); + session.InvBlockPendingTasks.Remove(hashes); foreach (UInt256 hash in hashes) session.Tasks[hash] = DateTime.UtcNow; foreach (InvPayload group in InvPayload.CreateGroup(InventoryType.Block, hashes.ToArray())) @@ -256,7 +260,7 @@ internal protected override bool IsHighPriority(object message) switch (message) { case TaskManager.Register _: - case TaskManager.RestartTasks _: + case TaskManager.ConsensusTxsTask _: return true; case TaskManager.NewTasks tasks: if (tasks.Payload.Type == InventoryType.Block || tasks.Payload.Type == InventoryType.Consensus) diff --git a/neo/Network/P2P/TaskSession.cs b/neo/Network/P2P/TaskSession.cs index a1cf8a0ffc..7f79290906 100644 --- a/neo/Network/P2P/TaskSession.cs +++ b/neo/Network/P2P/TaskSession.cs @@ -12,7 +12,10 @@ internal class TaskSession public readonly IActorRef RemoteNode; public readonly VersionPayload Version; public readonly Dictionary Tasks = new Dictionary(); - public readonly HashSet AvailableTasks = new HashSet(); + /// + /// Pending high priority tasks of type `InventoryType.Block` + /// + public readonly HashSet InvBlockPendingTasks = new HashSet(); public bool HasTask => Tasks.Count > 0; public uint StartHeight { get; }