Commit fd8a9d76 authored by Cecile Tonglet's avatar Cecile Tonglet
Browse files

Merge commit 21f31f78 (no conflict)

Parent branch: origin/master
Forked at: 4234dee5
parents e8573ae5 21f31f78
...@@ -4358,6 +4358,7 @@ dependencies = [ ...@@ -4358,6 +4358,7 @@ dependencies = [
"polkadot-erasure-coding", "polkadot-erasure-coding",
"polkadot-primitives", "polkadot-primitives",
"polkadot-validation", "polkadot-validation",
"rand 0.7.3",
"sc-network", "sc-network",
"sc-network-gossip", "sc-network-gossip",
"sp-api", "sp-api",
......
...@@ -26,6 +26,7 @@ futures-timer = "2.0" ...@@ -26,6 +26,7 @@ futures-timer = "2.0"
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
wasm-timer = "0.2.4" wasm-timer = "0.2.4"
rand = "0.7.3"
[dev-dependencies] [dev-dependencies]
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
......
...@@ -24,6 +24,7 @@ use crate::legacy::collator_pool::Role; ...@@ -24,6 +24,7 @@ use crate::legacy::collator_pool::Role;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::time::Duration; use std::time::Duration;
use wasm_timer::Instant; use wasm_timer::Instant;
use rand::seq::SliceRandom;
const LIVE_FOR: Duration = Duration::from_secs(60 * 5); const LIVE_FOR: Duration = Duration::from_secs(60 * 5);
...@@ -106,9 +107,7 @@ impl<C: Clone> LocalCollations<C> { ...@@ -106,9 +107,7 @@ impl<C: Clone> LocalCollations<C> {
relay_parent: Hash, relay_parent: Hash,
targets: HashSet<ValidatorId>, targets: HashSet<ValidatorId>,
collation: C collation: C
) ) -> impl Iterator<Item=(ValidatorId, C)> + 'a {
-> impl Iterator<Item=(ValidatorId, C)> + 'a
{
self.local_collations.insert(relay_parent, LocalCollation { self.local_collations.insert(relay_parent, LocalCollation {
targets, targets,
collation, collation,
...@@ -119,8 +118,17 @@ impl<C: Clone> LocalCollations<C> { ...@@ -119,8 +118,17 @@ impl<C: Clone> LocalCollations<C> {
.expect("just inserted to this key; qed"); .expect("just inserted to this key; qed");
let borrowed_collation = &local.collation; let borrowed_collation = &local.collation;
// If we are conected to multiple validators,
// make sure we always send the collation to one of the validators
// we are registered as backup. This ensures that one collator that
// is primary at multiple validators, desn't block the Parachain from progressing.
let mut rng = rand::thread_rng();
let diff = local.targets.difference(&self.primary_for).collect::<Vec<_>>();
local.targets local.targets
.intersection(&self.primary_for) .intersection(&self.primary_for)
.chain(diff.choose(&mut rng).map(|r| r.clone()))
.map(move |k| (k.clone(), borrowed_collation.clone())) .map(move |k| (k.clone(), borrowed_collation.clone()))
} }
...@@ -149,7 +157,7 @@ mod tests { ...@@ -149,7 +157,7 @@ mod tests {
}; };
let mut tracker = LocalCollations::new(); let mut tracker = LocalCollations::new();
assert!(tracker.add_collation(relay_parent, targets, 5).next().is_none()); assert!(tracker.add_collation(relay_parent, targets, 5).next().is_some());
assert_eq!(tracker.note_validator_role(key, Role::Primary), vec![(relay_parent, 5)]); assert_eq!(tracker.note_validator_role(key, Role::Primary), vec![(relay_parent, 5)]);
} }
...@@ -165,7 +173,7 @@ mod tests { ...@@ -165,7 +173,7 @@ mod tests {
}; };
let mut tracker: LocalCollations<u8> = LocalCollations::new(); let mut tracker: LocalCollations<u8> = LocalCollations::new();
assert!(tracker.add_collation(relay_parent, targets, 5).next().is_none()); assert!(tracker.add_collation(relay_parent, targets, 5).next().is_some());
assert!(tracker.note_validator_role(orig_key.clone(), Role::Primary).is_empty()); assert!(tracker.note_validator_role(orig_key.clone(), Role::Primary).is_empty());
assert_eq!(tracker.fresh_key(&orig_key, &new_key), vec![(relay_parent, 5u8)]); assert_eq!(tracker.fresh_key(&orig_key, &new_key), vec![(relay_parent, 5u8)]);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment