mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 20:59:23 +00:00
Add a next block notification system to Tributary
Also adds a loop missing from the prior commit.
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user