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

Remove parallel verification #1429

Merged
merged 10 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
37 changes: 5 additions & 32 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Import { public IEnumerable<Block> Blocks; public bool Verify = tru
public class ImportCompleted { }
public class FillMemoryPool { public IEnumerable<Transaction> Transactions; }
public class FillCompleted { }
private class ParallelVerified { public Transaction Transaction; public bool ShouldRelay; public RelayResultReason VerifyResult; }

public static readonly uint MillisecondsPerBlock = ProtocolSettings.Default.MillisecondsPerBlock;
public const uint DecrementInterval = 2000000;
Expand Down Expand Up @@ -407,39 +406,16 @@ private void OnNewTransaction(Transaction transaction, bool relay)
else if (!MemPool.CanTransactionFitInPool(transaction))
reason = RelayResultReason.OutOfMemory;
else
reason = transaction.VerifyForEachBlock(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(transaction.Sender));
if (reason == RelayResultReason.Succeed)
{
Task.Run(() =>
{
return new ParallelVerified
{
Transaction = transaction,
ShouldRelay = relay,
VerifyResult = transaction.VerifyParallelParts(currentSnapshot)
};
}).PipeTo(Self, Sender);
}
else
{
Sender.Tell(reason);
}
}
reason = transaction.Verify(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(transaction.Sender));

private void OnParallelVerified(ParallelVerified parallelVerified)
{
RelayResultReason reason = parallelVerified.VerifyResult;
if (reason == RelayResultReason.Succeed)
{
if (View.ContainsTransaction(parallelVerified.Transaction.Hash))
reason = RelayResultReason.AlreadyExists;
else if (!MemPool.CanTransactionFitInPool(parallelVerified.Transaction))
if (!MemPool.TryAdd(transaction.Hash, transaction))
reason = RelayResultReason.OutOfMemory;
else if (!MemPool.TryAdd(parallelVerified.Transaction.Hash, parallelVerified.Transaction))
reason = RelayResultReason.OutOfMemory;
else if (parallelVerified.ShouldRelay)
system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = parallelVerified.Transaction });
else if (relay)
system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = transaction });
}

Sender.Tell(reason);
}

Expand Down Expand Up @@ -475,9 +451,6 @@ protected override void OnReceive(object message)
case Transaction transaction:
OnNewTransaction(transaction, true);
break;
case ParallelVerified parallelVerified:
OnParallelVerified(parallelVerified);
break;
case ConsensusPayload payload:
Sender.Tell(OnNewConsensus(payload));
break;
Expand Down
11 changes: 3 additions & 8 deletions src/neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ bool IInventory.Verify(StoreView snapshot)
return Verify(snapshot, BigInteger.Zero) == RelayResultReason.Succeed;
}

public virtual RelayResultReason Verify(StoreView snapshot, BigInteger totalSenderFeeFromPool)
{
RelayResultReason result = VerifyForEachBlock(snapshot, totalSenderFeeFromPool);
if (result != RelayResultReason.Succeed) return result;
return VerifyParallelParts(snapshot);
}

public virtual RelayResultReason VerifyForEachBlock(StoreView snapshot, BigInteger totalSenderFeeFromPool)
{
if (ValidUntilBlock <= snapshot.Height || ValidUntilBlock > snapshot.Height + MaxValidUntilBlockIncrement)
Expand All @@ -292,8 +285,10 @@ public virtual RelayResultReason VerifyForEachBlock(StoreView snapshot, BigInteg
return RelayResultReason.Succeed;
}

public RelayResultReason VerifyParallelParts(StoreView snapshot)
public virtual RelayResultReason Verify(StoreView snapshot, BigInteger totalSenderFeeFromPool)
{
RelayResultReason result = VerifyForEachBlock(snapshot, totalSenderFeeFromPool);
if (result != RelayResultReason.Succeed) return result;
int size = Size;
if (size > MaxTransactionSize) return RelayResultReason.Invalid;
long net_fee = NetworkFee - size * NativeContract.Policy.GetFeePerByte(snapshot);
Expand Down