mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Strongly type SlashReport, populate cosign/slash report tasks with work
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use serai_validator_sets_primitives::Session;
|
||||
use serai_validator_sets_primitives::{Session, Slash};
|
||||
|
||||
use serai_db::{Get, DbTxn, create_db, db_channel};
|
||||
|
||||
@@ -15,6 +15,9 @@ create_db! {
|
||||
|
||||
db_channel! {
|
||||
SignersGlobal {
|
||||
Cosign: (session: Session) -> (u64, [u8; 32]),
|
||||
SlashReport: (session: Session) -> Vec<Slash>,
|
||||
|
||||
CoordinatorToCosignerMessages: (session: Session) -> CoordinatorMessage,
|
||||
CosignerToCoordinatorMessages: (session: Session) -> ProcessorMessage,
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use zeroize::Zeroizing;
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
||||
use frost::dkg::{ThresholdCore, ThresholdKeys};
|
||||
|
||||
use serai_validator_sets_primitives::Session;
|
||||
use serai_validator_sets_primitives::{Session, Slash};
|
||||
use serai_in_instructions_primitives::SignedBatch;
|
||||
|
||||
use serai_db::{DbTxn, Db};
|
||||
@@ -139,6 +139,8 @@ impl<ST: SignableTransaction> Signers<ST> {
|
||||
while scanner::CompletedEventualities::try_recv(&mut txn, &external_key).is_some() {}
|
||||
|
||||
// Drain our DB channels
|
||||
while db::Cosign::try_recv(&mut txn, session).is_some() {}
|
||||
while db::SlashReport::try_recv(&mut txn, session).is_some() {}
|
||||
while db::CoordinatorToCosignerMessages::try_recv(&mut txn, session).is_some() {}
|
||||
while db::CosignerToCoordinatorMessages::try_recv(&mut txn, session).is_some() {}
|
||||
while db::CoordinatorToBatchSignerMessages::try_recv(&mut txn, session).is_some() {}
|
||||
@@ -276,7 +278,7 @@ impl<ST: SignableTransaction> Signers<ST> {
|
||||
|
||||
/// Queue handling a message.
|
||||
///
|
||||
/// This is a cheap call and able to be done inline with a higher-level loop.
|
||||
/// This is a cheap call and able to be done inline from a higher-level loop.
|
||||
pub fn queue_message(&mut self, txn: &mut impl DbTxn, message: &CoordinatorMessage) {
|
||||
let sign_id = message.sign_id();
|
||||
let tasks = self.tasks.get(&sign_id.session);
|
||||
@@ -307,4 +309,39 @@ impl<ST: SignableTransaction> Signers<ST> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Cosign a block.
|
||||
///
|
||||
/// This is a cheap call and able to be done inline from a higher-level loop.
|
||||
pub fn cosign_block(
|
||||
&mut self,
|
||||
mut txn: impl DbTxn,
|
||||
session: Session,
|
||||
block_number: u64,
|
||||
block: [u8; 32],
|
||||
) {
|
||||
db::Cosign::send(&mut txn, session, &(block_number, block));
|
||||
txn.commit();
|
||||
|
||||
if let Some(tasks) = self.tasks.get(&session) {
|
||||
tasks.cosign.run_now();
|
||||
}
|
||||
}
|
||||
|
||||
/// Sign a slash report.
|
||||
///
|
||||
/// This is a cheap call and able to be done inline from a higher-level loop.
|
||||
pub fn sign_slash_report(
|
||||
&mut self,
|
||||
mut txn: impl DbTxn,
|
||||
session: Session,
|
||||
slash_report: Vec<Slash>,
|
||||
) {
|
||||
db::SlashReport::send(&mut txn, session, &slash_report);
|
||||
txn.commit();
|
||||
|
||||
if let Some(tasks) = self.tasks.get(&session) {
|
||||
tasks.slash_report.run_now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user