Reload Tributaries

add_active_tributary writes the spec to disk before it returns, so even if the
VecDeque it pushes to isn't popped, the tributary will still be loaded on boot.
This commit is contained in:
Luke Parker
2023-04-23 04:31:00 -04:00
parent 2b09309adc
commit f2d9d70068
5 changed files with 130 additions and 15 deletions

View File

@@ -23,6 +23,9 @@ use ::tributary::Tributary;
mod tributary;
use crate::tributary::{TributarySpec, Transaction};
mod db;
use db::MainDb;
mod p2p;
pub use p2p::*;
@@ -48,9 +51,9 @@ async fn run<D: Db, Pro: Processor, P: P2p>(
mut processor: Pro,
serai: Serai,
) {
let add_new_tributary = |spec: TributarySpec| async {
let add_new_tributary = |db, spec: TributarySpec| async {
MainDb(db).add_active_tributary(&spec);
NEW_TRIBUTARIES.write().await.push_back(spec);
// TODO: Save this tributary's information to the databae before returning
};
{
@@ -92,6 +95,7 @@ async fn run<D: Db, Pro: Processor, P: P2p>(
let mut tributaries = HashMap::<[u8; 32], ActiveTributary<D, P>>::new();
// TODO: Use a db on a distinct volume
async fn add_tributary<D: Db, P: P2p>(
db: D,
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
@@ -113,7 +117,10 @@ async fn run<D: Db, Pro: Processor, P: P2p>(
tributaries.insert(tributary.genesis(), ActiveTributary { spec, tributary });
}
// TODO: Reload tributaries
// TODO: Can MainDb take a borrow?
for spec in MainDb(raw_db.clone()).active_tributaries().1 {
add_tributary(raw_db.clone(), key.clone(), p2p.clone(), &mut tributaries, spec).await;
}
let mut tributary_db = tributary::TributaryDb::new(raw_db.clone());
tokio::spawn(async move {
@@ -130,7 +137,7 @@ async fn run<D: Db, Pro: Processor, P: P2p>(
}
}
for (genesis, ActiveTributary { spec, tributary }) in tributaries.iter_mut() {
for ActiveTributary { spec, tributary } in tributaries.values() {
tributary::scanner::handle_new_blocks::<_, _, P>(
&mut tributary_db,
&key,