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

[master-2.x] Add try-catch when receive a new tx #2066

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
32 changes: 19 additions & 13 deletions neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,26 @@ private void OnNewHeaders(Header[] headers)

private RelayResultReason OnNewTransaction(Transaction transaction)
{
if (transaction.Type == TransactionType.MinerTransaction)
return RelayResultReason.Invalid;
if (ContainsTransaction(transaction.Hash))
return RelayResultReason.AlreadyExists;
if (!MemPool.CanTransactionFitInPool(transaction))
return RelayResultReason.OutOfMemory;
if (!transaction.Verify(currentSnapshot, MemPool.GetVerifiedTransactions()))
return RelayResultReason.Invalid;
if (!Plugin.CheckPolicy(transaction))
return RelayResultReason.PolicyFail;

if (!MemPool.TryAdd(transaction.Hash, transaction))
return RelayResultReason.OutOfMemory;
try
{
if (transaction.Type == TransactionType.MinerTransaction)
return RelayResultReason.Invalid;
if (ContainsTransaction(transaction.Hash))
return RelayResultReason.AlreadyExists;
if (!MemPool.CanTransactionFitInPool(transaction))
return RelayResultReason.OutOfMemory;
if (!transaction.Verify(currentSnapshot, MemPool.GetVerifiedTransactions()))
return RelayResultReason.Invalid;
if (!Plugin.CheckPolicy(transaction))
return RelayResultReason.PolicyFail;

if (!MemPool.TryAdd(transaction.Hash, transaction))
return RelayResultReason.OutOfMemory;
}
catch
{
return RelayResultReason.Error;
}
system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = transaction });
return RelayResultReason.Succeed;
}
Expand Down
3 changes: 2 additions & 1 deletion neo/Ledger/RelayResultReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum RelayResultReason : byte
UnableToVerify,
Invalid,
PolicyFail,
Unknown
Unknown,
Error
}
}