Skip to content

Commit

Permalink
fix: break when getting blocks count is less then hash chunk size
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Suho committed Nov 26, 2020
1 parent c29817f commit 5ce6db6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ To be released.
### Backward-incompatible API changes

### Backward-incompatible network protocol changes
- If the count of blocks `Swarm<T>` have received is less than
the `Swarm<T>.FindNextHashesChunkSize`, `Swarm<T>` will no longer retry. [[#1112]]

### Backward-incompatible storage format changes

Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,7 @@ out HashDigest<SHA256> branchPoint
cancellationToken
);

var receivedBlockCountCurrentLoop = 0;
await foreach (Block<T> block in blocks)
{
_logger.Debug(
Expand All @@ -1877,11 +1878,11 @@ out HashDigest<SHA256> branchPoint
renderBlocks: renderBlocks,
renderActions: renderActions
);
receivedBlockCount++;
receivedBlockCountCurrentLoop++;
progress?.Report(new BlockDownloadState
{
TotalBlockCount = totalBlockCount,
ReceivedBlockCount = receivedBlockCount,
ReceivedBlockCount = receivedBlockCount + receivedBlockCountCurrentLoop,
ReceivedBlockHash = block.Hash,
SourcePeer = peer,
});
Expand All @@ -1891,6 +1892,18 @@ out HashDigest<SHA256> 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)
Expand Down

0 comments on commit 5ce6db6

Please sign in to comment.