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 downloader hangs in some case #4362

Merged
merged 3 commits into from
Aug 4, 2022

Conversation

asdacap
Copy link
Contributor

@asdacap asdacap commented Aug 4, 2022

Fix downloader hangs when peer response with no body.

Changes:

  • Allow downloader and merge block downloader to process block partially.
  • In RequestBodies, exit early if peer response with no body at all.
  • In RequestReceipts, exit early if block does not have body when it should have body.
  • In DownloadBodies, throw exception when block should have body but does not.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Testing

Requires testing

  • Yes
  • No

In case you checked yes, did you write tests??

  • Yes
  • No

Comments about testing , should you have some (optional)

Further comments (optional)

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@@ -475,7 +486,13 @@ protected async Task RequestReceipts(PeerInfo peer, CancellationToken cancellati
for (int i = 0; i < result.Length; i++)
{
TxReceipt[] txReceipts = result[i];
if (!context.TrySetReceipts(i + offset, txReceipts, out Block block))
Block block = context.GetBlockByRequestIdx(i + offset);
if (block.Header.HasBody && block.Transactions.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

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

what about unlces only blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, good catch

@@ -172,6 +172,11 @@ bool HasMoreToSync()
Block currentBlock = blocks[blockIndex];
if (_logger.IsTrace) _logger.Trace($"Received {currentBlock} from {bestPeer}");

if (currentBlock.Header.HasBody && currentBlock.Body.IsEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

This is now duplicated in 3 places, should we have some kind of method for this validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, I'm still good with this expression IMO, still understandable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to currentBlock.IsBodyMissing

@asdacap asdacap force-pushed the fix-downloader-hang-in-some-case branch from 4d65f7f to 332ce66 Compare August 4, 2022 15:06
@LukaszRozmej LukaszRozmej merged commit 223172a into master Aug 4, 2022
@LukaszRozmej LukaszRozmej deleted the fix-downloader-hang-in-some-case branch August 4, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants