Skip to content

Commit

Permalink
Remove parallel verification (neo-project#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and Tommo-L committed Jun 22, 2020
1 parent e5d3663 commit a2594db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
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

0 comments on commit a2594db

Please sign in to comment.