mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Remove Session from VariantSignId::SlashReport
It's only there to make the VariantSignid unique across Sessions. By localizing the VariantSignid to a Session, we avoid this, and can better ensure we don't queue work for historic sessions.
This commit is contained in:
@@ -14,7 +14,7 @@ use messages::sign::{VariantSignId, SignId, ProcessorMessage};
|
||||
|
||||
create_db!(
|
||||
FrostAttemptManager {
|
||||
Attempted: (id: VariantSignId) -> u32,
|
||||
Attempted: (session: Session, id: VariantSignId) -> u32,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -92,11 +92,11 @@ impl<D: Db, M: Clone + PreprocessMachine> SigningProtocol<D, M> {
|
||||
*/
|
||||
{
|
||||
let mut txn = self.db.txn();
|
||||
let prior_attempted = Attempted::get(&txn, self.id);
|
||||
let prior_attempted = Attempted::get(&txn, self.session, self.id);
|
||||
if Some(attempt) <= prior_attempted {
|
||||
return vec![];
|
||||
}
|
||||
Attempted::set(&mut txn, self.id, &attempt);
|
||||
Attempted::set(&mut txn, self.session, self.id, &attempt);
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ impl<D: Db, M: Clone + PreprocessMachine> SigningProtocol<D, M> {
|
||||
}
|
||||
|
||||
/// Cleanup the database entries for a specified signing protocol.
|
||||
pub(crate) fn cleanup(txn: &mut impl DbTxn, id: VariantSignId) {
|
||||
Attempted::del(txn, id);
|
||||
pub(crate) fn cleanup(txn: &mut impl DbTxn, session: Session, id: VariantSignId) {
|
||||
Attempted::del(txn, session, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<D: Db, M: Clone + PreprocessMachine> AttemptManager<D, M> {
|
||||
|
||||
/// Register a signing protocol to attempt.
|
||||
///
|
||||
/// This ID must be unique across all sessions, attempt managers, protocols, etc.
|
||||
/// This ID must be unique to the session, across all attempt managers, protocols, etc.
|
||||
pub fn register(&mut self, id: VariantSignId, machines: Vec<M>) -> Vec<ProcessorMessage> {
|
||||
let mut protocol =
|
||||
SigningProtocol::new(self.db.clone(), self.session, self.start_i, id, machines);
|
||||
@@ -66,7 +66,7 @@ impl<D: Db, M: Clone + PreprocessMachine> AttemptManager<D, M> {
|
||||
} else {
|
||||
log::info!("retired signing protocol {id:?}");
|
||||
}
|
||||
SigningProtocol::<D, M>::cleanup(txn, id);
|
||||
SigningProtocol::<D, M>::cleanup(txn, self.session, id);
|
||||
}
|
||||
|
||||
/// Handle a message for a signing protocol.
|
||||
|
||||
@@ -84,7 +84,7 @@ pub mod sign {
|
||||
pub enum VariantSignId {
|
||||
Cosign(u64),
|
||||
Batch(u32),
|
||||
SlashReport(Session),
|
||||
SlashReport,
|
||||
Transaction([u8; 32]),
|
||||
}
|
||||
impl fmt::Debug for VariantSignId {
|
||||
@@ -94,9 +94,7 @@ pub mod sign {
|
||||
f.debug_struct("VariantSignId::Cosign").field("0", &cosign).finish()
|
||||
}
|
||||
Self::Batch(batch) => f.debug_struct("VariantSignId::Batch").field("0", &batch).finish(),
|
||||
Self::SlashReport(session) => {
|
||||
f.debug_struct("VariantSignId::SlashReport").field("0", &session).finish()
|
||||
}
|
||||
Self::SlashReport => f.debug_struct("VariantSignId::SlashReport").finish(),
|
||||
Self::Transaction(tx) => {
|
||||
f.debug_struct("VariantSignId::Transaction").field("0", &hex::encode(tx)).finish()
|
||||
}
|
||||
@@ -189,7 +187,9 @@ pub mod substrate {
|
||||
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
|
||||
pub struct ExecutedBatch {
|
||||
pub id: u32,
|
||||
pub in_instructions: Vec<InInstructionResult>,
|
||||
pub publisher: Session,
|
||||
pub in_instructions_hash: [u8; 32],
|
||||
pub in_instruction_results: Vec<InInstructionResult>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
|
||||
@@ -197,6 +197,8 @@ pub mod substrate {
|
||||
/// Keys set on the Serai blockchain.
|
||||
SetKeys { serai_time: u64, session: Session, key_pair: KeyPair },
|
||||
/// Slashes reported on the Serai blockchain OR the process timed out.
|
||||
///
|
||||
/// This is the final message for a session,
|
||||
SlashesReported { session: Session },
|
||||
/// A block from Serai with relevance to this processor.
|
||||
Block {
|
||||
|
||||
@@ -376,6 +376,12 @@ impl<
|
||||
/// 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();
|
||||
|
||||
// Don't queue messages for already retired keys
|
||||
if Some(sign_id.session.0) <= db::LatestRetiredSession::get(txn).map(|session| session.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let tasks = self.tasks.get(&sign_id.session);
|
||||
match sign_id.id {
|
||||
VariantSignId::Cosign(_) => {
|
||||
@@ -390,7 +396,7 @@ impl<
|
||||
tasks.batch.run_now();
|
||||
}
|
||||
}
|
||||
VariantSignId::SlashReport(_) => {
|
||||
VariantSignId::SlashReport => {
|
||||
db::CoordinatorToSlashReportSignerMessages::send(txn, sign_id.session, message);
|
||||
if let Some(tasks) = tasks {
|
||||
tasks.slash_report.run_now();
|
||||
@@ -415,6 +421,11 @@ impl<
|
||||
block_number: u64,
|
||||
block: [u8; 32],
|
||||
) {
|
||||
// Don't cosign blocks with already retired keys
|
||||
if Some(session.0) <= db::LatestRetiredSession::get(txn).map(|session| session.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
db::ToCosign::set(&mut txn, session, &(block_number, block));
|
||||
txn.commit();
|
||||
|
||||
@@ -432,6 +443,11 @@ impl<
|
||||
session: Session,
|
||||
slash_report: &Vec<Slash>,
|
||||
) {
|
||||
// Don't sign slash reports with already retired keys
|
||||
if Some(session.0) <= db::LatestRetiredSession::get(txn).map(|session| session.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
db::SlashReport::send(&mut txn, session, slash_report);
|
||||
txn.commit();
|
||||
|
||||
|
||||
@@ -79,8 +79,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SlashReportSignerTask<D, S> {
|
||||
}
|
||||
}
|
||||
let mut txn = self.db.txn();
|
||||
for msg in self.attempt_manager.register(VariantSignId::SlashReport(self.session), machines)
|
||||
{
|
||||
for msg in self.attempt_manager.register(VariantSignId::SlashReport, machines) {
|
||||
SlashReportSignerToCoordinatorMessages::send(&mut txn, self.session, &msg);
|
||||
}
|
||||
txn.commit();
|
||||
@@ -102,14 +101,15 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SlashReportSignerTask<D, S> {
|
||||
}
|
||||
}
|
||||
Response::Signature { id, signature } => {
|
||||
let VariantSignId::SlashReport(session) = id else {
|
||||
panic!("SlashReportSignerTask signed a non-SlashReport")
|
||||
};
|
||||
assert_eq!(session, self.session);
|
||||
assert_eq!(id, VariantSignId::SlashReport);
|
||||
// Drain the channel
|
||||
SlashReport::try_recv(&mut txn, self.session).unwrap();
|
||||
// Send the signature
|
||||
SlashReportSignature::send(&mut txn, session, &Signature::from(signature).encode());
|
||||
SlashReportSignature::send(
|
||||
&mut txn,
|
||||
self.session,
|
||||
&Signature::from(signature).encode(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user