Implement grid topology routing for the statement distribution subsystem (#5476)

* Move NewGossipTopology -> SessionGridTopology outside as this implementation is shared

* Add method to return peers difference between topologies

* Implement basic grid topology usage for the bitfield distribution

* Fix tests

* Oops, fix tests

* Add some tests for random routing

* Add a unit test for topology distribution

* Store the current and the previous topology to match sessions boundaries

* Update tests

* Update node/network/bitfield-distribution/src/lib.rs

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

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

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

* Update node/network/bitfield-distribution/src/lib.rs

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

* Add some debug

* Fix tests as HashSet order is undefined

* Move session bounded topology to the common code part

* Fix tests

* Allow to select routing by peer index

* Implement grid topology in the statement distribution subsystem

* Fix tests compilation

* Fix test

* Refactor API slightly

* Address review comments

* Reduce runtime error logging severity

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

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>

* Update node/network/bitfield-distribution/src/tests.rs

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>

* Fmt run

* Use named struct

* Fix logging stuff

* One more accidental fmt damage

* Increase active queue size and add metrics

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Revert "Increase active queue size and add metrics"

This reverts commit c4f48e8bded6dfeb9c62814ba2f8d815c34b04cf.

* Use validator index to choose the routing strategy

Noted by: @rphmeier

* Fix test after distribution logic fix

Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>
Co-authored-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
Vsevolod Stakhov
2022-05-18 13:27:06 +01:00
committed by GitHub
parent 28cae2ef45
commit 195b901cc9
8 changed files with 189 additions and 92 deletions
@@ -505,10 +505,11 @@ fn peer_view_update_sends_messages() {
let peer = PeerId::random();
executor::block_on(async move {
let gossip_peers = HashSet::from_iter(vec![peer.clone()].into_iter());
let mut topology: SessionGridTopology = Default::default();
topology.peers_x = HashSet::from_iter(vec![peer.clone()].into_iter());
update_peer_view_and_maybe_send_unlocked(
peer.clone(),
&gossip_peers,
&topology,
&mut peer_data,
&mut ctx,
&active_heads,
@@ -634,10 +635,12 @@ fn circulated_statement_goes_to_all_peers_with_view() {
};
let statement = StoredStatement { comparator: &comparator, statement: &statement };
let gossip_peers =
let mut topology: SessionGridTopology = Default::default();
topology.peers_x =
HashSet::from_iter(vec![peer_a.clone(), peer_b.clone(), peer_c.clone()].into_iter());
let needs_dependents = circulate_statement(
&gossip_peers,
RequiredRouting::GridXY,
&topology,
&mut peer_data,
&mut ctx,
hash_b,
@@ -2004,19 +2007,31 @@ fn handle_multiple_seconded_statements() {
our_neighbors_y: HashMap::new(),
};
// This is relying on the fact that statement distribution
// just extracts the peer IDs from this struct and does nothing else
// with it.
// Create a topology to ensure that we send messages not to `peer_a`/`peer_b`
for (i, peer) in lucky_peers.iter().enumerate() {
let authority_id = AuthorityPair::generate().0.public();
t.our_neighbors_x.insert(
t.our_neighbors_y.insert(
authority_id,
network_bridge_event::TopologyPeerInfo {
peer_ids: vec![peer.clone()],
validator_index: (i as u32).into(),
validator_index: (i as u32 + 2_u32).into(),
},
);
}
t.our_neighbors_x.insert(
AuthorityPair::generate().0.public(),
network_bridge_event::TopologyPeerInfo {
peer_ids: vec![peer_a.clone()],
validator_index: 0_u32.into(),
},
);
t.our_neighbors_x.insert(
AuthorityPair::generate().0.public(),
network_bridge_event::TopologyPeerInfo {
peer_ids: vec![peer_b.clone()],
validator_index: 1_u32.into(),
},
);
t
};