Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Jan 28, 2021
1 parent 0bf2752 commit d0cf078
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ public SnapshotCache GetSnapshot()

private void OnImport(IEnumerable<Block> blocks, bool verify)
{
uint currentHeight = NativeContract.Ledger.CurrentIndex(View);
DataCache snapshot = View;
uint currentHeight = NativeContract.Ledger.CurrentIndex(snapshot);
foreach (Block block in blocks)
{
if (block.Index <= currentHeight) continue;
if (block.Index != currentHeight + 1)
throw new InvalidOperationException();
if (verify && !block.Verify(View))
if (verify && !block.Verify(snapshot))
throw new InvalidOperationException();
Persist(block);
++currentHeight;
Expand Down Expand Up @@ -215,7 +216,8 @@ private void OnInventory(IInventory inventory, bool relay = true)

private VerifyResult OnNewBlock(Block block)
{
uint currentHeight = NativeContract.Ledger.CurrentIndex(View);
DataCache snapshot = View;
uint currentHeight = NativeContract.Ledger.CurrentIndex(snapshot);
if (block.Index <= currentHeight)
return VerifyResult.AlreadyExists;
if (block.Index - 1 > currentHeight)
Expand All @@ -225,7 +227,7 @@ private VerifyResult OnNewBlock(Block block)
}
if (block.Index == currentHeight + 1)
{
if (!block.Verify(View))
if (!block.Verify(snapshot))
return VerifyResult.Invalid;
block_cache.TryAdd(block.Hash, block);
block_cache_unverified.Remove(block.Index);
Expand Down

0 comments on commit d0cf078

Please sign in to comment.