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 sync peer disconnected when peer has no body #4267

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

asdacap
Copy link
Contributor

@asdacap asdacap commented Jul 11, 2022

Fixes issue on kurtosis when peer return empty array on request body.

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • 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...

@asdacap asdacap requested a review from MarekM25 July 11, 2022 13:33
Comment on lines 308 to 309
if (blocks == null || blocks.Length == 0)
break;
Copy link
Member

@LukaszRozmej LukaszRozmej Jul 11, 2022

Choose a reason for hiding this comment

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

Shouldn't we validate that all Roots of requested blocks are empty and if not disconnect the peer? So if we are requesting empty or not blocks?

That would check TxRoot, ReceiptsRoot and UncleHash.

Actually, we can do that before sending the request!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea. I'm just replicating the logic of MergeBlockDownloader. I guess if all root is empty, then we need to create empty block to replace them? But what if the peer is just waiting to download block from one of it peers?

Copy link
Member

Choose a reason for hiding this comment

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

We already have it here:

if (header.HasBody)
{
Blocks[i - 1] = new Block(header);
_indexMapping.Add(currentBodyIndex, i - 1);
currentBodyIndex++;
NonEmptyBlockHashes.Add(header.Hash);
}
else
{
Blocks[i - 1] = new Block(header, BlockBody.Empty);
}

so why is that a problem? Some kind of edge case?

Copy link
Member

Choose a reason for hiding this comment

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

If all roots are empty don't send the request and don't expect response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think the problem is that the headers returned is 1 instead of 2 which is the minimum.

@asdacap asdacap force-pushed the fix-disconnected-when-sync-peer-has-no-body branch from 914974a to dbacb69 Compare July 11, 2022 15:17
Comment on lines +290 to +295
if (headers.Length < 2)
{
// Peer dont have new header
break;
}

Copy link
Member

Choose a reason for hiding this comment

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

Can you include more robust comment explanation of this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you have in mind?

@asdacap asdacap merged commit 2e4bc1c into master Jul 12, 2022
@asdacap asdacap deleted the fix-disconnected-when-sync-peer-has-no-body branch July 12, 2022 05:27
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