Skip to content
Open
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
60 changes: 43 additions & 17 deletions src/Nethermind/Nethermind.Network/PeerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,38 +219,64 @@
private async Task RunPeerUpdateLoop()
{
Channel<Peer> taskChannel = Channel.CreateBounded<Peer>(1);
using ArrayPoolList<Task> tasks = Enumerable.Range(0, _outgoingConnectParallelism).Select(async idx =>
using ArrayPoolList<Task> tasks = new(_outgoingConnectParallelism);
for (int idx = 0; idx < _outgoingConnectParallelism; idx++)
{
tasks.Add(RunWorker(idx));
}

async Task RunWorker(int workerIdx)
{
await foreach (Peer peer in taskChannel.Reader.ReadAllAsync(_cancellationTokenSource.Token))
{
await foreach (Peer peer in taskChannel.Reader.ReadAllAsync(_cancellationTokenSource.Token))
try
{
try
{
await SetupOutgoingPeerConnection(peer);
}
catch (TaskCanceledException)
{
if (_logger.IsDebug) _logger.Debug($"Connect worker {idx} cancelled");
break;
}
catch (Exception e)
await SetupOutgoingPeerConnection(peer);
}
catch (TaskCanceledException)
{
if (_logger.IsDebug) _logger.Debug($"Connect worker {workerIdx} cancelled");
break;
}
catch (Exception e)
{
if (_logger.IsError) _logger.Error($"Error setting up connection to {peer}, {e}");
}
}
if (_logger.IsDebug) _logger.Debug($"Connect worker {workerIdx} completed");
}
{
await foreach (Peer peer in taskChannel.Reader.ReadAllAsync(_cancellationTokenSource.Token))
{
// This is strictly speaking not related to the connection, but something outside of it.
if (_logger.IsError) _logger.Error($"Error setting up connection to {peer}, {e}");
try
{
await SetupOutgoingPeerConnection(peer);
}
catch (TaskCanceledException)
{
if (_logger.IsDebug) _logger.Debug($"Connect worker {workerIdx} cancelled");
break;
}
catch (Exception e)
{
// This is strictly speaking not related to the connection, but something outside of it.
if (_logger.IsError) _logger.Error($"Error setting up connection to {peer}, {e}");
}
}
}
if (_logger.IsDebug) _logger.Debug($"Connect worker {idx} completed");
}).ToPooledList(_outgoingConnectParallelism);
if (_logger.IsDebug) _logger.Debug($"Connect worker {workerIdx} completed");
}));

Check failure on line 267 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

} expected

Check failure on line 267 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

} expected

Check failure on line 267 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

} expected

Check failure on line 267 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

} expected

Check failure on line 267 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

} expected
}

int loopCount = 0;
long previousActivePeersCount = 0;
int failCount = 0;
while (true)

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Invalid token 'true' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

) expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Tuple must contain at least two elements.

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Type expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Invalid token 'while' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Invalid token 'true' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

) expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Tuple must contain at least two elements.

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Type expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Invalid token 'while' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Invalid token 'true' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

) expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Tuple must contain at least two elements.

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Type expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Invalid token 'while' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Invalid token 'true' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

) expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Tuple must contain at least two elements.

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Type expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Invalid token 'while' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Invalid token 'true' in a member declaration

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

) expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Tuple must contain at least two elements.

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Type expected

Check failure on line 273 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Invalid token 'while' in a member declaration
{
try
{
if (loopCount++ % 100 == 0)

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Invalid token '++' in a member declaration

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

) expected

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Tuple must contain at least two elements.

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Invalid token '++' in a member declaration

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

) expected

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Tuple must contain at least two elements.

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Invalid token '++' in a member declaration

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

) expected

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Tuple must contain at least two elements.

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Invalid token '++' in a member declaration

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

) expected

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Tuple must contain at least two elements.

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Invalid token '++' in a member declaration

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

) expected

Check failure on line 277 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Tuple must contain at least two elements.
{
if (_logger.IsTrace) _logger.Trace($"Running peer update loop {loopCount - 1} - active: {_peerPool.ActivePeerCount} | candidates : {_peerPool.PeerCount}");

Check failure on line 279 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Tuple must contain at least two elements.

Check failure on line 279 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Tuple must contain at least two elements.

Check failure on line 279 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Tuple must contain at least two elements.

Check failure on line 279 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Tuple must contain at least two elements.

Check failure on line 279 in src/Nethermind/Nethermind.Network/PeerManager.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

Tuple must contain at least two elements.
}

try
Expand Down
9 changes: 5 additions & 4 deletions src/Nethermind/Nethermind.Trie/BatchedTrieVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -146,9 +145,11 @@ public void Start(

try
{
using ArrayPoolListRef<Task> tasks = Enumerable.Range(0, trieVisitContext.MaxDegreeOfParallelism)
.Select(_ => Task.Run(BatchedThread))
.ToPooledListRef(trieVisitContext.MaxDegreeOfParallelism);
using ArrayPoolListRef<Task> tasks = new(trieVisitContext.MaxDegreeOfParallelism);
for (int i = 0; i < trieVisitContext.MaxDegreeOfParallelism; i++)
{
tasks.Add(Task.Run(BatchedThread));
}

Task.WaitAll(tasks.AsSpan());
}
Expand Down
Loading