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

Renaming two variables related to Consensus Reverification of txs #1162

Closed
wants to merge 2 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 @@ -462,7 +462,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
13 changes: 9 additions & 4 deletions neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot)
return hashes.OrderBy(p => p).ToArray();
}

public virtual bool Reverify(Snapshot snapshot, IEnumerable<Transaction> mempool)
public virtual bool Reverify(Snapshot snapshot, IEnumerable<Transaction> transactionsPool)
{
if (ValidUntilBlock <= snapshot.Height || ValidUntilBlock > snapshot.Height + MaxValidUntilBlockIncrement)
return false;
Expand All @@ -139,7 +139,7 @@ public virtual bool Reverify(Snapshot snapshot, IEnumerable<Transaction> mempool
BigInteger balance = NativeContract.GAS.BalanceOf(snapshot, Sender);
BigInteger fee = SystemFee + NetworkFee;
if (balance < fee) return false;
fee += mempool.Where(p => p != this && p.Sender.Equals(Sender)).Select(p => (BigInteger)(p.SystemFee + p.NetworkFee)).Sum();
fee += transactionsPool.Where(p => p != this && p.Sender.Equals(Sender)).Select(p => (BigInteger)(p.SystemFee + p.NetworkFee)).Sum();
if (balance < fee) return false;
UInt160[] hashes = GetScriptHashesForVerifying(snapshot);
if (hashes.Length != Witnesses.Length) return false;
Expand Down Expand Up @@ -209,9 +209,14 @@ bool IInventory.Verify(Snapshot snapshot)
return Verify(snapshot, Enumerable.Empty<Transaction>());
}

public virtual bool Verify(Snapshot snapshot, IEnumerable<Transaction> mempool)
/// <summary>
/// Verifies the transactions against a snapshot and a set of transactions
/// </summary>
/// <param name="snapshot">A snapshot of the current </param>
/// <param name="transactionsPool">Usually local node memorypool or consensus node list of transactions proposed by a speaker</param>
public virtual bool Verify(Snapshot snapshot, IEnumerable<Transaction> transactionsPool)
{
if (!Reverify(snapshot, mempool)) return false;
if (!Reverify(snapshot, transactionsPool)) return false;
int size = Size;
if (size > MaxTransactionSize) return false;
long net_fee = NetworkFee - size * NativeContract.Policy.GetFeePerByte(snapshot);
Expand Down
14 changes: 9 additions & 5 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 @@ -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 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