From ff850c5e170a8a132132de9aea6168b0668125aa Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 3 Mar 2020 07:40:06 +0100 Subject: [PATCH] Remove parallel verification (#1429) --- src/neo/Ledger/Blockchain.cs | 37 +++------------------ src/neo/Network/P2P/Payloads/Transaction.cs | 11 ++---- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/neo/Ledger/Blockchain.cs b/src/neo/Ledger/Blockchain.cs index 9090a5b339..65bba7bee0 100644 --- a/src/neo/Ledger/Blockchain.cs +++ b/src/neo/Ledger/Blockchain.cs @@ -27,7 +27,6 @@ public class Import { public IEnumerable Blocks; public bool Verify = tru public class ImportCompleted { } public class FillMemoryPool { public IEnumerable 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; @@ -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); } @@ -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; diff --git a/src/neo/Network/P2P/Payloads/Transaction.cs b/src/neo/Network/P2P/Payloads/Transaction.cs index 2b6523a6aa..e511e17c94 100644 --- a/src/neo/Network/P2P/Payloads/Transaction.cs +++ b/src/neo/Network/P2P/Payloads/Transaction.cs @@ -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) @@ -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);