refactor grid topology to expose more info to subsystems (#6140)

* refactor grid topology to expose more info to subsystems

* fix grid_topology test

* fix overseer test

* Update node/network/protocol/src/grid_topology.rs

Co-authored-by: Vsevolod Stakhov <vsevolod.stakhov@parity.io>

* Update node/network/protocol/src/grid_topology.rs

Co-authored-by: Andronik <write@reusable.software>

* Update node/network/protocol/src/grid_topology.rs

Co-authored-by: Andronik <write@reusable.software>

* fix bug in populating topology

* fmt

Co-authored-by: Vsevolod Stakhov <vsevolod.stakhov@parity.io>
Co-authored-by: Andronik <write@reusable.software>
This commit is contained in:
asynchronous rob
2022-10-12 18:30:12 -05:00
committed by GitHub
parent bccffcad12
commit a7780e0797
17 changed files with 614 additions and 328 deletions
+7 -12
View File
@@ -328,18 +328,13 @@ pub enum NetworkBridgeRxMessage {
NewGossipTopology {
/// The session info this gossip topology is concerned with.
session: SessionIndex,
/// Ids of our neighbors in the X dimensions of the new gossip topology,
/// along with their validator indices within the session.
///
/// We're not necessarily connected to all of them, but we should
/// try to be.
our_neighbors_x: HashMap<AuthorityDiscoveryId, ValidatorIndex>,
/// Ids of our neighbors in the X dimensions of the new gossip topology,
/// along with their validator indices within the session.
///
/// We're not necessarily connected to all of them, but we should
/// try to be.
our_neighbors_y: HashMap<AuthorityDiscoveryId, ValidatorIndex>,
/// Our validator index in the session, if any.
local_index: Option<ValidatorIndex>,
/// The canonical shuffling of validators for the session.
canonical_shuffling: Vec<(AuthorityDiscoveryId, ValidatorIndex)>,
/// The reverse mapping of `canonical_shuffling`: from validator index
/// to the index in `canonical_shuffling`
shuffled_indices: Vec<usize>,
},
}
@@ -14,10 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use std::{
collections::{HashMap, HashSet},
convert::TryFrom,
};
use std::{collections::HashSet, convert::TryFrom};
pub use sc_network::{PeerId, ReputationChange};
@@ -27,25 +24,15 @@ use polkadot_node_network_protocol::{
};
use polkadot_primitives::v2::{AuthorityDiscoveryId, SessionIndex, ValidatorIndex};
/// Information about a peer in the gossip topology for a session.
#[derive(Debug, Clone, PartialEq)]
pub struct TopologyPeerInfo {
/// The validator's known peer IDs.
pub peer_ids: Vec<PeerId>,
/// The index of the validator in the discovery keys of the corresponding
/// `SessionInfo`. This can extend _beyond_ the set of active parachain validators.
pub validator_index: ValidatorIndex,
}
/// A struct indicating new gossip topology.
#[derive(Debug, Clone, PartialEq)]
pub struct NewGossipTopology {
/// The session index this topology corresponds to.
pub session: SessionIndex,
/// Neighbors in the 'X' dimension of the grid.
pub our_neighbors_x: HashMap<AuthorityDiscoveryId, TopologyPeerInfo>,
/// Neighbors in the 'Y' dimension of the grid.
pub our_neighbors_y: HashMap<AuthorityDiscoveryId, TopologyPeerInfo>,
/// The topology itself.
pub topology: SessionGridTopology,
/// The local validator index, if any.
pub local_index: Option<ValidatorIndex>,
}
/// Events from network.
@@ -122,19 +109,3 @@ impl<M> NetworkBridgeEvent<M> {
})
}
}
impl From<NewGossipTopology> for SessionGridTopology {
fn from(topology: NewGossipTopology) -> Self {
let peers_x =
topology.our_neighbors_x.values().flat_map(|p| &p.peer_ids).cloned().collect();
let peers_y =
topology.our_neighbors_y.values().flat_map(|p| &p.peer_ids).cloned().collect();
let validator_indices_x =
topology.our_neighbors_x.values().map(|p| p.validator_index.clone()).collect();
let validator_indices_y =
topology.our_neighbors_y.values().map(|p| p.validator_index.clone()).collect();
SessionGridTopology { peers_x, peers_y, validator_indices_x, validator_indices_y }
}
}