diff --git a/processor/frost-attempt-manager/src/individual.rs b/processor/frost-attempt-manager/src/individual.rs index 6a8b3352..e918ff02 100644 --- a/processor/frost-attempt-manager/src/individual.rs +++ b/processor/frost-attempt-manager/src/individual.rs @@ -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 SigningProtocol { */ { 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 SigningProtocol { } /// 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); } } diff --git a/processor/frost-attempt-manager/src/lib.rs b/processor/frost-attempt-manager/src/lib.rs index db8b0861..670d8d9f 100644 --- a/processor/frost-attempt-manager/src/lib.rs +++ b/processor/frost-attempt-manager/src/lib.rs @@ -45,7 +45,7 @@ impl AttemptManager { /// 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) -> Vec { let mut protocol = SigningProtocol::new(self.db.clone(), self.session, self.start_i, id, machines); @@ -66,7 +66,7 @@ impl AttemptManager { } else { log::info!("retired signing protocol {id:?}"); } - SigningProtocol::::cleanup(txn, id); + SigningProtocol::::cleanup(txn, self.session, id); } /// Handle a message for a signing protocol. diff --git a/processor/messages/src/lib.rs b/processor/messages/src/lib.rs index 659491d4..748cf39b 100644 --- a/processor/messages/src/lib.rs +++ b/processor/messages/src/lib.rs @@ -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, + pub publisher: Session, + pub in_instructions_hash: [u8; 32], + pub in_instruction_results: Vec, } #[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 { diff --git a/processor/signers/src/lib.rs b/processor/signers/src/lib.rs index a6714fdf..d247cf8f 100644 --- a/processor/signers/src/lib.rs +++ b/processor/signers/src/lib.rs @@ -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, ) { + // 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(); diff --git a/processor/signers/src/slash_report.rs b/processor/signers/src/slash_report.rs index e040798c..577ec90b 100644 --- a/processor/signers/src/slash_report.rs +++ b/processor/signers/src/slash_report.rs @@ -79,8 +79,7 @@ impl ContinuallyRan for SlashReportSignerTask { } } 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 ContinuallyRan for SlashReportSignerTask { } } 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(), + ); } }