Skip to content

Commit

Permalink
Small optimizations using cached VM Script (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and erikzhang committed Nov 26, 2019
1 parent 8005e90 commit 84d6190
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class FillCompleted { }
Transactions = new[] { DeployNativeContracts() }
};

private readonly static byte[] onPersistNativeContractScript;
private readonly static Script onPersistNativeContractScript;
private const int MaxTxToReverifyPerIdle = 10;
private static readonly object lockObj = new object();
private readonly NeoSystem system;
Expand Down Expand Up @@ -323,8 +323,7 @@ private RelayResultReason OnNewBlock(Block block)
using (Snapshot snapshot = GetSnapshot())
{
snapshot.Blocks.Add(block.Hash, block.Header.Trim());
snapshot.HeaderHashIndex.GetAndChange().Hash = block.Hash;
snapshot.HeaderHashIndex.GetAndChange().Index = block.Index;
snapshot.HeaderHashIndex.GetAndChange().Set(block);
SaveHeaderHashList(snapshot);
snapshot.Commit();
}
Expand Down
2 changes: 0 additions & 2 deletions src/neo/Network/P2P/Payloads/Header.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Neo.IO.Json;
using Neo.Ledger;
using Neo.Wallets;
using System;
using System.IO;
using System.Linq;

namespace Neo.Network.P2P.Payloads
{
Expand Down
4 changes: 2 additions & 2 deletions src/neo/SmartContract/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, Snapshot snaps
{
engine.LoadScript(verification);
engine.LoadScript(verifiable.Witnesses[i].InvocationScript);
if (engine.Execute().HasFlag(VMState.FAULT)) return false;
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().ToBoolean()) return false;
if (engine.Execute() == VMState.FAULT) return false;
if (!engine.ResultStack.TryPop(out var result) || !result.ToBoolean()) return false;
}
}
return true;
Expand Down

0 comments on commit 84d6190

Please sign in to comment.