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

Add relay-block-filter #1380

Merged
merged 12 commits into from
Jan 6, 2020
19 changes: 17 additions & 2 deletions src/neo/Network/P2P/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected override void NeedMorePeers(int count)
else
{
// Will call AddPeers with default SeedList set cached on <see cref="ProtocolSettings"/>.
// It will try to add those, sequentially, to the list of currently uncconected ones.
// It will try to add those, sequentially, to the list of currently unconnected ones.

Random rand = new Random();
AddPeers(SeedList.Where(u => u != null).OrderBy(p => rand.Next()).Take(count));
Expand Down Expand Up @@ -197,7 +197,22 @@ private void OnRelay(IInventory inventory)
system.Blockchain.Tell(inventory);
}

private void OnRelayDirectly(IInventory inventory) => SendToRemoteNodes(new RemoteNode.Relay { Inventory = inventory });
private void OnRelayDirectly(IInventory inventory)
{
var message = new RemoteNode.Relay { Inventory = inventory };
// When relaying a block, if the block's index is greater than 'LastBlockIndex' of the RemoteNode, relay the block;
// otherwise, don't relay.
if (inventory is Block block)
{
foreach (KeyValuePair<IActorRef, RemoteNode> kvp in RemoteNodes)
{
if (block.Index > kvp.Value.LastBlockIndex)
kvp.Key.Tell(message);
}
}
else
SendToRemoteNodes(message);
}

private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory);

Expand Down