diff --git a/src/neo/Network/P2P/MessageCommand.cs b/src/neo/Network/P2P/MessageCommand.cs index ccddacfba2..771a98a459 100644 --- a/src/neo/Network/P2P/MessageCommand.cs +++ b/src/neo/Network/P2P/MessageCommand.cs @@ -33,6 +33,7 @@ public enum MessageCommand : byte GetData = 0x28, [ReflectionCache(typeof(GetBlockDataPayload))] GetBlockData = 0x29, + [ReflectionCache(typeof(InvPayload))] NotFound = 0x2a, [ReflectionCache(typeof(Transaction))] Transaction = 0x2b, diff --git a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs index 91b3921326..2146501e85 100644 --- a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs +++ b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs @@ -217,8 +217,8 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload) /// The payload containing the requested information. private void OnGetDataMessageReceived(InvPayload payload) { - UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray(); - foreach (UInt256 hash in hashes) + var notFound = new List(); + foreach (UInt256 hash in payload.Hashes.Where(p => sentHashes.Add(p))) { switch (payload.Type) { @@ -226,6 +226,8 @@ private void OnGetDataMessageReceived(InvPayload payload) Transaction tx = Blockchain.Singleton.GetTransaction(hash); if (tx != null) EnqueueMessage(Message.Create(MessageCommand.Transaction, tx)); + else + notFound.Add(hash); break; case InventoryType.Block: Block block = Blockchain.Singleton.GetBlock(hash); @@ -241,6 +243,10 @@ private void OnGetDataMessageReceived(InvPayload payload) EnqueueMessage(Message.Create(MessageCommand.MerkleBlock, MerkleBlockPayload.Create(block, flags))); } } + else + { + notFound.Add(hash); + } break; case InventoryType.Consensus: if (Blockchain.Singleton.ConsensusRelayCache.TryGet(hash, out IInventory inventoryConsensus)) @@ -248,6 +254,12 @@ private void OnGetDataMessageReceived(InvPayload payload) break; } } + + if (notFound.Count > 0) + { + foreach (InvPayload entry in InvPayload.CreateGroup(payload.Type, notFound.ToArray())) + EnqueueMessage(Message.Create(MessageCommand.NotFound, entry)); + } } ///