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: Fix extra GetBlock requests for validators #27

Merged
merged 4 commits into from
Nov 10, 2023

Conversation

slowli
Copy link
Contributor

@slowli slowli commented Nov 7, 2023

What ❔

If the SyncBlocks actor runs on a validator node, the node previously produced unnecessary GetBlock requests to peers. This is because SyncBlocks logic assumed that new blocks are only added within the actor. This PR lifts this assumption; it filters GetBlock requests and cancels pending requests reacting to new blocks being put in the storage.

Why ❔

Extra GetBlock requests waste traffic and processing time of peers.

@slowli slowli marked this pull request as ready for review November 7, 2023 12:50
@@ -139,6 +158,31 @@ impl PeerStates {
}
}

/// Cancels pending block retrieval for blocks that appear in the storage using other means
/// (e.g., thanks to the consensus algorithm). This works at best-effort basis; it's not guaranteed
/// that this method will timely cancel all block retrievals.
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to compromise here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the most general approach I've come up with that doesn't make many assumptions as to what could update blocks externally and how these updates would look (e.g., whether it's consensus or some other actor). I guess with the knowledge of consensus we could do marginally better by cancelling not only the latest block produced by consensus, but all the preceding blocks as well; is this what you had in mind? If you have any suggestions, I'm happy to listen.

Copy link
Collaborator

@pompon0 pompon0 Nov 9, 2023

Choose a reason for hiding this comment

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

I mean you are using watch to signal the received block from external source, which naturally will lead to NOT cancelling some blocks fetching tasks if multiple blocks are received from an external source at the same time. Also AFAICT there is a race condition between spawning a fetching routine for a block and receiving this block from an external source.

Copy link
Member

@brunoffranca brunoffranca left a comment

Choose a reason for hiding this comment

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

Looks good. Just to be sure, this only cancels ongoing requests for the next block? It doesn't prevent validators from requesting non-existent blocks to begin with, correct?

@slowli
Copy link
Contributor Author

slowli commented Nov 9, 2023

@brunoffranca WDYM by non-existent blocks? SyncBlocks would only request blocks for which there's a proof of existence (either of the block itself or a following block).

@brunoffranca
Copy link
Member

I misremembered how sync_blocks works. I thought it would always try to fetch block N+1 if we had block N. But you just ask peers for their head number. My question doesn't apply then.

@slowli slowli merged commit 04c9639 into main Nov 10, 2023
4 checks passed
@slowli slowli deleted the aov-bft-370-fix-extra-getblock-requests-for-validators branch November 10, 2023 09:11
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.

3 participants