-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(net): add BAL requirement to block access list requests #23682
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3d6d272
feat(net): add BAL requirement to block access list requests
0xKarl98 695b99e
feat(net): reject optional BAL at ingress
0xKarl98 a7f6ca4
fix(net): remove never_loop in fetch poll_action
0xKarl98 abbb7e1
rename
0xKarl98 57601ef
fix(net): handle optional BAL queue edge cases
mattsse 2dd8642
Revert "fix(net): handle optional BAL queue edge cases"
mattsse 22de11b
fix(net): restore fetch queue comments
mattsse f7fd967
refactor(net): add peer requirement helper
mattsse 46e33d4
refactor(net): add optional BAL request helper
mattsse f827ae6
docs(net): explain optional BAL peer check
mattsse 05fc488
fix(net): reject queued optional BAL without eth71
mattsse 5c57098
Merge branch 'main' into feat/FullBlockClient
mattsse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ use reth_eth_wire::{ | |
| }; | ||
| use reth_network_api::test_utils::PeersHandle; | ||
| use reth_network_p2p::{ | ||
| block_access_lists::client::BalRequirement, | ||
| error::{EthResponseValidator, PeerRequestResult, RequestError, RequestResult}, | ||
| headers::client::HeadersRequest, | ||
| priority::Priority, | ||
|
|
@@ -195,28 +196,39 @@ impl<N: NetworkPrimitives> StateFetcher<N> { | |
| Some(*best_peer.0) | ||
| } | ||
|
|
||
| /// Returns whether any connected peer can serve BAL requests. | ||
| fn has_bal_capable_peer(&self) -> bool { | ||
| self.peers.values().any(|peer| { | ||
| !matches!(peer.state, PeerState::Closing) && | ||
| peer.capabilities.supports_eth_at_least(&EthVersion::Eth71) | ||
| }) | ||
| } | ||
|
|
||
| /// Returns the next action to return | ||
| fn poll_action(&mut self) -> PollAction { | ||
| // we only check and not pop here since we don't know yet whether a peer is available. | ||
| if self.queued_requests.is_empty() { | ||
| return PollAction::NoRequests | ||
| } | ||
| loop { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we need to change anything here? this is hard to review, and I think we can achieve this feature with fewer changes |
||
| // we only check and not pop here since we don't know yet whether a peer is available. | ||
| if self.queued_requests.is_empty() { | ||
| return PollAction::NoRequests | ||
| } | ||
|
|
||
| if self.peers.is_empty() { | ||
| return PollAction::NoPeersAvailable | ||
| } | ||
| let request = self.queued_requests.pop_front().expect("not empty"); | ||
| let Some(peer_id) = self.next_best_peer(request.best_peer_requirements()) else { | ||
| if request.should_complete_without_capable_peer(self.has_bal_capable_peer()) { | ||
| request.send_err_response(RequestError::UnsupportedCapability); | ||
| continue | ||
| } | ||
|
|
||
| let request = self.queued_requests.pop_front().expect("not empty"); | ||
| let Some(peer_id) = self.next_best_peer(request.best_peer_requirements()) else { | ||
| // no peer matches this request's requirements; requeue at the back so other | ||
| // queued requests get a chance on the next poll instead of head-of-line blocking. | ||
| self.queued_requests.push_back(request); | ||
| return PollAction::NoPeersAvailable | ||
| }; | ||
| // no peer matches this request's requirements; requeue at the back so other | ||
| // queued requests get a chance on the next poll instead of head-of-line blocking. | ||
| self.queued_requests.push_back(request); | ||
| return PollAction::NoPeersAvailable | ||
| }; | ||
|
|
||
| let request = self.prepare_block_request(peer_id, request); | ||
| let request = self.prepare_block_request(peer_id, request); | ||
|
|
||
| PollAction::Ready(FetchAction::BlockRequest { peer_id, request }) | ||
| return PollAction::Ready(FetchAction::BlockRequest { peer_id, request }) | ||
| } | ||
| } | ||
|
|
||
| /// Advance the state the syncer | ||
|
|
@@ -602,6 +614,7 @@ pub(crate) enum DownloadRequest<N: NetworkPrimitives> { | |
| request: Vec<B256>, | ||
| response: oneshot::Sender<PeerRequestResult<BlockAccessLists>>, | ||
| priority: Priority, | ||
| requirement: BalRequirement, | ||
| }, | ||
| /// Download receipts for the given block hashes and send response through channel | ||
| GetReceipts { | ||
|
|
@@ -639,6 +652,22 @@ impl<N: NetworkPrimitives> DownloadRequest<N> { | |
| self.get_priority().is_normal() | ||
| } | ||
|
|
||
| /// Returns whether the request may complete locally when no capable peer exists. | ||
| const fn should_complete_without_capable_peer(&self, has_bal_capable_peer: bool) -> bool { | ||
| matches!(self, Self::GetBlockAccessLists { requirement: BalRequirement::Optional, .. }) && | ||
| !has_bal_capable_peer | ||
| } | ||
|
|
||
| /// Sends an error response to the waiting caller. | ||
| fn send_err_response(self, err: RequestError) { | ||
| let _ = match self { | ||
| Self::GetBlockHeaders { response, .. } => response.send(Err(err)).ok(), | ||
| Self::GetBlockBodies { response, .. } => response.send(Err(err)).ok(), | ||
| Self::GetBlockAccessLists { response, .. } => response.send(Err(err)).ok(), | ||
| Self::GetReceipts { response, .. } => response.send(Err(err)).ok(), | ||
| }; | ||
| } | ||
|
|
||
| /// Returns the best peer requirements for this request. | ||
| fn best_peer_requirements(&self) -> BestPeerRequirements { | ||
| match self { | ||
|
|
@@ -1541,6 +1570,7 @@ mod tests { | |
| request: vec![], | ||
| response: tx, | ||
| priority: Priority::Normal, | ||
| requirement: BalRequirement::Mandatory, | ||
| }); | ||
|
|
||
| let waker = noop_waker(); | ||
|
|
@@ -1583,4 +1613,76 @@ mod tests { | |
| assert_eq!(peer_id, peer_71); | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_optional_bal_request_completes_without_capable_peer() { | ||
| use futures::task::noop_waker; | ||
| use std::task::{Context, Poll}; | ||
|
|
||
| let manager = PeersManager::new(PeersConfig::default()); | ||
| let mut fetcher = | ||
| StateFetcher::<EthNetworkPrimitives>::new(manager.handle(), Default::default()); | ||
|
|
||
| let peer_old = B512::random(); | ||
| let caps_old = Arc::new(Capabilities::new(vec![])); | ||
| fetcher.new_active_peer( | ||
| peer_old, | ||
| B256::random(), | ||
| 100, | ||
| caps_old, | ||
| Arc::new(AtomicU64::new(10)), | ||
| None, | ||
| ); | ||
|
|
||
| let (tx, rx) = oneshot::channel(); | ||
| fetcher.queued_requests.push_back(DownloadRequest::GetBlockAccessLists { | ||
| request: vec![], | ||
| response: tx, | ||
| priority: Priority::Normal, | ||
| requirement: BalRequirement::Optional, | ||
| }); | ||
|
|
||
| let waker = noop_waker(); | ||
| let mut cx = Context::from_waker(&waker); | ||
|
|
||
| assert!(matches!(fetcher.poll(&mut cx), Poll::Pending)); | ||
| assert!(fetcher.queued_requests.is_empty()); | ||
| assert_eq!(rx.await.unwrap().unwrap_err(), RequestError::UnsupportedCapability); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_optional_bal_request_waits_for_busy_capable_peer() { | ||
| use futures::task::noop_waker; | ||
| use std::task::{Context, Poll}; | ||
|
|
||
| let manager = PeersManager::new(PeersConfig::default()); | ||
| let mut fetcher = | ||
| StateFetcher::<EthNetworkPrimitives>::new(manager.handle(), Default::default()); | ||
|
|
||
| let peer_71 = B512::random(); | ||
| let caps_71 = Arc::new(Capabilities::from(vec![Capability::new("eth".into(), 71)])); | ||
| fetcher.new_active_peer( | ||
| peer_71, | ||
| B256::random(), | ||
| 100, | ||
| caps_71, | ||
| Arc::new(AtomicU64::new(10)), | ||
| None, | ||
| ); | ||
| fetcher.peers.get_mut(&peer_71).expect("peer exists").state = PeerState::GetBlockHeaders; | ||
|
|
||
| let (tx, _rx) = oneshot::channel(); | ||
| fetcher.queued_requests.push_back(DownloadRequest::GetBlockAccessLists { | ||
| request: vec![], | ||
| response: tx, | ||
| priority: Priority::Normal, | ||
| requirement: BalRequirement::Optional, | ||
| }); | ||
|
|
||
| let waker = noop_waker(); | ||
| let mut cx = Context::from_waker(&waker); | ||
|
|
||
| assert!(matches!(fetcher.poll(&mut cx), Poll::Pending)); | ||
| assert_eq!(fetcher.queued_requests.len(), 1); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.