Skip to content

Commit

Permalink
Allow to verify import blocks (#1415)
Browse files Browse the repository at this point in the history
* Verify Import

* Default true
  • Loading branch information
shargon committed Jan 17, 2020
1 parent fc1a64b commit d5ec715
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed partial class Blockchain : UntypedActor
{
public partial class ApplicationExecuted { }
public class PersistCompleted { public Block Block; }
public class Import { public IEnumerable<Block> Blocks; }
public class Import { public IEnumerable<Block> Blocks; public bool Verify = true; }
public class ImportCompleted { }
public class FillMemoryPool { public IEnumerable<Transaction> Transactions; }
public class FillCompleted { }
Expand Down Expand Up @@ -239,13 +239,15 @@ public Transaction GetTransaction(UInt256 hash)
return View.GetTransaction(hash);
}

private void OnImport(IEnumerable<Block> blocks)
private void OnImport(IEnumerable<Block> blocks, bool verify)
{
foreach (Block block in blocks)
{
if (block.Index <= Height) continue;
if (block.Index != Height + 1)
throw new InvalidOperationException();
if (verify && !block.Verify(currentSnapshot))
throw new InvalidOperationException();
Persist(block);
SaveHeaderHashList();
}
Expand Down Expand Up @@ -453,7 +455,7 @@ protected override void OnReceive(object message)
switch (message)
{
case Import import:
OnImport(import.Blocks);
OnImport(import.Blocks, import.Verify);
break;
case FillMemoryPool fill:
OnFillMemoryPool(fill.Transactions);
Expand Down

0 comments on commit d5ec715

Please sign in to comment.