feat/view: assure heads in a view are sorted (#2493)

* feat/view: assure heads in a view are sorted

Allows O(n) comparisons, adds an alternate equiv relation
which takes O(n^2) for integrity verification.

Ref #2133

* revert: remove custom PartialEq impl, there are no duplicates

* fix: do not sort the live_heads, that alters the local view

* refactor/view: heads should not be public

* chore/spellcheck: add unfinalized

* fix/view: add missing len() and is_empty() fns

* quirk

* vec is not view

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

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

* Update node/network/bridge/src/lib.rs

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

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

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

* fixup comment

* fix botched test

Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
Bernhard Schuster
2021-02-23 16:39:57 +01:00
committed by GitHub
parent 571651e326
commit e3f776abed
11 changed files with 85 additions and 38 deletions
@@ -417,7 +417,7 @@ where
.filter(|(_peer, view)| {
// collect all direct interests of a peer w/o ancestors
state
.cached_live_candidates_unioned(view.heads.iter())
.cached_live_candidates_unioned(view.iter())
.contains(&candidate_hash)
})
.map(|(peer, _view)| peer.clone())
@@ -623,7 +623,7 @@ where
let _timer = metrics.time_process_incoming_peer_message();
// obtain the set of candidates we are interested in based on our current view
let live_candidates = state.cached_live_candidates_unioned(state.view.heads.iter());
let live_candidates = state.cached_live_candidates_unioned(state.view.iter());
// check if the candidate is of interest
let candidate_hash = message.candidate_hash;
@@ -764,7 +764,7 @@ where
// peers view must contain the candidate hash too
cached_live_candidates_unioned(
per_relay_parent,
view.heads.iter(),
view.iter(),
).contains(&message.candidate_hash)
})
.map(|(peer, _)| -> PeerId { peer.clone() })