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

Avoid processing own messages (2x) #1010

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions neo/IO/Caching/FIFOSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public bool Add(T item)
return true;
}

public bool Contains(T item)
{
return dictionary.Contains(item);
}

public void ExceptWith(IEnumerable<UInt256> hashes)
{
foreach (var hash in hashes)
Expand Down
2 changes: 1 addition & 1 deletion neo/Network/P2P/ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void OnInventoryReceived(IInventory inventory)

private void OnInvMessageReceived(InvPayload payload)
{
UInt256[] hashes = payload.Hashes.Where(p => knownHashes.Add(p)).ToArray();
UInt256[] hashes = payload.Hashes.Where(p => knownHashes.Add(p) && !sentHashes.Contains(p)).ToArray();
Copy link
Contributor

@igormcoelho igormcoelho Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will naturally add to knownHashes, as Add will run before sentHashes is verified... interesting.
If this is not intended, we need to reverse this && here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intend is to verify this:

            bool sentByMe = payload.Hashes.Any(p => sentHashes.Contains(p));
            if (hashes.Length == 0 || sentByMe) return;

Check if there is Any of this hashes in the SentHashes.

Is this the same as it is? Shargon suggested this embed in a single line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And where is p => knownHashes.Add(p) part? hahahah

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IO caching Fifoset

if (hashes.Length == 0) return;
vncoelho marked this conversation as resolved.
Show resolved Hide resolved
switch (payload.Type)
{
Expand Down