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

fix(net): reset block demand when not changed #1167

Conversation

moreal
Copy link
Contributor

@moreal moreal commented Jan 21, 2021

This fixes an issue where it can reset block demand at an incorrect time. For instance:

  • Received BlockHeader 100 and BlockDemand 100 block.
  • ProcessFillBlocks() starts to download the 100 blocks.
  • Received BlockHeader 101 and BlockDemand 101 block.
  • ProcessFillBlocks() finished to download the 100 blocks and reset Swarm<T>.BlockDemand as null.
  • Though BlockHeader 101 was received, it was ignored.

I tried to fix the problem by resetting the block demand as null when starting SyncPreviousBlocksAsync() after moving the block demand as the local variable, but it makes many code changes and I felt hard to build the situation. So I fixed the problem with the current changes simply. Also, I skipped the changelog because Swarm<T>.BlockDemand was not released yet. If you think it needs to be recorded in the changelog or have other suggestions, please leave your opinions free.

@moreal moreal changed the title fix(net): reset block demand on correct time [WIP] fix(net): reset block demand on correct time Jan 21, 2021
@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch 3 times, most recently from 90b1c05 to 81d7c28 Compare January 22, 2021 08:25
@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #1167 (e14af51) into main (fb4a208) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1167      +/-   ##
==========================================
- Coverage   87.77%   87.67%   -0.10%     
==========================================
  Files         355      355              
  Lines       30812    30840      +28     
==========================================
- Hits        27044    27039       -5     
- Misses       2057     2088      +31     
- Partials     1711     1713       +2     
Impacted Files Coverage Δ
Libplanet.Tests/Net/SwarmTest.cs 96.03% <100.00%> (+0.21%) ⬆️
Libplanet/Net/Swarm.cs 81.96% <100.00%> (-0.86%) ⬇️
Libplanet/Net/NetMQTransport.cs 79.41% <0.00%> (-4.18%) ⬇️
Libplanet/Net/Protocols/KademliaProtocol.cs 78.61% <0.00%> (-0.80%) ⬇️
Libplanet/Store/DefaultStore.cs 87.76% <0.00%> (+1.56%) ⬆️
Libplanet/Hashcash.cs 100.00% <0.00%> (+5.55%) ⬆️

@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch 2 times, most recently from 51404b2 to 5d70c66 Compare January 22, 2021 08:36
@moreal moreal changed the title [WIP] fix(net): reset block demand on correct time fix(net): reset block demand when not changed Jan 22, 2021
@moreal moreal self-assigned this Jan 22, 2021
@moreal moreal added the bug Something isn't working label Jan 22, 2021
@moreal moreal marked this pull request as ready for review January 22, 2021 09:02
Copy link
Contributor

@dahlia dahlia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a regression test for this bug? Would it be difficult or too complicated?

longfin
longfin previously approved these changes Jan 25, 2021
@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch 2 times, most recently from 7b93570 to 61dcf01 Compare January 25, 2021 05:34
@moreal
Copy link
Contributor Author

moreal commented Jan 25, 2021

Could we have a regression test for this bug? Would it be difficult or too complicated?

@dahlia I tried to write the test in 61dcf01. As a comment, I felt those events should be reorganized once. For example, the FillBlockAsyncStarted event has been called also in PreloadAsync directly even if the method named FillBlocksAsync() exists.

longfin
longfin previously approved these changes Jan 25, 2021
@moreal moreal requested a review from dahlia January 25, 2021 05:41
limebell
limebell previously approved these changes Jan 25, 2021
@@ -1758,9 +1761,14 @@ CancellationToken cancellationToken
{
// FIXME: Should only reset when BlockDemand has not changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we can remove this FIXME.

@moreal moreal dismissed stale reviews from limebell and longfin via 596683e January 25, 2021 05:52
@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch from 61dcf01 to 596683e Compare January 25, 2021 05:52
Comment on lines -1759 to -1777
// FIXME: Should only reset when BlockDemand has not changed
// from the beginning of this operation.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@limebell I removed the lines also 🙏

longfin
longfin previously approved these changes Jan 25, 2021
dahlia
dahlia previously approved these changes Jan 25, 2021
limebell
limebell previously approved these changes Jan 25, 2021
@moreal moreal dismissed stale reviews from limebell, dahlia, and longfin via a2f1f96 January 26, 2021 01:46
@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch from 596683e to a2f1f96 Compare January 26, 2021 01:46
This commit checks the situation like below steps
 - Received `BlockHeader` 19 and `BlockDemand` 19 block.
 - `ProcessFillBlocks()` starts to download the 19 blocks.
 - Received `BlockHeader` 20 and `BlockDemand` 20 block.
 - `ProcessFillBlocks()` finished to download the 19 blocks and reset
   `Swarm<T>.BlockDemand` as `null`.
 - Though `BlockHeader` 101 was received, it will be ignored.

[changelog skip]
@moreal moreal force-pushed the bugfix/network/reset-block-demand-on-correct-time branch from a2f1f96 to e14af51 Compare January 26, 2021 05:01
@moreal
Copy link
Contributor Author

moreal commented Jan 26, 2021

I rebased this pull request, PTAL @planetarium/libplanet 🙏

@moreal moreal merged commit d71b72a into planetarium:main Jan 27, 2021
longfin pushed a commit that referenced this pull request Jan 29, 2021
…d-on-correct-time

fix(net): reset block demand when not changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants