From 7a5e54cd3d433def2c9d33b4f419556ed826ed2e Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Mon, 23 Dec 2019 16:45:09 +0800 Subject: [PATCH 1/5] add relay-block-filter --- src/neo/Network/P2P/LocalNode.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index ffd0ac9930..825f7e6e6e 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -155,7 +155,7 @@ protected override void NeedMorePeers(int count) else { // Will call AddPeers with default SeedList set cached on . - // 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)); @@ -197,7 +197,24 @@ 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 higher than 'LastBlockIndex' of the RemoteNode, send the block; + // otherwise, don't send. + if (inventory is Block block) + { + foreach (KeyValuePair kvp in RemoteNodes) + { + if (block.Index > kvp.Value.LastBlockIndex) + kvp.Key.Tell(message); + } + } + else + SendToRemoteNodes(message); + } + private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory); From bd32e9ce519a621ae54215e0398cd6065c9dab21 Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Mon, 23 Dec 2019 16:47:45 +0800 Subject: [PATCH 2/5] modify --- src/neo/Network/P2P/LocalNode.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 825f7e6e6e..16b0cc18d8 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -200,9 +200,8 @@ private void OnRelay(IInventory inventory) private void OnRelayDirectly(IInventory inventory) { var message = new RemoteNode.Relay { Inventory = inventory }; - - // When relaying a block, if the block's index is higher than 'LastBlockIndex' of the RemoteNode, send the block; - // otherwise, don't send. + // When relaying a block, if the block's index is higher than 'LastBlockIndex' of the RemoteNode, relay the block; + // otherwise, don't relay. if (inventory is Block block) { foreach (KeyValuePair kvp in RemoteNodes) From dc82bf87c73581077d374df83bbd9213b1b61964 Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Mon, 23 Dec 2019 17:34:40 +0800 Subject: [PATCH 3/5] modify --- src/neo/Network/P2P/LocalNode.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 16b0cc18d8..436d519f75 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -214,7 +214,6 @@ private void OnRelayDirectly(IInventory inventory) SendToRemoteNodes(message); } - private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory); public static Props Props(NeoSystem system) From a02f02acddf15cdc44ec9bc0e08543449897abb6 Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Mon, 23 Dec 2019 17:49:26 +0800 Subject: [PATCH 4/5] modify --- src/neo/Network/P2P/LocalNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 436d519f75..345a0abebb 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -200,7 +200,7 @@ private void OnRelay(IInventory inventory) private void OnRelayDirectly(IInventory inventory) { var message = new RemoteNode.Relay { Inventory = inventory }; - // When relaying a block, if the block's index is higher than 'LastBlockIndex' of the RemoteNode, relay the block; + // 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) { From a0ad21d3035bf8f09174269e8cc2a205f4ce3b61 Mon Sep 17 00:00:00 2001 From: ShawnYun Date: Mon, 23 Dec 2019 17:54:35 +0800 Subject: [PATCH 5/5] modify --- src/neo/Network/P2P/LocalNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 345a0abebb..bdc4713bfe 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -213,7 +213,7 @@ private void OnRelayDirectly(IInventory inventory) else SendToRemoteNodes(message); } - + private void OnSendDirectly(IInventory inventory) => SendToRemoteNodes(inventory); public static Props Props(NeoSystem system)