Initial Tributary handling

This commit is contained in:
Luke Parker
2023-04-20 05:05:17 -04:00
parent 9e1f3fc85c
commit 8041a0d845
9 changed files with 413 additions and 42 deletions

View File

@@ -1,8 +1,9 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unreachable_code)]
#![allow(clippy::diverging_sub_expression)]
use std::time::Duration;
use std::{time::Duration, collections::HashMap};
use zeroize::Zeroizing;
@@ -13,10 +14,7 @@ use serai_client::Serai;
use tokio::time::sleep;
mod db;
pub use db::*;
pub mod tributary;
mod tributary;
mod p2p;
pub use p2p::*;
@@ -30,42 +28,63 @@ mod substrate;
mod tests;
async fn run<D: Db, Pro: Processor, P: P2p>(
db: D,
raw_db: D,
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
p2p: P,
mut processor: Pro,
serai: Serai,
) {
let mut db = MainDb::new(db);
let mut substrate_db = substrate::SubstrateDb::new(raw_db.clone());
let mut last_substrate_block = substrate_db.last_block();
let mut last_tributary_block = HashMap::<[u8; 32], _>::new();
let mut last_substrate_block = db.last_substrate_block();
tokio::spawn(async move {
loop {
match substrate::handle_new_blocks(
&mut db,
&key,
&p2p,
&mut processor,
&serai,
&mut last_substrate_block,
)
.await
{
Ok(()) => {}
Err(e) => {
log::error!("couldn't communicate with serai node: {e}");
sleep(Duration::from_secs(5)).await;
{
let key = key.clone();
let mut processor = processor.clone();
tokio::spawn(async move {
loop {
match substrate::handle_new_blocks(
&mut substrate_db,
&key,
&p2p,
&mut processor,
&serai,
&mut last_substrate_block,
)
.await
{
Ok(()) => sleep(Duration::from_secs(3)).await,
Err(e) => {
log::error!("couldn't communicate with serai node: {e}");
sleep(Duration::from_secs(5)).await;
}
}
}
}
});
});
}
{
let mut tributary_db = tributary::TributaryDb::new(raw_db);
tokio::spawn(async move {
loop {
for (_, last_block) in last_tributary_block.iter_mut() {
tributary::scanner::handle_new_blocks::<_, _, P>(
&mut tributary_db,
&key,
&mut processor,
todo!(),
todo!(),
last_block,
)
.await;
}
sleep(Duration::from_secs(3)).await;
}
});
}
loop {
// Handle all messages from tributaries
// Handle all messages from processors
todo!()
}
}