diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index f5c1d6bc93..889d4b18bb 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -60,7 +60,7 @@ public class FillCompleted { } private uint stored_header_count = 0; private readonly Dictionary block_cache = new Dictionary(); private readonly Dictionary> block_cache_unverified = new Dictionary>(); - internal readonly RelayCache RelayCache = new RelayCache(100); + internal readonly RelayCache ConsensusRelayCache = new RelayCache(100); private Snapshot currentSnapshot; public Store Store { get; } @@ -328,7 +328,7 @@ private RelayResultReason OnNewConsensus(ConsensusPayload payload) { if (!payload.Verify(currentSnapshot)) return RelayResultReason.Invalid; system.Consensus?.Tell(payload); - RelayCache.Add(payload); + ConsensusRelayCache.Add(payload); system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = payload }); return RelayResultReason.Succeed; } diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index 234c42d9ef..63ecbe3318 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -180,23 +180,20 @@ private void OnGetDataMessageReceived(InvPayload payload) UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); foreach (UInt256 hash in hashes) { - Blockchain.Singleton.RelayCache.TryGet(hash, out IInventory inventory); switch (payload.Type) { case InventoryType.TX: - if (inventory == null) - inventory = Blockchain.Singleton.GetTransaction(hash); - if (inventory is Transaction) - Context.Parent.Tell(Message.Create(MessageCommand.Transaction, inventory)); + Transaction tx = Blockchain.Singleton.GetTransaction(hash); + if (tx != null) + Context.Parent.Tell(Message.Create(MessageCommand.Transaction, tx)); break; case InventoryType.Block: - if (inventory == null) - inventory = Blockchain.Singleton.GetBlock(hash); - if (inventory is Block block) + Block block = Blockchain.Singleton.GetBlock(hash); + if (block != null) { if (bloom_filter == null) { - Context.Parent.Tell(Message.Create(MessageCommand.Block, inventory)); + Context.Parent.Tell(Message.Create(MessageCommand.Block, block)); } else { @@ -206,8 +203,8 @@ private void OnGetDataMessageReceived(InvPayload payload) } break; case InventoryType.Consensus: - if (inventory != null) - Context.Parent.Tell(Message.Create(MessageCommand.Consensus, inventory)); + if (Blockchain.Singleton.ConsensusRelayCache.TryGet(hash, out IInventory inventoryConsensus)) + Context.Parent.Tell(Message.Create(MessageCommand.Consensus, inventoryConsensus)); break; } }