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

Not found command #1645

Merged
merged 4 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions src/neo/Network/P2P/MessageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@ private void OnGetBlockDataMessageReceived(GetBlockDataPayload payload)
/// <param name="payload">The payload containing the requested information.</param>
private void OnGetDataMessageReceived(InvPayload payload)
{
UInt256[] hashes = payload.Hashes.Where(p => sentHashes.Add(p)).ToArray();
foreach (UInt256 hash in hashes)
var notFound = new List<UInt256>();
foreach (UInt256 hash in payload.Hashes.Where(p => sentHashes.Add(p)))
{
switch (payload.Type)
{
case InventoryType.TX:
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);
Expand All @@ -241,13 +243,23 @@ 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))
EnqueueMessage(Message.Create(MessageCommand.Consensus, inventoryConsensus));
break;
}
}

if (notFound.Count > 0)
{
foreach (InvPayload entry in InvPayload.CreateGroup(payload.Type, notFound.ToArray()))
EnqueueMessage(Message.Create(MessageCommand.NotFound, entry));
}
}

/// <summary>
Expand Down