From 1b6d7f15eff95e6c6782d40e1631032d1f6c120b Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 13:02:49 +0100 Subject: [PATCH 01/13] Peer discovery tweak --- src/Nethermind/Nethermind.Network/PeerManager.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index af3155806b7..d92f7c24f7b 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -333,6 +333,9 @@ private async Task RunPeerUpdateLoop() if (_peerPool.ActivePeerCount < MaxActivePeers) { + // We been though all the peers once, so slight additional delay before + // trying them again to avoid busy loop + await Task.Delay(1000); _peerUpdateRequested.Set(); } From e7af98b9d25ca56cfbd01b23ba2cb3bf7d1c5263 Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 13:25:39 +0100 Subject: [PATCH 02/13] Make 10 secs --- src/Nethermind/Nethermind.Network/PeerManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index d92f7c24f7b..f813e847061 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -335,7 +335,7 @@ private async Task RunPeerUpdateLoop() { // We been though all the peers once, so slight additional delay before // trying them again to avoid busy loop - await Task.Delay(1000); + await Task.Delay(10_000); _peerUpdateRequested.Set(); } From 61abb2fd017123a47cdfb265e5fae766c5f28ef0 Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 13:28:35 +0100 Subject: [PATCH 03/13] Wait TIME-WAIT --- src/Nethermind/Nethermind.Network/PeerManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index f813e847061..dfd8a0310a6 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -333,9 +333,9 @@ private async Task RunPeerUpdateLoop() if (_peerPool.ActivePeerCount < MaxActivePeers) { - // We been though all the peers once, so slight additional delay before - // trying them again to avoid busy loop - await Task.Delay(10_000); + // We been though all the peers once, so wait TIME-WAIT additional delay before + // trying them again to avoid busy loop or exhausting sockets. + await Task.Delay(60_000); _peerUpdateRequested.Set(); } From 84376fddff3d93aaa6694dbe4546ceea67e26555 Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 13:31:07 +0100 Subject: [PATCH 04/13] Add constant --- src/Nethermind/Nethermind.Network/PeerManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index dfd8a0310a6..c27fac0e924 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -333,9 +333,10 @@ private async Task RunPeerUpdateLoop() if (_peerPool.ActivePeerCount < MaxActivePeers) { + const int TIME_WAIT = 60_000; // We been though all the peers once, so wait TIME-WAIT additional delay before // trying them again to avoid busy loop or exhausting sockets. - await Task.Delay(60_000); + await Task.Delay(TIME_WAIT); _peerUpdateRequested.Set(); } From 63afd96bf13e3b2cbc210eef69d6d0b6f0afd404 Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 13:47:31 +0100 Subject: [PATCH 05/13] Also wait for time-wait in inner loop --- .../Nethermind.Network/PeerManager.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index c27fac0e924..5dba6fc7b89 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -205,6 +205,8 @@ private class CandidateSelection private async Task RunPeerUpdateLoop() { + const int TIME_WAIT = 60_000; + int loopCount = 0; long previousActivePeersCount = 0; int failCount = 0; @@ -258,6 +260,7 @@ private async Task RunPeerUpdateLoop() int currentPosition = 0; long lastMs = Environment.TickCount64; + int peersTried = 0; while (true) { if (_cancellationTokenSource.IsCancellationRequested) @@ -271,6 +274,7 @@ private async Task RunPeerUpdateLoop() break; } + peersTried += nodesToTry; ActionBlock workerBlock = new( SetupOutgoingPeerConnection, new ExecutionDataflowBlockOptions @@ -294,10 +298,19 @@ private async Task RunPeerUpdateLoop() Interlocked.Increment(ref _connectionRounds); long nowMs = Environment.TickCount64; - long diffMs = nowMs - lastMs; - if (diffMs < 50) + if (peersTried > 10_000) + { + peersTried = 0; + // Wait for sockets to clear + await Task.Delay(TIME_WAIT); + } + else { - await Task.Delay(50 - (int)diffMs); + long diffMs = nowMs - lastMs; + if (diffMs < 50) + { + await Task.Delay(50 - (int)diffMs); + } } lastMs = nowMs; } @@ -333,7 +346,6 @@ private async Task RunPeerUpdateLoop() if (_peerPool.ActivePeerCount < MaxActivePeers) { - const int TIME_WAIT = 60_000; // We been though all the peers once, so wait TIME-WAIT additional delay before // trying them again to avoid busy loop or exhausting sockets. await Task.Delay(TIME_WAIT); From 23cf06492e56e16fa833c35dabfa0293a55b46fb Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 20:20:22 +0100 Subject: [PATCH 06/13] Reduce calls to DateTime.UtcNow --- .../Nethermind.Core/Crypto/PublicKey.cs | 8 +++- .../DiscoveryApp.cs | 3 +- .../DiscoveryManager.cs | 6 +-- .../Nethermind.Network.Stats/INodeStats.cs | 11 +++-- .../Nethermind.Network.Stats/Model/Node.cs | 4 +- .../NodeStatsLight.cs | 47 ++++++++++--------- .../NodeStatsManager.cs | 9 ++-- .../NetworkStorageTests.cs | 9 ++-- .../Nethermind.Network.Test/NodeStatsTests.cs | 15 +++--- src/Nethermind/Nethermind.Network/Peer.cs | 11 ++++- .../Nethermind.Network/PeerManager.cs | 15 ++++-- .../Nethermind.Network/ProtocolsManager.cs | 2 +- 12 files changed, 86 insertions(+), 54 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs b/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs index 40c77f6c4bc..20b01a3b4a0 100644 --- a/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs +++ b/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs @@ -16,6 +16,7 @@ public class PublicKey : IEquatable private Address? _address; private byte[]? _prefixedBytes; + private int _hashCode; public PublicKey(string? hexString) : this(Core.Extensions.Bytes.FromHexString(hexString ?? throw new ArgumentNullException(nameof(hexString)))) @@ -37,6 +38,7 @@ public PublicKey(ReadOnlySpan bytes) } Bytes = bytes.Slice(bytes.Length - 64, 64).ToArray(); + _hashCode = GetHashCode(Bytes); } public Address Address @@ -97,7 +99,11 @@ public override bool Equals(object? obj) public override int GetHashCode() { - byte[] bytes = Bytes; + return _hashCode; + } + + private static int GetHashCode(byte[] bytes) + { long l0 = Unsafe.ReadUnaligned(ref MemoryMarshal.GetArrayDataReference(bytes)); long l1 = Unsafe.ReadUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(bytes), sizeof(long))); long l2 = Unsafe.ReadUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(bytes), sizeof(long) * 2)); diff --git a/src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs b/src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs index df35c7f6673..2de4f5c1a4a 100644 --- a/src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs +++ b/src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs @@ -500,9 +500,10 @@ private async Task RunDiscoveryPersistenceCommit() try { IReadOnlyCollection managers = _discoveryManager.GetNodeLifecycleManagers(); + DateTime utcNow = DateTime.UtcNow; //we need to update all notes to update reputation _discoveryStorage.UpdateNodes(managers.Select(x => new NetworkNode(x.ManagedNode.Id, x.ManagedNode.Host, - x.ManagedNode.Port, x.NodeStats.NewPersistedNodeReputation)).ToArray()); + x.ManagedNode.Port, x.NodeStats.NewPersistedNodeReputation(utcNow))).ToArray()); if (!_discoveryStorage.AnyPendingChange()) { diff --git a/src/Nethermind/Nethermind.Network.Discovery/DiscoveryManager.cs b/src/Nethermind/Nethermind.Network.Discovery/DiscoveryManager.cs index 60ea08bad8c..aa901178dfa 100644 --- a/src/Nethermind/Nethermind.Network.Discovery/DiscoveryManager.cs +++ b/src/Nethermind/Nethermind.Network.Discovery/DiscoveryManager.cs @@ -126,7 +126,7 @@ public void OnIncomingMsg(DiscoveryMsg msg) manager.OnStateChanged += ManagerOnOnStateChanged; if (!isPersisted) { - _discoveryStorage.UpdateNodes(new[] { new NetworkNode(manager.ManagedNode.Id, manager.ManagedNode.Host, manager.ManagedNode.Port, manager.NodeStats.NewPersistedNodeReputation) }); + _discoveryStorage.UpdateNodes(new[] { new NetworkNode(manager.ManagedNode.Id, manager.ManagedNode.Host, manager.ManagedNode.Port, manager.NodeStats.NewPersistedNodeReputation(DateTime.UtcNow)) }); } return manager; @@ -280,9 +280,9 @@ private void CleanUpLifecycleManagers() } } } - + DateTime utcNow = DateTime.UtcNow; foreach ((Keccak key, INodeLifecycleManager value) in _nodeLifecycleManagers.ToArray() - .OrderBy(x => x.Value.NodeStats.CurrentNodeReputation)) + .OrderBy(x => x.Value.NodeStats.CurrentNodeReputation(utcNow))) { if (RemoveManager((key, value.ManagedNode.Id))) { diff --git a/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs b/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs index 8db7210c4c6..027f8c6849f 100644 --- a/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs +++ b/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; + using Nethermind.Stats.Model; namespace Nethermind.Stats @@ -19,11 +21,12 @@ public interface INodeStats void AddTransferSpeedCaptureEvent(TransferSpeedType speedType, long bytesPerMillisecond); long? GetAverageTransferSpeed(TransferSpeedType speedType); - (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed(); - - long CurrentNodeReputation { get; } + (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed(DateTime nowUTC); + + long CurrentNodeReputation() => CurrentNodeReputation(DateTime.UtcNow); + long CurrentNodeReputation(DateTime nowUTC); long CurrentPersistedNodeReputation { get; set; } - long NewPersistedNodeReputation { get; } + long NewPersistedNodeReputation(DateTime nowUTC); P2PNodeDetails P2PNodeDetails { get; } SyncPeerNodeDetails EthNodeDetails { get; } diff --git a/src/Nethermind/Nethermind.Network.Stats/Model/Node.cs b/src/Nethermind/Nethermind.Network.Stats/Model/Node.cs index 55b2cd204c0..001dbdbce5f 100644 --- a/src/Nethermind/Nethermind.Network.Stats/Model/Node.cs +++ b/src/Nethermind/Nethermind.Network.Stats/Model/Node.cs @@ -16,7 +16,6 @@ public sealed class Node : IFormattable, IEquatable private string _clientId; private string _paddedHost; private string _paddedPort; - private int _hashCode; /// /// Node public key - same as in enode. @@ -85,7 +84,6 @@ public Node(PublicKey id, IPEndPoint address, bool isStatic = false) { Id = id; IdHash = Keccak.Compute(Id.PrefixedBytes); - _hashCode = id.GetHashCode(); IsStatic = isStatic; SetIPEndPoint(address); } @@ -121,7 +119,7 @@ public override bool Equals(object obj) return false; } - public override int GetHashCode() => _hashCode; + public override int GetHashCode() => Id.GetHashCode(); public override string ToString() => ToString(Format.WithPublicKey); diff --git a/src/Nethermind/Nethermind.Network.Stats/NodeStatsLight.cs b/src/Nethermind/Nethermind.Network.Stats/NodeStatsLight.cs index d23610f4b24..d2ed5e49073 100644 --- a/src/Nethermind/Nethermind.Network.Stats/NodeStatsLight.cs +++ b/src/Nethermind/Nethermind.Network.Stats/NodeStatsLight.cs @@ -41,7 +41,7 @@ public class NodeStatsLight : INodeStats private DateTime? _lastDisconnectTime; private DateTime? _lastFailedConnectionTime; - private (DateTimeOffset, NodeStatsEventType) _delayConnectDeadline = (DateTimeOffset.Now - TimeSpan.FromSeconds(1), NodeStatsEventType.None); + private (DateTime, NodeStatsEventType) _delayConnectDeadline = (DateTime.UtcNow - TimeSpan.FromSeconds(1), NodeStatsEventType.None); private static readonly Random Random = new(); @@ -55,11 +55,11 @@ public NodeStatsLight(Node node, decimal latestSpeedWeight = 0.25m) Node = node; } - public long CurrentNodeReputation => CalculateCurrentReputation(); + public long CurrentNodeReputation(DateTime nowUTC) => CalculateCurrentReputation(nowUTC); public long CurrentPersistedNodeReputation { get; set; } - public long NewPersistedNodeReputation => IsReputationPenalized() ? -100 : (CurrentPersistedNodeReputation + CalculateSessionReputation()) / 2; + public long NewPersistedNodeReputation(DateTime nowUTC) => IsReputationPenalized(nowUTC) ? -100 : (CurrentPersistedNodeReputation + CalculateSessionReputation()) / 2; public P2PNodeDetails P2PNodeDetails { get; private set; } @@ -85,7 +85,7 @@ public void AddNodeStatsEvent(NodeStatsEventType nodeStatsEventType) if (_statsParameters.DelayDueToEvent.TryGetValue(nodeStatsEventType, out TimeSpan delay)) { - UpdateDelayConnectDeadline(delay, nodeStatsEventType); + UpdateDelayConnectDeadline(DateTime.UtcNow, delay, nodeStatsEventType); } Increment(nodeStatsEventType); @@ -98,7 +98,8 @@ public void AddNodeStatsHandshakeEvent(ConnectionDirection connectionDirection) public void AddNodeStatsDisconnectEvent(DisconnectType disconnectType, DisconnectReason disconnectReason) { - _lastDisconnectTime = DateTime.UtcNow; + DateTime nowUTC = DateTime.UtcNow; + _lastDisconnectTime = nowUTC; if (disconnectType == DisconnectType.Local) { _lastLocalDisconnect = disconnectReason; @@ -112,24 +113,24 @@ public void AddNodeStatsDisconnectEvent(DisconnectType disconnectType, Disconnec { if (_statsParameters.DelayDueToLocalDisconnect.TryGetValue(disconnectReason, out TimeSpan delay)) { - UpdateDelayConnectDeadline(delay, NodeStatsEventType.LocalDisconnectDelay); + UpdateDelayConnectDeadline(nowUTC, delay, NodeStatsEventType.LocalDisconnectDelay); } } else if (disconnectType == DisconnectType.Remote) { if (_statsParameters.DelayDueToRemoteDisconnect.TryGetValue(disconnectReason, out TimeSpan delay)) { - UpdateDelayConnectDeadline(delay, NodeStatsEventType.RemoteDisconnectDelay); + UpdateDelayConnectDeadline(nowUTC, delay, NodeStatsEventType.RemoteDisconnectDelay); } } Increment(NodeStatsEventType.Disconnect); } - private void UpdateDelayConnectDeadline(TimeSpan delay, NodeStatsEventType reason) + private void UpdateDelayConnectDeadline(DateTime nowUTC, TimeSpan delay, NodeStatsEventType reason) { - DateTimeOffset newDeadline = DateTimeOffset.Now + delay; - (DateTimeOffset currentDeadline, NodeStatsEventType _) = _delayConnectDeadline; + DateTime newDeadline = nowUTC + delay; + (DateTime currentDeadline, NodeStatsEventType _) = _delayConnectDeadline; if (newDeadline > currentDeadline) { _delayConnectDeadline = (newDeadline, reason); @@ -212,20 +213,20 @@ private void UpdateValue(ref decimal? currentValue, decimal newValue) }); } - public (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed() + public (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed(DateTime nowUTC) { - if (IsDelayedDueToDisconnect()) + if (IsDelayedDueToDisconnect(nowUTC)) { return (true, NodeStatsEventType.Disconnect); } - if (IsDelayedDueToFailedConnection()) + if (IsDelayedDueToFailedConnection(nowUTC)) { return (true, NodeStatsEventType.ConnectionFailed); } - (DateTimeOffset outgoingDelayDeadline, NodeStatsEventType reason) = _delayConnectDeadline; - if (outgoingDelayDeadline > DateTime.Now) + (DateTime outgoingDelayDeadline, NodeStatsEventType reason) = _delayConnectDeadline; + if (outgoingDelayDeadline > nowUTC) { return (true, reason); } @@ -233,14 +234,14 @@ private void UpdateValue(ref decimal? currentValue, decimal newValue) return (false, null); } - private bool IsDelayedDueToDisconnect() + private bool IsDelayedDueToDisconnect(DateTime nowUTC) { if (!_lastDisconnectTime.HasValue) { return false; } - double timePassed = DateTime.UtcNow.Subtract(_lastDisconnectTime.Value).TotalMilliseconds; + double timePassed = nowUTC.Subtract(_lastDisconnectTime.Value).TotalMilliseconds; int disconnectDelay = GetDisconnectDelay(); if (disconnectDelay <= 500) { @@ -257,14 +258,14 @@ private bool IsDelayedDueToDisconnect() return result; } - private bool IsDelayedDueToFailedConnection() + private bool IsDelayedDueToFailedConnection(DateTime nowUTC) { if (!_lastFailedConnectionTime.HasValue) { return false; } - double timePassed = DateTime.UtcNow.Subtract(_lastFailedConnectionTime.Value).TotalMilliseconds; + double timePassed = nowUTC.Subtract(_lastFailedConnectionTime.Value).TotalMilliseconds; int failedConnectionDelay = GetFailedConnectionDelay(); bool result = timePassed < failedConnectionDelay; @@ -309,9 +310,9 @@ private int GetDisconnectDelay() return disconnectDelay; } - private long CalculateCurrentReputation() + private long CalculateCurrentReputation(DateTime nowUTC) { - return IsReputationPenalized() ? -100 : CurrentPersistedNodeReputation / 2 + CalculateSessionReputation(); + return IsReputationPenalized(nowUTC) ? -100 : CurrentPersistedNodeReputation / 2 + CalculateSessionReputation(); } private bool HasDisconnectedOnce => _lastLocalDisconnect.HasValue || _lastRemoteDisconnect.HasValue; @@ -374,7 +375,7 @@ private long CalculateSessionReputation() return discoveryReputation + 100 * rlpxReputation; } - private bool IsReputationPenalized() + private bool IsReputationPenalized(DateTime nowUTC) { if (!HasDisconnectedOnce) { @@ -399,7 +400,7 @@ private bool IsReputationPenalized() { if (_lastRemoteDisconnect == DisconnectReason.TooManyPeers || _lastRemoteDisconnect == DisconnectReason.AlreadyConnected) { - double timeFromLastDisconnect = DateTime.UtcNow.Subtract(_lastDisconnectTime ?? DateTime.MinValue).TotalMilliseconds; + double timeFromLastDisconnect = nowUTC.Subtract(_lastDisconnectTime ?? DateTime.MinValue).TotalMilliseconds; return timeFromLastDisconnect < _statsParameters.PenalizedReputationTooManyPeersTimeout; } diff --git a/src/Nethermind/Nethermind.Network.Stats/NodeStatsManager.cs b/src/Nethermind/Nethermind.Network.Stats/NodeStatsManager.cs index 6a54998c138..a99c2642a8e 100644 --- a/src/Nethermind/Nethermind.Network.Stats/NodeStatsManager.cs +++ b/src/Nethermind/Nethermind.Network.Stats/NodeStatsManager.cs @@ -42,8 +42,9 @@ private void CleanupTimerOnElapsed(object sender, EventArgs e) if (deleteCount > 0) { + DateTime utcNow = DateTime.UtcNow; IEnumerable toDelete = _nodeStats - .OrderBy(n => n.Value.CurrentNodeReputation) + .OrderBy(n => n.Value.CurrentNodeReputation(utcNow)) .Select(n => n.Key) .Take(_nodeStats.Count - _maxCount); @@ -102,7 +103,7 @@ public void ReportEvent(Node node, NodeStatsEventType eventType) public (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed(Node node) { INodeStats stats = GetOrAdd(node); - return stats.IsConnectionDelayed(); + return stats.IsConnectionDelayed(DateTime.UtcNow); } public CompatibilityValidationType? FindCompatibilityValidationResult(Node node) @@ -114,7 +115,7 @@ public void ReportEvent(Node node, NodeStatsEventType eventType) public long GetCurrentReputation(Node node) { INodeStats stats = GetOrAdd(node); - return stats.CurrentNodeReputation; + return stats.CurrentNodeReputation(DateTime.UtcNow); } public void ReportP2PInitializationEvent(Node node, P2PNodeDetails p2PNodeDetails) @@ -149,7 +150,7 @@ public void ReportDisconnect(Node node, DisconnectType disconnectType, Disconnec public long GetNewPersistedReputation(Node node) { INodeStats stats = GetOrAdd(node); - return stats.NewPersistedNodeReputation; + return stats.NewPersistedNodeReputation(DateTime.UtcNow); } public long GetCurrentPersistedReputation(Node node) diff --git a/src/Nethermind/Nethermind.Network.Test/NetworkStorageTests.cs b/src/Nethermind/Nethermind.Network.Test/NetworkStorageTests.cs index 2a82b32138e..01042fc47b4 100644 --- a/src/Nethermind/Nethermind.Network.Test/NetworkStorageTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/NetworkStorageTests.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.Linq; using Nethermind.Config; using Nethermind.Core.Test.Builders; @@ -68,7 +69,8 @@ public void Can_store_discovery_nodes() }; var managers = nodes.Select(CreateLifecycleManager).ToArray(); - var networkNodes = managers.Select(x => new NetworkNode(x.ManagedNode.Id, x.ManagedNode.Host, x.ManagedNode.Port, x.NodeStats.NewPersistedNodeReputation)).ToArray(); + DateTime utcNow = DateTime.UtcNow; + var networkNodes = managers.Select(x => new NetworkNode(x.ManagedNode.Id, x.ManagedNode.Host, x.ManagedNode.Port, x.NodeStats.NewPersistedNodeReputation(utcNow))).ToArray(); _storage.StartBatch(); @@ -82,7 +84,7 @@ public void Can_store_discovery_nodes() Assert.IsNotNull(persistedNode); Assert.That(persistedNode.Port, Is.EqualTo(manager.ManagedNode.Port)); Assert.That(persistedNode.Host, Is.EqualTo(manager.ManagedNode.Host)); - Assert.That(persistedNode.Reputation, Is.EqualTo(manager.NodeStats.CurrentNodeReputation)); + Assert.That(persistedNode.Reputation, Is.EqualTo(manager.NodeStats.CurrentNodeReputation())); } _storage.StartBatch(); @@ -96,13 +98,14 @@ public void Can_store_discovery_nodes() Assert.IsNull(persistedNode); } + utcNow = DateTime.UtcNow; foreach (INodeLifecycleManager manager in managers.Skip(1)) { NetworkNode persistedNode = persistedNodes.FirstOrDefault(x => x.NodeId.Equals(manager.ManagedNode.Id)); Assert.IsNotNull(persistedNode); Assert.That(persistedNode.Port, Is.EqualTo(manager.ManagedNode.Port)); Assert.That(persistedNode.Host, Is.EqualTo(manager.ManagedNode.Host)); - Assert.That(persistedNode.Reputation, Is.EqualTo(manager.NodeStats.CurrentNodeReputation)); + Assert.That(persistedNode.Reputation, Is.EqualTo(manager.NodeStats.CurrentNodeReputation(utcNow))); } } diff --git a/src/Nethermind/Nethermind.Network.Test/NodeStatsTests.cs b/src/Nethermind/Nethermind.Network.Test/NodeStatsTests.cs index 8c3cea8b30d..ce6e844919d 100644 --- a/src/Nethermind/Nethermind.Network.Test/NodeStatsTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/NodeStatsTests.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.Threading.Tasks; using FluentAssertions; using Nethermind.Core.Test.Builders; @@ -61,15 +62,15 @@ public async Task DisconnectDelayTest() { _nodeStats = new NodeStatsLight(_node); - var isConnDelayed = _nodeStats.IsConnectionDelayed(); + var isConnDelayed = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); Assert.IsFalse(isConnDelayed.Result, "before disconnect"); _nodeStats.AddNodeStatsDisconnectEvent(DisconnectType.Remote, DisconnectReason.Other); - isConnDelayed = _nodeStats.IsConnectionDelayed(); + isConnDelayed = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); Assert.IsTrue(isConnDelayed.Result, "just after disconnect"); Assert.That(isConnDelayed.DelayReason, Is.EqualTo(NodeStatsEventType.Disconnect)); await Task.Delay(125); - isConnDelayed = _nodeStats.IsConnectionDelayed(); + isConnDelayed = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); Assert.IsFalse(isConnDelayed.Result, "125ms after disconnect"); } @@ -81,11 +82,11 @@ public void DisconnectDelayDueToNodeStatsEvent(NodeStatsEventType eventType, boo { _nodeStats = new NodeStatsLight(_node); - (bool isConnDelayed, NodeStatsEventType? _) = _nodeStats.IsConnectionDelayed(); + (bool isConnDelayed, NodeStatsEventType? _) = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); Assert.IsFalse(isConnDelayed, "before disconnect"); _nodeStats.AddNodeStatsEvent(eventType); - (isConnDelayed, _) = _nodeStats.IsConnectionDelayed(); + (isConnDelayed, _) = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); isConnDelayed.Should().Be(connectionDelayed); } @@ -95,12 +96,12 @@ public async Task DisconnectDelayDueToDisconnect(DisconnectType disconnectType, { _nodeStats = new NodeStatsLight(_node); - (bool isConnDelayed, NodeStatsEventType? _) = _nodeStats.IsConnectionDelayed(); + (bool isConnDelayed, NodeStatsEventType? _) = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); Assert.IsFalse(isConnDelayed, "before disconnect"); _nodeStats.AddNodeStatsDisconnectEvent(disconnectType, reason); await Task.Delay(125); // Standard disconnect delay without specific handling - (isConnDelayed, _) = _nodeStats.IsConnectionDelayed(); + (isConnDelayed, _) = _nodeStats.IsConnectionDelayed(DateTime.UtcNow); isConnDelayed.Should().Be(connectionDelayed); } } diff --git a/src/Nethermind/Nethermind.Network/Peer.cs b/src/Nethermind/Nethermind.Network/Peer.cs index d845eae140b..e895c29ec0e 100644 --- a/src/Nethermind/Nethermind.Network/Peer.cs +++ b/src/Nethermind/Nethermind.Network/Peer.cs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; + using Nethermind.Network.P2P; using Nethermind.Stats; using Nethermind.Stats.Model; @@ -16,7 +18,7 @@ namespace Nethermind.Network /// The logic for choosing which session to drop has to be consistent between the two peers - we use the PublicKey /// comparison to choose the connection direction in the same way on both sides. /// - public sealed class Peer + public sealed class Peer : IEquatable { public Peer(Node node) : this(node, null) { } @@ -51,5 +53,12 @@ public override string ToString() { return $"[Peer|{Node:s}|{InSession}|{OutSession}]"; } + + public bool Equals(Peer? other) + { + return Node.Equals(other?.Node); + } + + public override int GetHashCode() => Node.GetHashCode(); } } diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index 5dba6fc7b89..aa02cdd0ef0 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -435,6 +435,7 @@ private void SelectAndRankCandidates() _currentSelection.Counters[ActivePeerSelectionCounter.AllNonActiveCandidates] = _currentSelection.PreCandidates.Count; + DateTime nowUTC = DateTime.UtcNow; foreach (Peer preCandidate in _currentSelection.PreCandidates) { if (preCandidate.Node.Port == 0) @@ -443,7 +444,7 @@ private void SelectAndRankCandidates() continue; } - (bool Result, NodeStatsEventType? DelayReason) delayResult = preCandidate.Stats.IsConnectionDelayed(); + (bool Result, NodeStatsEventType? DelayReason) delayResult = preCandidate.Stats.IsConnectionDelayed(nowUTC); if (delayResult.Result) { if (delayResult.DelayReason == NodeStatsEventType.Disconnect) @@ -478,7 +479,15 @@ private void SelectAndRankCandidates() _currentSelection.Candidates.AddRange(_peerPool.StaticPeers.Where(sn => !_peerPool.ActivePeers.ContainsKey(sn.Node.Id))); } - _stats.UpdateCurrentReputation(_currentSelection.Candidates); + foreach (Peer peer in _currentSelection.Candidates) + { + Node? node = peer.Node; + + if (node is null) continue; + + node.CurrentReputation = peer.Stats.CurrentNodeReputation(nowUTC); + } + _currentSelection.Candidates.Sort(_peerComparer); } @@ -757,7 +766,7 @@ private bool CanConnectToPeer(Peer peer) return false; } - (bool delayed, NodeStatsEventType? reason) = peer.Stats.IsConnectionDelayed(); + (bool delayed, NodeStatsEventType? reason) = peer.Stats.IsConnectionDelayed(DateTime.UtcNow); if (delayed) { if (_logger.IsTrace) _logger.Trace($"Not connecting peer: {peer} due forced connection delay. Reason: {reason}"); diff --git a/src/Nethermind/Nethermind.Network/ProtocolsManager.cs b/src/Nethermind/Nethermind.Network/ProtocolsManager.cs index 43c975e6d25..d19184c7878 100644 --- a/src/Nethermind/Nethermind.Network/ProtocolsManager.cs +++ b/src/Nethermind/Nethermind.Network/ProtocolsManager.cs @@ -348,7 +348,7 @@ private void InitSyncPeerProtocol(ISession session, SyncPeerProtocolHandlerBase if (_logger.IsTrace) _logger.Trace($"Finalized {handler.ProtocolCode.ToUpper()} protocol initialization on {session} - adding sync peer {session.Node:s}"); //Add/Update peer to the storage and to sync manager - _peerStorage.UpdateNode(new NetworkNode(session.Node.Id, session.Node.Host, session.Node.Port, _stats.GetOrAdd(session.Node).NewPersistedNodeReputation)); + _peerStorage.UpdateNode(new NetworkNode(session.Node.Id, session.Node.Host, session.Node.Port, _stats.GetOrAdd(session.Node).NewPersistedNodeReputation(DateTime.UtcNow))); } else { From 0157d4632396f8733bd17dd1a6ddd3178e8bb0df Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 20:24:37 +0100 Subject: [PATCH 07/13] Formatting --- src/Nethermind/Nethermind.Network.Stats/INodeStats.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs b/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs index 027f8c6849f..0020fef78e7 100644 --- a/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs +++ b/src/Nethermind/Nethermind.Network.Stats/INodeStats.cs @@ -22,7 +22,7 @@ public interface INodeStats void AddTransferSpeedCaptureEvent(TransferSpeedType speedType, long bytesPerMillisecond); long? GetAverageTransferSpeed(TransferSpeedType speedType); (bool Result, NodeStatsEventType? DelayReason) IsConnectionDelayed(DateTime nowUTC); - + long CurrentNodeReputation() => CurrentNodeReputation(DateTime.UtcNow); long CurrentNodeReputation(DateTime nowUTC); long CurrentPersistedNodeReputation { get; set; } From c566634c2a2b07432e2aca9825fd233fe5cf2b15 Mon Sep 17 00:00:00 2001 From: benaadams Date: Thu, 1 Jun 2023 20:33:26 +0100 Subject: [PATCH 08/13] Fix benchmark --- .../Nethermind.Network.Benchmark/NodeStatsCtorBenchmarks.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Network.Benchmark/NodeStatsCtorBenchmarks.cs b/src/Nethermind/Nethermind.Network.Benchmark/NodeStatsCtorBenchmarks.cs index 423c64d6052..a2b4dd854c8 100644 --- a/src/Nethermind/Nethermind.Network.Benchmark/NodeStatsCtorBenchmarks.cs +++ b/src/Nethermind/Nethermind.Network.Benchmark/NodeStatsCtorBenchmarks.cs @@ -11,6 +11,7 @@ namespace Nethermind.Network.Benchmarks { public class NodeStatsCtorBenchmarks { + private DateTime _now = DateTime.UtcNow; private Node _node; [GlobalSetup] @@ -35,7 +36,7 @@ public void Light() public long LightRep() { NodeStatsLight stats = new NodeStatsLight(_node); - return stats.CurrentNodeReputation; + return stats.CurrentNodeReputation(_now); } } } From 253833219aef66532de5af77b552a3e3fbab3187 Mon Sep 17 00:00:00 2001 From: benaadams Date: Fri, 2 Jun 2023 02:10:09 +0100 Subject: [PATCH 09/13] Reduce DateTime.UtcNow calls further --- .../RoutingTable/NodeBucketItemTests.cs | 2 +- .../Nethermind.Network.Discovery/RoutingTable/NodeBucket.cs | 6 ++++-- .../RoutingTable/NodeBucketItem.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketItemTests.cs b/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketItemTests.cs index b04a56f5218..b3b7b0b700a 100644 --- a/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketItemTests.cs +++ b/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketItemTests.cs @@ -41,7 +41,7 @@ public void Is_bonded_at_start() { Node node = new(TestItem.PublicKeyA, IPAddress.Loopback.ToString(), 30000); NodeBucketItem nodeBucketItem = new(node, DateTime.UtcNow); - nodeBucketItem.IsBonded.Should().BeTrue(); + nodeBucketItem.IsBonded(DateTime.UtcNow).Should().BeTrue(); } [Test] diff --git a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucket.cs b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucket.cs index 99bdcea2d40..4556e32350b 100644 --- a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucket.cs +++ b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucket.cs @@ -33,9 +33,10 @@ public IEnumerable BondedItems lock (_nodeBucketLock) { LinkedListNode? node = _items.Last; + DateTime utcNow = DateTime.UtcNow; while (node is not null) { - if (!node.Value.IsBonded) + if (!node.Value.IsBonded(utcNow)) { break; } @@ -55,9 +56,10 @@ public int BondedItemsCount { int result = _items.Count; LinkedListNode? node = _items.Last; + DateTime utcNow = DateTime.UtcNow; while (node is not null) { - if (node.Value.IsBonded) + if (node.Value.IsBonded(utcNow)) { break; } diff --git a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucketItem.cs b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucketItem.cs index b3113e21baa..7592ac272ea 100644 --- a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucketItem.cs +++ b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeBucketItem.cs @@ -17,7 +17,7 @@ public NodeBucketItem(Node? node, DateTime lastContactTime) public DateTime LastContactTime { get; private set; } - public bool IsBonded => LastContactTime > DateTime.UtcNow - TimeSpan.FromDays(2); + public bool IsBonded(DateTime utcNow) => LastContactTime > utcNow - TimeSpan.FromDays(2); public void OnContactReceived() { From 513cf8413099883200e60f1ff13a9339d627865c Mon Sep 17 00:00:00 2001 From: benaadams Date: Fri, 2 Jun 2023 03:02:32 +0100 Subject: [PATCH 10/13] Wait for sockets after 1k --- src/Nethermind/Nethermind.Network/PeerManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/PeerManager.cs b/src/Nethermind/Nethermind.Network/PeerManager.cs index aa02cdd0ef0..3b7d57ecf51 100644 --- a/src/Nethermind/Nethermind.Network/PeerManager.cs +++ b/src/Nethermind/Nethermind.Network/PeerManager.cs @@ -298,7 +298,7 @@ private async Task RunPeerUpdateLoop() Interlocked.Increment(ref _connectionRounds); long nowMs = Environment.TickCount64; - if (peersTried > 10_000) + if (peersTried > 1_000) { peersTried = 0; // Wait for sockets to clear @@ -427,7 +427,7 @@ private void SelectAndRankCandidates() hasOnlyStaticNodes = _currentSelection.PreCandidates.Count > 0; } - if (!_currentSelection.PreCandidates.Any() && !hasOnlyStaticNodes) + if (_currentSelection.PreCandidates.Count == 0 && !hasOnlyStaticNodes) { return; } From 4e2c7752baa9b3ad980b0eb199e25ffd590c2302 Mon Sep 17 00:00:00 2001 From: benaadams Date: Fri, 2 Jun 2023 04:44:09 +0100 Subject: [PATCH 11/13] Use Dict rather than List+HashSet --- .../Nethermind.Network/NetworkStorage.cs | 117 +++++++++--------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/NetworkStorage.cs b/src/Nethermind/Nethermind.Network/NetworkStorage.cs index d2a34278d58..b545affc6c6 100644 --- a/src/Nethermind/Nethermind.Network/NetworkStorage.cs +++ b/src/Nethermind/Nethermind.Network/NetworkStorage.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text; -using System.Threading; using Nethermind.Config; using Nethermind.Core; @@ -23,8 +20,7 @@ public class NetworkStorage : INetworkStorage private readonly object _lock = new(); private readonly IFullDb _fullDb; private readonly ILogger _logger; - private readonly List _nodesList = new(); - private readonly HashSet _nodePublicKeys = new(); + private readonly Dictionary _nodesDict = new(); private long _updateCounter; private long _removeCounter; private NetworkNode[] _nodes; @@ -55,38 +51,46 @@ private NetworkNode[] GenerateNodes() return nodes; } - List nodeList = _nodesList; - if (nodeList.Count > 0) + if (_nodesDict.Count > 0) { - return (_nodes = nodeList.ToArray()); + return CopyDictToArray(); } - foreach (byte[]? nodeRlp in _fullDb.Values) + LoadFromDb(); + + if (_nodesDict.Count == 0) { - if (nodeRlp is null) - { - continue; - } - - try - { - NetworkNode node = GetNode(nodeRlp); - nodeList.Add(node); - _nodePublicKeys.Add(node.NodeId); - } - catch (Exception e) - { - if (_logger.IsDebug) _logger.Debug($"Failed to add one of the persisted nodes (with RLP {nodeRlp.ToHexString()}), {e.Message}"); - } + return Array.Empty(); } - if (nodeList.Count == 0) + return CopyDictToArray(); + } + } + + private NetworkNode[] CopyDictToArray() + { + NetworkNode[] nodes = new NetworkNode[_nodesDict.Count]; + _nodesDict.Values.CopyTo(nodes, 0); + return (_nodes = nodes); + } + + private void LoadFromDb() + { + foreach (byte[]? nodeRlp in _fullDb.Values) + { + if (nodeRlp is null) { - return Array.Empty(); + continue; } - else + + try { - return (_nodes = nodeList.ToArray()); + NetworkNode node = GetNode(nodeRlp); + _nodesDict[node.NodeId] = node; + } + catch (Exception e) + { + if (_logger.IsDebug) _logger.Debug($"Failed to add one of the persisted nodes (with RLP {nodeRlp.ToHexString()}), {e.Message}"); } } } @@ -95,35 +99,35 @@ public void UpdateNode(NetworkNode node) { lock (_lock) { - (_currentBatch ?? (IKeyValueStore)_fullDb)[node.NodeId.Bytes] = Rlp.Encode(node).Bytes; - _updateCounter++; + UpdateNodeImpl(node); + } + } - if (!_nodePublicKeys.Contains(node.NodeId)) - { - _nodePublicKeys.Add(node.NodeId); - _nodesList.Add(node); - // New node, clear the cache - _nodes = null; - } - else - { - Span span = CollectionsMarshal.AsSpan(_nodesList); - for (int i = 0; i < span.Length; i++) - { - if (node.NodeId == span[i].NodeId) - { - span[i] = node; - } - } - } + private void UpdateNodeImpl(NetworkNode node) + { + (_currentBatch ?? (IKeyValueStore)_fullDb)[node.NodeId.Bytes] = Rlp.Encode(node).Bytes; + _updateCounter++; + + if (!_nodesDict.ContainsKey(node.NodeId)) + { + _nodesDict[node.NodeId] = node; + // New node, clear the cache + _nodes = null; + } + else + { + _nodesDict[node.NodeId] = node; } } public void UpdateNodes(IEnumerable nodes) { - foreach (NetworkNode node in nodes) + lock (_lock) { - UpdateNode(node); + foreach (NetworkNode node in nodes) + { + UpdateNodeImpl(node); + } } } @@ -139,17 +143,10 @@ private void RemoveLocal(PublicKey nodeId) { lock (_lock) { - Span span = CollectionsMarshal.AsSpan(_nodesList); - for (int i = 0; i < span.Length; i++) + if (_nodesDict.Remove(nodeId)) { - if (nodeId == span[i].NodeId) - { - _nodesList.RemoveAt(i); - _nodePublicKeys.Remove(nodeId); - // New node, clear the cache - _nodes = null; - return; - } + // Clear the cache + _nodes = null; } } } From eb44eb1f66e33918723804bb2bbe5ff2770ed7f0 Mon Sep 17 00:00:00 2001 From: "lukasz.rozmej" Date: Fri, 2 Jun 2023 17:21:31 +0200 Subject: [PATCH 12/13] small refactor --- .../Nethermind.Network/NetworkStorage.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Nethermind/Nethermind.Network/NetworkStorage.cs b/src/Nethermind/Nethermind.Network/NetworkStorage.cs index b545affc6c6..b2dc14142cb 100644 --- a/src/Nethermind/Nethermind.Network/NetworkStorage.cs +++ b/src/Nethermind/Nethermind.Network/NetworkStorage.cs @@ -23,7 +23,7 @@ public class NetworkStorage : INetworkStorage private readonly Dictionary _nodesDict = new(); private long _updateCounter; private long _removeCounter; - private NetworkNode[] _nodes; + private NetworkNode[]? _nodes; public NetworkStorage(IFullDb? fullDb, ILogManager? logManager) { @@ -36,34 +36,26 @@ public NetworkStorage(IFullDb? fullDb, ILogManager? logManager) public NetworkNode[] GetPersistedNodes() { NetworkNode[] nodes = _nodes; - return nodes is not null ? nodes : GenerateNodes(); + return nodes ?? GenerateNodes(); } private NetworkNode[] GenerateNodes() { - NetworkNode[] nodes; lock (_lock) { - nodes = _nodes; + NetworkNode[]? nodes = _nodes; if (nodes is not null) { // Already updated return nodes; } - if (_nodesDict.Count > 0) - { - return CopyDictToArray(); - } - - LoadFromDb(); - if (_nodesDict.Count == 0) { - return Array.Empty(); + LoadFromDb(); } - return CopyDictToArray(); + return _nodesDict.Count == 0 ? Array.Empty() : CopyDictToArray(); } } From d8ffa775186ba39da261d825a7a833536984ba16 Mon Sep 17 00:00:00 2001 From: benaadams Date: Sat, 3 Jun 2023 04:14:56 +0100 Subject: [PATCH 13/13] Extend wait delay --- src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs b/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs index 23748c3de27..79ec02369c2 100644 --- a/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs @@ -299,7 +299,7 @@ public async Task Will_fill_up_over_and_over_again_on_disconnects() for (int i = 0; i < 10; i++) { currentCount += 25; - await Task.Delay(_travisDelayLong); + await Task.Delay(_travisDelayLonger); Assert.That(ctx.RlpxPeer.ConnectAsyncCallsCount, Is.EqualTo(currentCount)); ctx.DisconnectAllSessions(); } @@ -345,6 +345,7 @@ public async Task IfPeerAdded_with_invalid_chain_then_do_not_connect() private int _travisDelay = 500; private int _travisDelayLong = 1000; + private int _travisDelayLonger = 3000; [Test] [Ignore("Behaviour changed that allows peers to go over max if awaiting response")]