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

Variables renaming on TaskManager #1185

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion neo.UnitTests/Network/P2P/UT_TaskManagerMailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
28 changes: 16 additions & 12 deletions neo/Network/P2P/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -60,7 +60,7 @@ private void OnNewTasks(InvPayload payload)
HashSet<UInt256> hashes = new HashSet<UInt256>(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)
Expand Down Expand Up @@ -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();
Expand All @@ -115,7 +115,11 @@ private void OnRegister(VersionPayload version)
RequestTasks(session);
}

private void OnRestartTasks(InvPayload payload)
/// <summary>
/// Receives the InvPayload of ConsensusService actors and cleans txs hashes in order to ensure new requests
/// </summary>
/// <param name="payload">An InvPayload payload that contains transactions that are missing in order to check a Block proposed by current Speaker </param>
private void OnConsensusTxsTask(InvPayload payload)
{
knownHashes.ExceptWith(payload.Hashes);
foreach (UInt256 hash in payload.Hashes)
Expand All @@ -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);
Expand Down Expand Up @@ -201,19 +205,19 @@ 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<UInt256> hashes = new HashSet<UInt256>(session.AvailableTasks);
session.InvBlockPendingTasks.Remove(knownHashes);
session.InvBlockPendingTasks.RemoveWhere(p => Blockchain.Singleton.ContainsBlock(p));
HashSet<UInt256> hashes = new HashSet<UInt256>(session.InvBlockPendingTasks);
if (hashes.Count > 0)
{
foreach (UInt256 hash in hashes.ToArray())
{
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()))
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion neo/Network/P2P/TaskSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ internal class TaskSession
public readonly IActorRef RemoteNode;
public readonly VersionPayload Version;
public readonly Dictionary<UInt256, DateTime> Tasks = new Dictionary<UInt256, DateTime>();
public readonly HashSet<UInt256> AvailableTasks = new HashSet<UInt256>();
/// <summary>
/// Pending high priority tasks of type `InventoryType.Block`
/// </summary>
public readonly HashSet<UInt256> InvBlockPendingTasks = new HashSet<UInt256>();
shargon marked this conversation as resolved.
Show resolved Hide resolved

public bool HasTask => Tasks.Count > 0;
public uint StartHeight { get; }
Expand Down