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

Forward exeption on fast block #4193

Merged
merged 2 commits into from
Jun 23, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Threading.Tasks;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Logging;
using Nethermind.Synchronization.ParallelSync;
using Nethermind.Synchronization.Peers;
Expand All @@ -41,22 +42,19 @@ protected override async Task Dispatch(PeerInfo peerInfo, BodiesSyncBatch batch,
ISyncPeer peer = peerInfo.SyncPeer;
batch.ResponseSourcePeer = peerInfo;
batch.MarkSent();
var hashes = batch.Infos.Where(i => i != null).Select(i => i!.BlockHash).ToArray();
Task<BlockBody[]> getBodiesTask = peer.GetBlockBodies(hashes, cancellationToken);
await getBodiesTask.ContinueWith(
(t, state) =>
{
BodiesSyncBatch batchLocal = (BodiesSyncBatch)state!;
if (t.IsCompletedSuccessfully)
{
if (batchLocal.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batchLocal} - peer is slow {batchLocal.RequestTime:F2}");
}

batchLocal.Response = t.Result;
}
}, batch);

Keccak[]? hashes = batch.Infos.Where(i => i != null).Select(i => i!.BlockHash).ToArray();
if (hashes.Length == 0)
{
if (Logger.IsDebug) Logger.Debug($"{batch} - attempted send a request with no hash.");
return;
}

batch.Response = await peer.GetBlockBodies(hashes, cancellationToken);
if (batch.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batch} - peer is slow {batch.RequestTime:F2}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,12 @@ public class HeadersSyncDispatcher : SyncDispatcher<HeadersSyncBatch>
ISyncPeer peer = peerInfo.SyncPeer;
batch.ResponseSourcePeer = peerInfo;
batch.MarkSent();
Task<BlockHeader[]> getHeadersTask
= peer.GetBlockHeaders(batch.StartNumber, batch.RequestSize, 0, cancellationToken);

await getHeadersTask.ContinueWith(
(t, state) =>
{
HeadersSyncBatch batchLocal = (HeadersSyncBatch)state!;
if (t.IsCompletedSuccessfully)
{
if (batchLocal.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batchLocal} - peer is slow {batchLocal.RequestTime:F2}");
}

batchLocal.Response = t.Result;
}
}, batch);
batch.Response = await peer.GetBlockHeaders(batch.StartNumber, batch.RequestSize, 0, cancellationToken);
if (batch.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batch} - peer is slow {batch.RequestTime:F2}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Threading.Tasks;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Logging;
using Nethermind.Synchronization.ParallelSync;
using Nethermind.Synchronization.Peers;
Expand All @@ -41,22 +42,19 @@ protected override async Task Dispatch(PeerInfo peerInfo, ReceiptsSyncBatch batc
ISyncPeer peer = peerInfo.SyncPeer;
batch.ResponseSourcePeer = peerInfo;
batch.MarkSent();
var hashes = batch.Infos.Where(i => i != null).Select(i => i!.BlockHash).ToArray();
Task<TxReceipt[][]> getReceiptsTask = peer.GetReceipts(hashes, cancellationToken);
await getReceiptsTask.ContinueWith(
(t, state) =>
{
ReceiptsSyncBatch batchLocal = (ReceiptsSyncBatch)state!;
if (t.IsCompletedSuccessfully)
{
if (batchLocal.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batchLocal} - peer is slow {batchLocal.RequestTime:F2}");
}

batchLocal.Response = t.Result;
}
}, batch);

Keccak[]? hashes = batch.Infos.Where(i => i != null).Select(i => i!.BlockHash).ToArray();
if (hashes.Length == 0)
{
if (Logger.IsDebug) Logger.Debug($"{batch} - attempted send a request with no hash.");
return;
}

batch.Response = await peer.GetReceipts(hashes, cancellationToken);
if (batch.RequestTime > 1000)
{
if (Logger.IsDebug) Logger.Debug($"{batch} - peer is slow {batch.RequestTime:F2}");
}
}
}
}