mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +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:
@@ -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