Skip to content

Commit

Permalink
Removed retrying logic when block downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Oct 30, 2020
1 parent 1c9d402 commit 5913e5a
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,56 +1683,30 @@ private async Task SyncPreviousBlocksAsync(
CancellationToken cancellationToken
)
{
int retry = 3;
long previousTipIndex = blockChain.Tip?.Index ?? -1;
BlockChain<T> synced = null;

try
{
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
long currentTipIndex = blockChain.Tip?.Index ?? -1;
long receivedBlockCount = currentTipIndex - previousTipIndex;

try
{
long currentTipIndex = blockChain.Tip?.Index ?? -1;
long receivedBlockCount = currentTipIndex - previousTipIndex;

FillBlocksAsyncStarted.Set();
synced = await FillBlocksAsync(
peer,
blockChain,
stop,
progress,
totalBlockCount,
receivedBlockCount,
true,
cancellationToken
);
break;
}
catch (TimeoutException e)
{
if (retry > 0)
{
_logger.Error(
e,
$"{nameof(FillBlocksAsync)}() failed; retrying...: {e}"
);
retry--;
}
else
{
FillBlocksAsyncFailed.Set();
throw;
}
}
catch (Exception)
{
FillBlocksAsyncFailed.Set();
throw;
}
}
FillBlocksAsyncStarted.Set();
synced = await FillBlocksAsync(
peer,
blockChain,
stop,
progress,
totalBlockCount,
receivedBlockCount,
true,
cancellationToken
);
}
catch (Exception)
{
FillBlocksAsyncFailed.Set();
throw;
}
finally
{
Expand Down

0 comments on commit 5913e5a

Please sign in to comment.