mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Route the coordinator, fix race conditions in the signers library
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use core::marker::PhantomData;
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
use group::GroupEncoding;
|
||||
use scale::{Encode, Decode, IoReader};
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
use serai_db::{Get, DbTxn, create_db, db_channel};
|
||||
@@ -526,20 +527,20 @@ mod _completed_eventualities {
|
||||
|
||||
db_channel! {
|
||||
ScannerPublic {
|
||||
CompletedEventualities: (empty_key: ()) -> [u8; 32],
|
||||
CompletedEventualities: (key: &[u8]) -> [u8; 32],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The IDs of completed Eventualities found on-chain, within a finalized block.
|
||||
pub struct CompletedEventualities<S: ScannerFeed>(PhantomData<S>);
|
||||
impl<S: ScannerFeed> CompletedEventualities<S> {
|
||||
pub(crate) fn send(txn: &mut impl DbTxn, id: [u8; 32]) {
|
||||
_completed_eventualities::CompletedEventualities::send(txn, (), &id);
|
||||
pub struct CompletedEventualities<K: GroupEncoding>(PhantomData<K>);
|
||||
impl<K: GroupEncoding> CompletedEventualities<K> {
|
||||
pub(crate) fn send(txn: &mut impl DbTxn, key: &K, id: [u8; 32]) {
|
||||
_completed_eventualities::CompletedEventualities::send(txn, key.to_bytes().as_ref(), &id);
|
||||
}
|
||||
|
||||
/// Receive the ID of a completed Eventuality.
|
||||
pub fn try_recv(txn: &mut impl DbTxn) -> Option<[u8; 32]> {
|
||||
_completed_eventualities::CompletedEventualities::try_recv(txn, ())
|
||||
pub fn try_recv(txn: &mut impl DbTxn, key: &K) -> Option<[u8; 32]> {
|
||||
_completed_eventualities::CompletedEventualities::try_recv(txn, key.to_bytes().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ impl<D: Db, S: ScannerFeed, Sch: Scheduler<S>> ContinuallyRan for EventualityTas
|
||||
hex::encode(eventuality.id()),
|
||||
hex::encode(tx.as_ref())
|
||||
);
|
||||
CompletedEventualities::<S>::send(&mut txn, eventuality.id());
|
||||
CompletedEventualities::send(&mut txn, &key.key, eventuality.id());
|
||||
}
|
||||
|
||||
// Fetch all non-External outputs
|
||||
|
||||
@@ -362,24 +362,24 @@ impl<S: ScannerFeed> Scanner<S> {
|
||||
let substrate_task = substrate::SubstrateTask::<_, S>::new(db.clone());
|
||||
let eventuality_task = eventuality::EventualityTask::<_, _, Sch>::new(db, feed, start_block);
|
||||
|
||||
let (index_run, _index_handle) = Task::new();
|
||||
let (scan_run, scan_handle) = Task::new();
|
||||
let (report_run, report_handle) = Task::new();
|
||||
let (substrate_run, substrate_handle) = Task::new();
|
||||
let (eventuality_run, eventuality_handle) = Task::new();
|
||||
let (index_task_def, _index_handle) = Task::new();
|
||||
let (scan_task_def, scan_handle) = Task::new();
|
||||
let (report_task_def, report_handle) = Task::new();
|
||||
let (substrate_task_def, substrate_handle) = Task::new();
|
||||
let (eventuality_task_def, eventuality_handle) = Task::new();
|
||||
|
||||
// Upon indexing a new block, scan it
|
||||
tokio::spawn(index_task.continually_run(index_run, vec![scan_handle.clone()]));
|
||||
tokio::spawn(index_task.continually_run(index_task_def, vec![scan_handle.clone()]));
|
||||
// Upon scanning a block, report it
|
||||
tokio::spawn(scan_task.continually_run(scan_run, vec![report_handle]));
|
||||
tokio::spawn(scan_task.continually_run(scan_task_def, vec![report_handle]));
|
||||
// Upon reporting a block, we do nothing (as the burden is on Substrate which won't be
|
||||
// immediately ready)
|
||||
tokio::spawn(report_task.continually_run(report_run, vec![]));
|
||||
tokio::spawn(report_task.continually_run(report_task_def, vec![]));
|
||||
// Upon handling an event from Substrate, we run the Eventuality task (as it's what's affected)
|
||||
tokio::spawn(substrate_task.continually_run(substrate_run, vec![eventuality_handle]));
|
||||
tokio::spawn(substrate_task.continually_run(substrate_task_def, vec![eventuality_handle]));
|
||||
// Upon handling the Eventualities in a block, we run the scan task as we've advanced the
|
||||
// window its allowed to scan
|
||||
tokio::spawn(eventuality_task.continually_run(eventuality_run, vec![scan_handle]));
|
||||
tokio::spawn(eventuality_task.continually_run(eventuality_task_def, vec![scan_handle]));
|
||||
|
||||
Self { substrate_handle, _S: PhantomData }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user