SlashReport signing and signature publication

This commit is contained in:
Luke Parker
2024-09-09 04:18:54 -04:00
parent 3cc7b49492
commit 46c12c0e66
8 changed files with 200 additions and 34 deletions

View File

@@ -1,14 +1,9 @@
use scale::Decode;
use serai_db::{DbTxn, Db};
use primitives::task::ContinuallyRan;
use crate::{
db::{
RegisteredKeys, CosignerToCoordinatorMessages, BatchSignerToCoordinatorMessages,
SlashReportSignerToCoordinatorMessages, TransactionSignerToCoordinatorMessages,
},
Coordinator,
};
use crate::{db::*, Coordinator};
mod db;
@@ -30,6 +25,7 @@ impl<D: Db, C: Coordinator> ContinuallyRan for CoordinatorTask<D, C> {
let mut iterated = false;
for session in RegisteredKeys::get(&self.db).unwrap_or(vec![]) {
// Publish the messages generated by this key's signers
loop {
let mut txn = self.db.txn();
let Some(msg) = CosignerToCoordinatorMessages::try_recv(&mut txn, session) else {
@@ -93,6 +89,26 @@ impl<D: Db, C: Coordinator> ContinuallyRan for CoordinatorTask<D, C> {
txn.commit();
}
// If this session signed its slash report, publish its signature
{
let mut txn = self.db.txn();
if let Some(slash_report_signature) = SlashReportSignature::try_recv(&mut txn, session) {
iterated = true;
self
.coordinator
.publish_slash_report_signature(
<_>::decode(&mut slash_report_signature.as_slice()).unwrap(),
)
.await
.map_err(|e| {
format!("couldn't send slash report signature to the coordinator: {e:?}")
})?;
txn.commit();
}
}
}
// Publish the Batches