From 969588c050c433949763a7ec7fee88f9f25e7cfa Mon Sep 17 00:00:00 2001 From: Lee Suho Date: Thu, 26 Nov 2020 14:42:05 +0900 Subject: [PATCH] fix: break when getting blocks count is less then hash chunk size --- CHANGES.md | 3 +++ Libplanet/Net/Swarm.cs | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2195a277a..03671e27aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,8 @@ To be released. ### Backward-incompatible API changes ### Backward-incompatible network protocol changes + - If the count of blocks `Swarm` have received is less than + the `FindNextHashesChunkSize`, `Swarm` will no longer retry. [[#1112]] ### Backward-incompatible storage format changes @@ -61,6 +63,7 @@ To be released. [#1101]: https://github.com/planetarium/libplanet/pull/1101 [#1102]: https://github.com/planetarium/libplanet/pull/1102 [#1110]: https://github.com/planetarium/libplanet/pull/1110 +[#1112]: https://github.com/planetarium/libplanet/pull/1112 Version 0.10.2 diff --git a/Libplanet/Net/Swarm.cs b/Libplanet/Net/Swarm.cs index c53cab81dd..9e8d9385a6 100644 --- a/Libplanet/Net/Swarm.cs +++ b/Libplanet/Net/Swarm.cs @@ -1860,6 +1860,7 @@ out HashDigest branchPoint cancellationToken ); + var receivedBlockCountCurrentLoop = 0; await foreach (Block block in blocks) { _logger.Debug( @@ -1877,11 +1878,11 @@ out HashDigest branchPoint renderBlocks: renderBlocks, renderActions: renderActions ); - receivedBlockCount++; + receivedBlockCountCurrentLoop++; progress?.Report(new BlockDownloadState { TotalBlockCount = totalBlockCount, - ReceivedBlockCount = receivedBlockCount, + ReceivedBlockCount = receivedBlockCount + receivedBlockCountCurrentLoop, ReceivedBlockHash = block.Hash, SourcePeer = peer, }); @@ -1891,6 +1892,18 @@ out HashDigest branchPoint block.Hash ); } + + receivedBlockCount += receivedBlockCountCurrentLoop; + + // FIXME: Need test + if (receivedBlockCountCurrentLoop < FindNextHashesChunkSize) + { + _logger.Debug( + $"Got all blocks from Peer [{peer}]", + peer.Address.ToHex() + ); + break; + } } } catch (Exception e)