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

Optimize Ping message #1903

Merged
merged 24 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ private VerifyResult OnNewBlock(Block block)
return VerifyResult.Invalid;
block_cache.TryAdd(block.Hash, block);
block_cache_unverified.Remove(block.Index);
// We can store the new block in block_cache and tell the new height to other nodes before Persist().
system.LocalNode.Tell(Message.Create(MessageCommand.Ping, PingPayload.Create(Singleton.Height + 1)));
Persist(block);
SaveHeaderHashList();
if (block_cache_unverified.TryGetValue(Height + 1, out var unverifiedBlocks))
Expand All @@ -359,6 +357,8 @@ private VerifyResult OnNewBlock(Block block)
Self.Tell(unverifiedBlock, ActorRefs.NoSender);
Copy link
Member

Choose a reason for hiding this comment

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

This is not parallel, right?
In this sense, we were telling heights that were cached?

Copy link
Member Author

Choose a reason for hiding this comment

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

previously was before persists, now after it

block_cache_unverified.Remove(Height + 1);
}
// We can store the new block in block_cache and tell the new height to other nodes after Persist().
system.LocalNode.Tell(Message.Create(MessageCommand.Ping, PingPayload.Create(Singleton.Height)));
}
return VerifyResult.Succeed;
}
Expand Down
6 changes: 6 additions & 0 deletions src/neo/Network/P2P/RemoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal class Relay { public IInventory Inventory; }
public int ListenerTcpPort { get; private set; } = 0;
public VersionPayload Version { get; private set; }
public uint LastBlockIndex { get; private set; } = 0;
public uint LastHeightSent { get; private set; } = 0;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
public bool IsFullNode { get; private set; } = false;

public RemoteNode(NeoSystem system, object connection, IPEndPoint remote, IPEndPoint local)
Expand Down Expand Up @@ -124,6 +125,11 @@ protected override void OnReceive(object message)
RefreshPendingKnownHashes();
break;
case Message msg:
if (msg.Command == MessageCommand.Ping && msg.Payload is PingPayload ping)
{
if (LastHeightSent >= ping.LastBlockIndex) return;
LastHeightSent = ping.LastBlockIndex;
}
EnqueueMessage(msg);
break;
case IInventory inventory:
Expand Down