Add a next block notification system to Tributary

Also adds a loop missing from the prior commit.
This commit is contained in:
Luke Parker
2023-09-25 23:11:36 -04:00
parent 7312428a44
commit 2508633de9
4 changed files with 116 additions and 91 deletions

View File

@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{VecDeque, HashMap};
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
@@ -13,7 +13,7 @@ use crate::{
transaction::{Signed, TransactionKind, Transaction as TransactionTrait},
};
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Debug)]
pub(crate) struct Blockchain<D: Db, T: TransactionTrait> {
db: Option<D>,
genesis: [u8; 32],
@@ -24,6 +24,8 @@ pub(crate) struct Blockchain<D: Db, T: TransactionTrait> {
provided: ProvidedTransactions<D, T>,
mempool: Mempool<D, T>,
pub(crate) next_block_notifications: VecDeque<tokio::sync::oneshot::Sender<()>>,
}
impl<D: Db, T: TransactionTrait> Blockchain<D, T> {
@@ -76,6 +78,8 @@ impl<D: Db, T: TransactionTrait> Blockchain<D, T> {
provided: ProvidedTransactions::new(db.clone(), genesis),
mempool: Mempool::new(db, genesis),
next_block_notifications: VecDeque::new(),
};
if let Some((block_number, tip)) = {
@@ -274,6 +278,10 @@ impl<D: Db, T: TransactionTrait> Blockchain<D, T> {
txn.commit();
self.db = Some(db);
for tx in self.next_block_notifications.drain(..) {
let _ = tx.send(());
}
Ok(())
}
}