Skip to content

Commit

Permalink
Forward exeption on fast block (#4193)
Browse files Browse the repository at this point in the history
* Forward exeption on fast block

* Check if requested hashes is 0
  • Loading branch information
asdacap authored Jun 23, 2022
1 parent 4adc90a commit ad72e01
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 48 deletions.
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 @@ protected override async Task Dispatch(
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}");
}
}
}
}

0 comments on commit ad72e01

Please sign in to comment.