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

Improve pending blocks retrieval mechanism #4227

Merged

Conversation

Gabriel-Trintinalia
Copy link
Contributor

@Gabriel-Trintinalia Gabriel-Trintinalia commented Aug 8, 2022

Signed-off-by: Gabriel Trintinalia gabriel.trintinalia@consensys.net

PR description

When a block is saved for future import, requesting the lowest announced block parent does not seem to be always the best option. It can be that we cannot retrieve this block and then we keep selecting the lowest block over and over and eventually it does not fix the gap. A better approach for trying to unstick could be to request the parent of the lowest pending ancestor

Changes:

  • When saving a block for future import, try to retrieve the parent of the lowest pending block connected to this block.
  • When saving a block for future import, do not try to retrieve the parent the lowest announced block.
  • Avoid requesting the same parent block several times when saving pending blocks
  • Improve logs when saving/importing a block

Fixed Issue(s)

potential aid for #3955
#4197

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Changelog

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as draft August 8, 2022 03:22
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
@non-fungible-nelson non-fungible-nelson added the TeamRevenant GH issues worked on by Revenant Team label Aug 8, 2022
Gabriel-Trintinalia and others added 5 commits August 9, 2022 16:26
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
@Gabriel-Trintinalia Gabriel-Trintinalia changed the title WIP: Add more log to retrieve parent method WIP: Request the parent of the lowest pending block instead of lowest announced block Aug 9, 2022
Gabriel-Trintinalia and others added 3 commits August 10, 2022 08:49
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
@Gabriel-Trintinalia Gabriel-Trintinalia changed the title WIP: Request the parent of the lowest pending block instead of lowest announced block Improve pending blocks retrieval mechanism Aug 9, 2022
@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as ready for review August 9, 2022 23:42
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
…ancestors of Block

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

This goes in the right directions, implementing a basic backward sync to fill gaps in the block propagation, I have reported just a couple of minor things.

During this code review, I have also reviewed the role of maybeProcessNonAnnouncedBlocks that looks forward, so in the future to try to proactively fetch new blocks, that usually should be notified by peers soon after, so not sure how much it is useful, instead this class was missing something that looks backward, that is probably much needed, not sure if the author relied on the fact that full sync eventally fills the gaps, but when full sync stalls (for yet unknown reasons) we are in throuble, and this PR should fix that!

Gabriel-Trintinalia and others added 5 commits August 11, 2022 11:53
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
…ing pending block to the list

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
…block

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

I'm leaning on @fab-10 's review here a fair bit for the finer details of how this works but looks good to my understanding.

Copy link
Contributor

@pinges pinges left a comment

Choose a reason for hiding this comment

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

LGTM, you might want to think about getting rid of the second parameter of the pendingAncestorBlockOf() method.
Some finals missing :-)

LOG.info(
"Imported {} pending blocks: {}",
r.size(),
r.stream().map(b -> b.getHeader().getNumber()).collect(Collectors.toList()));
}
if (t != null) {
LOG.error("Error importing pending blocks", t);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if there was an error? Do we need to remove a block from the pending blocks? Depending on what error was thrown?

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
@macfarla macfarla enabled auto-merge (squash) August 12, 2022 03:54
Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
auto-merge was automatically disabled August 12, 2022 03:59

Head branch was pushed to by a user without write access

@macfarla macfarla merged commit f847ead into hyperledger:main Aug 12, 2022
@Gabriel-Trintinalia Gabriel-Trintinalia deleted the 3955-besu-stop-importing branch October 5, 2022 01:30
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* Add more log to retrieve parent method
* Request the lowest pending ancestor when saving a block
* Replace recursive implementation with iterative when getting pending ancestors of Block
* Decrease scope of synchronized block to reflect only the event of adding pending block to the list
* Add fork to the chain so test is more representative

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Co-authored-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mainnet TeamRevenant GH issues worked on by Revenant Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants