mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Handle signing batches in the processor
Duplicates the existing signer for one tailored to batch signing.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use core::{marker::PhantomData, time::Duration};
|
||||
use core::marker::PhantomData;
|
||||
use std::{
|
||||
sync::Arc,
|
||||
time::{SystemTime, Duration},
|
||||
collections::{HashSet, HashMap},
|
||||
};
|
||||
|
||||
@@ -20,8 +21,8 @@ use crate::{
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ScannerEvent<C: Coin> {
|
||||
// Outputs received
|
||||
Outputs(<C::Curve as Ciphersuite>::G, <C::Block as Block<C>>::Id, Vec<C::Output>),
|
||||
// Block scanned
|
||||
Block(<C::Curve as Ciphersuite>::G, <C::Block as Block<C>>::Id, SystemTime, Vec<C::Output>),
|
||||
}
|
||||
|
||||
pub type ScannerEventChannel<C> = mpsc::UnboundedReceiver<ScannerEvent<C>>;
|
||||
@@ -395,7 +396,6 @@ impl<C: Coin, D: Db> Scanner<C, D> {
|
||||
scanner.ram_outputs.insert(id);
|
||||
}
|
||||
|
||||
// TODO: Still fire an empty Outputs event if we haven't had inputs in a while
|
||||
if outputs.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -405,8 +405,47 @@ impl<C: Coin, D: Db> Scanner<C, D> {
|
||||
scanner.db.save_outputs(&mut txn, &key, &block_id, &outputs);
|
||||
txn.commit();
|
||||
|
||||
const TIME_TOLERANCE: u64 = 15;
|
||||
|
||||
let now = SystemTime::now();
|
||||
let mut time = block.time();
|
||||
|
||||
// Block is older than the tolerance
|
||||
// This isn't an issue, yet shows our daemon may have fallen behind/been disconnected
|
||||
if now.duration_since(time).unwrap_or(Duration::ZERO) >
|
||||
Duration::from_secs(TIME_TOLERANCE)
|
||||
{
|
||||
warn!(
|
||||
"the time is {} and we only just received a block dated {}",
|
||||
(now.duration_since(SystemTime::UNIX_EPOCH)).expect("now before epoch").as_secs(),
|
||||
(time.duration_since(SystemTime::UNIX_EPOCH))
|
||||
.expect("block time before epoch")
|
||||
.as_secs(),
|
||||
);
|
||||
}
|
||||
|
||||
// If this block is in the future, either this server's clock is wrong OR the block's
|
||||
// miner's clock is wrong. The latter is the problem
|
||||
//
|
||||
// This time is used to schedule signing sessions over the content of this block
|
||||
// If it's in the future, the first attempt won't time out until this block is no
|
||||
// longer in the future
|
||||
//
|
||||
// Since we don't need consensus, if this time is more than 15s in the future,
|
||||
// set it to the local time
|
||||
//
|
||||
// As long as a supermajority of nodes set a time within ~15s of each other, this
|
||||
// should be fine
|
||||
|
||||
// TODO2: Make more robust
|
||||
if time.duration_since(now).unwrap_or(Duration::ZERO) >
|
||||
Duration::from_secs(TIME_TOLERANCE)
|
||||
{
|
||||
time = now;
|
||||
}
|
||||
|
||||
// Send all outputs
|
||||
if !scanner.emit(ScannerEvent::Outputs(key, block_id, outputs)) {
|
||||
if !scanner.emit(ScannerEvent::Block(key, block_id, time, outputs)) {
|
||||
return;
|
||||
}
|
||||
// Write this number as scanned so we won't re-fire these outputs
|
||||
|
||||
Reference in New Issue
Block a user