This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Request based PoV distribution #2640
Merged
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
df828ac
Indentation fix.
eskimor 06d4d90
Prepare request-response for PoV fetching.
eskimor 6a940eb
Drop old PoV distribution.
eskimor a7fc368
WIP: Fetch PoV directly from backing.
eskimor 9847b81
Merge branch 'master' into rk-pov-distribution-2590
eskimor e03ff75
Backing compiles.
eskimor a49b4d4
Runtime access and connection management for PoV distribution.
eskimor 545e950
Get rid of seemingly dead code.
eskimor 47d9f5f
Implement PoV fetching.
eskimor 0a283ab
Don't send `ConnectToValidators` for empty list.
eskimor afd795f
Even better - no need to check over and over again.
eskimor 1c3eec8
PoV fetching implemented.
eskimor fb24855
Merge branch 'master' into rk-pov-distribution-2590
eskimor cceddce
Check PoV hash upon reception.
eskimor 89f0bf9
Implement retry of PoV fetching in backing.
eskimor ab75fea
Avoid pointless validation spawning.
eskimor 10da891
Merge branch 'master' into rk-pov-distribution-2590
eskimor 3915a57
Add jaeger span to pov requesting.
eskimor fa6409e
Add back tracing.
eskimor 8b9c2d4
Review remarks.
eskimor 2d27be5
Merge branch 'master' into rk-pov-distribution-2590
eskimor 4af7d2e
Whitespace.
eskimor 5c09829
Whitespace again.
eskimor ea9bde4
Cleanup + fix tests.
eskimor 4207eaf
Log to log target in overseer.
eskimor 3691061
Fix more tests.
eskimor b1a201a
Don't fail if group cannot be found.
eskimor 298fe9d
Simple test for PoV fetcher.
eskimor af9f12c
Handle missing group membership better.
eskimor 0c30792
Add test for retry functionality.
eskimor eb47465
Fix flaky test.
eskimor 071bcca
Merge branch 'master' into rk-pov-distribution-2590
eskimor 3fa5791
Spaces again.
eskimor 82d4a11
Guide updates.
eskimor b58a2ab
Merge branch 'master' into rk-pov-distribution-2590
eskimor a0609e7
Spaces.
eskimor 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
Runtime access and connection management for PoV distribution.
- Loading branch information
commit a49b4d431b2a58b525df2b67199f734f23017d42
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
128 changes: 128 additions & 0 deletions
128
node/network/availability-distribution/src/pov_requester/mod.rs
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 |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright 2021 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! PoV requester takes care of requesting PoVs from validators of a backing group. | ||
|
|
||
| use futures::channel::mpsc; | ||
| use lru::LruCache; | ||
|
|
||
| use polkadot_node_network_protocol::{PeerId, peer_set::PeerSet}; | ||
| use polkadot_primitives::v1::{AuthorityDiscoveryId, Hash, SessionIndex}; | ||
| use polkadot_subsystem::{ActiveLeavesUpdate, SubsystemContext, messages::{AllMessages, NetworkBridgeMessage}}; | ||
|
|
||
| use crate::runtime::Runtime; | ||
|
|
||
| /// Number of sessions we want to keep in the LRU. | ||
| const NUM_SESSIONS: usize = 2; | ||
|
|
||
| pub struct PoVRequester { | ||
|
|
||
| /// We only ever care about being connected to validators of at most two sessions. | ||
| /// | ||
| /// So we keep an LRU for managing connection requests of size 2. | ||
| connected_validators: LruCache<SessionIndex, mpsc::Receiver<(AuthorityDiscoveryId, PeerId)>>, | ||
| } | ||
|
|
||
| impl PoVRequester { | ||
| /// Create a new requester for PoVs. | ||
| pub fn new() -> Self { | ||
| Self { | ||
| connected_validators: LruCache::new(NUM_SESSIONS), | ||
| } | ||
| } | ||
|
|
||
| /// Make sure we are connected to the right set of validators. | ||
| /// | ||
| /// On every `ActiveLeavesUpdate`, we check whether we are connected properly to our current | ||
| /// validator group. | ||
| pub async fn update_connected_validators<Context>( | ||
| &mut self, | ||
| ctx: &mut Context, | ||
| runtime: &mut Runtime, | ||
| update: &ActiveLeavesUpdate, | ||
| ) -> super::Result<()> | ||
| where | ||
| Context: SubsystemContext, | ||
| { | ||
| let activated = update.activated.iter().map(|(h, _)| h); | ||
| let activated_sessions = | ||
| get_activated_sessions(ctx, runtime, activated).await?; | ||
|
|
||
| for (parent, session_index) in activated_sessions { | ||
| if self.connected_validators.contains(&session_index) { | ||
| continue | ||
| } | ||
| self.connected_validators.put( | ||
| session_index, | ||
| connect_to_relevant_validators(ctx, runtime, parent, session_index).await? | ||
| ); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| async fn get_activated_sessions<Context>(ctx: &mut Context, runtime: &mut Runtime, new_heads: impl Iterator<Item = &Hash>) | ||
| -> super::Result<impl Iterator<Item = (Hash, SessionIndex)>> | ||
| where | ||
| Context: SubsystemContext, | ||
| { | ||
| let mut sessions = Vec::new(); | ||
| for parent in new_heads { | ||
| sessions.push((*parent, runtime.get_session_index(ctx, *parent).await?)); | ||
| } | ||
| Ok(sessions.into_iter()) | ||
| } | ||
|
|
||
| async fn connect_to_relevant_validators<Context>( | ||
| ctx: &mut Context, | ||
| runtime: &mut Runtime, | ||
| parent: Hash, | ||
| session: SessionIndex | ||
| ) | ||
| -> super::Result<mpsc::Receiver<(AuthorityDiscoveryId, PeerId)>> | ||
| where | ||
| Context: SubsystemContext, | ||
| { | ||
| let validator_ids = determine_relevant_validators(ctx, runtime, parent, session).await?; | ||
| // We don't actually care about `PeerId`s, just keeping receiver so we stay connected: | ||
| let (tx, rx) = mpsc::channel(0); | ||
| ctx.send_message(AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToValidators { | ||
| validator_ids, peer_set: PeerSet::Validation, connected: tx | ||
| })).await; | ||
| Ok(rx) | ||
| } | ||
|
|
||
| async fn determine_relevant_validators<Context>( | ||
| ctx: &mut Context, | ||
| runtime: &mut Runtime, | ||
| parent: Hash, | ||
| session: SessionIndex, | ||
| ) | ||
| -> super::Result<Vec<AuthorityDiscoveryId>> | ||
| where | ||
| Context: SubsystemContext, | ||
| { | ||
| let info = runtime.get_session_info_by_index(ctx, parent, session).await?; | ||
| if let Some(validator_info) = &info.validator_info { | ||
| let indeces = info.session_info.validator_groups.get(validator_info.our_group.0 as usize) | ||
| .expect("Our group got retrieved from that session info, it must exist. qed.") | ||
| .clone(); | ||
| Ok(indeces.into_iter().map(|i| info.session_info.discovery_keys[i.0 as usize].clone()).collect()) | ||
| } else { | ||
| Ok(Vec::new()) | ||
| } | ||
| } |
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.