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

Small optimizations using cached VM Script #1215

Merged
merged 17 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from 12 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
10 changes: 4 additions & 6 deletions neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ 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;
private readonly List<UInt256> header_index = new List<UInt256>();
private uint stored_header_count = 0;
Expand Down Expand Up @@ -91,7 +90,7 @@ static Blockchain()
foreach (NativeContract contract in contracts)
sb.EmitAppCall(contract.Hash, "onPersist");

onPersistNativeContractScript = sb.ToArray();
onPersistNativeContractScript = new Script(sb.ToArray());
}
}

Expand All @@ -100,7 +99,7 @@ public Blockchain(NeoSystem system, Store store)
this.system = system;
this.MemPool = new MemoryPool(system, ProtocolSettings.Default.MemoryPoolMaxTransactions);
this.Store = store;
lock (lockObj)
lock (typeof(Blockchain))
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
if (singleton != null)
throw new InvalidOperationException();
Expand Down Expand Up @@ -323,8 +322,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 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 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<PrimitiveType>(out var result) || !result.ToBoolean()) return false;
}
}
return true;
Expand Down