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

Remove currentSnapshot #2273

Merged
merged 7 commits into from
Jan 28, 2021
Merged
Changes from 1 commit
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: 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))
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
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