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

Cache most recent block #1592

Merged
merged 12 commits into from
Apr 26, 2020
5 changes: 4 additions & 1 deletion src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class RelayResult { public IInventory Inventory; public VerifyResult Resu
public static readonly byte ValidatorsCount = ProtocolSettings.Default.ValidatorsCount;
public static readonly ECPoint[] StandbyCommittee = ProtocolSettings.Default.StandbyCommittee.Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();
public static readonly ECPoint[] StandbyValidators = StandbyCommittee[..ValidatorsCount];
private static UInt256 lastBlockhash = null;

public static readonly Block GenesisBlock = new Block
{
Expand Down Expand Up @@ -367,6 +368,7 @@ private VerifyResult OnNewBlock(Block block)
Self.Tell(unverifiedBlock, ActorRefs.NoSender);
block_cache_unverified.Remove(Height + 1);
}
block_cache.Add(block.Hash, block);
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand Down Expand Up @@ -430,7 +432,8 @@ private VerifyResult OnNewTransaction(Transaction transaction)

private void OnPersistCompleted(Block block)
{
block_cache.Remove(block.Hash);
if (lastBlockhash != null) block_cache.Remove(lastBlockhash);
lastBlockhash = block.Hash;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
MemPool.UpdatePoolForBlockPersisted(block, currentSnapshot);
Context.System.EventStream.Publish(new PersistCompleted { Block = block });
}
Expand Down