Publish ExternablBlock/SubstrateBlock, delay *Preprocess until ID acknowledged

Adds a channel for the Tributary scanner to communicate when an ID has been
acknowledged.
This commit is contained in:
Luke Parker
2023-05-08 22:20:51 -04:00
parent a7f2740dfb
commit 964fdee175
7 changed files with 252 additions and 77 deletions

View File

@@ -7,7 +7,7 @@ use rand_core::{RngCore, OsRng};
use ciphersuite::{Ciphersuite, Ristretto};
use frost::Participant;
use tokio::time::sleep;
use tokio::{time::sleep, sync::mpsc};
use serai_db::MemDb;
@@ -81,7 +81,16 @@ async fn dkg_test() {
) -> (TributaryDb<MemDb>, MemProcessor) {
let mut scanner_db = TributaryDb(MemDb::new());
let processor = MemProcessor::new();
handle_new_blocks(&mut scanner_db, key, &processor, spec, &tributary.reader()).await;
// Uses a brand new channel since this channel won't be used within this test
handle_new_blocks(
&mut scanner_db,
key,
&mpsc::unbounded_channel().0,
&processor,
spec,
&tributary.reader(),
)
.await;
(scanner_db, processor)
}
@@ -96,7 +105,15 @@ async fn dkg_test() {
sleep(Duration::from_secs(Tributary::<MemDb, Transaction, LocalP2p>::block_time().into())).await;
// Verify the scanner emits a KeyGen::Commitments message
handle_new_blocks(&mut scanner_db, &keys[0], &processor, &spec, &tributaries[0].1.reader()).await;
handle_new_blocks(
&mut scanner_db,
&keys[0],
&mpsc::unbounded_channel().0,
&processor,
&spec,
&tributaries[0].1.reader(),
)
.await;
{
let mut msgs = processor.0.write().await;
assert_eq!(msgs.pop_front().unwrap(), expected_commitments);
@@ -137,7 +154,15 @@ async fn dkg_test() {
}
// With just 4 sets of shares, nothing should happen yet
handle_new_blocks(&mut scanner_db, &keys[0], &processor, &spec, &tributaries[0].1.reader()).await;
handle_new_blocks(
&mut scanner_db,
&keys[0],
&mpsc::unbounded_channel().0,
&processor,
&spec,
&tributaries[0].1.reader(),
)
.await;
assert!(processor.0.write().await.is_empty());
// Publish the final set of shares
@@ -168,7 +193,15 @@ async fn dkg_test() {
};
// Any scanner which has handled the prior blocks should only emit the new event
handle_new_blocks(&mut scanner_db, &keys[0], &processor, &spec, &tributaries[0].1.reader()).await;
handle_new_blocks(
&mut scanner_db,
&keys[0],
&mpsc::unbounded_channel().0,
&processor,
&spec,
&tributaries[0].1.reader(),
)
.await;
{
let mut msgs = processor.0.write().await;
assert_eq!(msgs.pop_front().unwrap(), shares_for(0));