mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-09 20:39:29 +00:00
fix tributary sync test
This commit is contained in:
parent
8c020abb86
commit
790fe7ee23
1 changed files with 25 additions and 16 deletions
|
@ -35,10 +35,11 @@ async fn sync_test() {
|
||||||
|
|
||||||
// Have the rest form a P2P net
|
// Have the rest form a P2P net
|
||||||
let mut tributary_arcs = vec![];
|
let mut tributary_arcs = vec![];
|
||||||
|
let mut p2p_threads = vec![];
|
||||||
for (i, (p2p, tributary)) in tributaries.drain(..).enumerate() {
|
for (i, (p2p, tributary)) in tributaries.drain(..).enumerate() {
|
||||||
let tributary = Arc::new(RwLock::new(tributary));
|
let tributary = Arc::new(RwLock::new(tributary));
|
||||||
tributary_arcs.push(tributary.clone());
|
tributary_arcs.push(tributary.clone());
|
||||||
tokio::spawn(handle_p2p(
|
let thread = tokio::spawn(handle_p2p(
|
||||||
Ristretto::generator() * *keys[i],
|
Ristretto::generator() * *keys[i],
|
||||||
p2p,
|
p2p,
|
||||||
Arc::new(RwLock::new(HashMap::from([(
|
Arc::new(RwLock::new(HashMap::from([(
|
||||||
|
@ -46,6 +47,7 @@ async fn sync_test() {
|
||||||
ActiveTributary { spec: spec.clone(), tributary },
|
ActiveTributary { spec: spec.clone(), tributary },
|
||||||
)]))),
|
)]))),
|
||||||
));
|
));
|
||||||
|
p2p_threads.push(thread);
|
||||||
}
|
}
|
||||||
let tributaries = tributary_arcs;
|
let tributaries = tributary_arcs;
|
||||||
|
|
||||||
|
@ -112,21 +114,28 @@ async fn sync_test() {
|
||||||
assert!(syncer_tributary.read().await.tip().await != syncer_tip);
|
assert!(syncer_tributary.read().await.tip().await != syncer_tip);
|
||||||
|
|
||||||
// Verify it's now participating in consensus
|
// Verify it's now participating in consensus
|
||||||
// Because only `t` validators are used in a commit, check several commits
|
// Because only `t` validators are used in a commit, take n - t nodes offline
|
||||||
// This should be biased in favor of the syncer since we're using the syncer's view of the commit
|
// leaving only `t` nodes. Which should force it to participate in the consensus
|
||||||
for _ in 0 .. 10 {
|
// of next blocks.
|
||||||
let syncer_tributary = syncer_tributary.read().await;
|
let n = (spec.n() - spec.t()) as usize;
|
||||||
if syncer_tributary
|
for t in p2p_threads.iter().take(n) {
|
||||||
.reader()
|
t.abort();
|
||||||
.parsed_commit(&syncer_tributary.tip().await)
|
|
||||||
.unwrap()
|
|
||||||
.validators
|
|
||||||
.iter()
|
|
||||||
.any(|signer| signer == &syncer_key.to_bytes())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sleep(Duration::from_secs(block_time)).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for a block
|
||||||
|
sleep(Duration::from_secs(block_time)).await;
|
||||||
|
|
||||||
|
let syncer_tributary = syncer_tributary.read().await;
|
||||||
|
if syncer_tributary
|
||||||
|
.reader()
|
||||||
|
.parsed_commit(&syncer_tributary.tip().await)
|
||||||
|
.unwrap()
|
||||||
|
.validators
|
||||||
|
.iter()
|
||||||
|
.any(|signer| signer == &syncer_key.to_bytes())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
panic!("synced tributary didn't start participating in consensus");
|
panic!("synced tributary didn't start participating in consensus");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue