Have the coordinator task publish Batches

This commit is contained in:
Luke Parker 2024-09-09 01:15:56 -04:00
parent ed0221d804
commit a3cb514400
6 changed files with 41 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use serai_in_instructions_primitives::{Batch, SignedBatch};
use serai_db::{Get, DbTxn, create_db}; use serai_db::{Get, DbTxn, create_db};
create_db! { create_db! {
BatchSigner { SignersBatch {
ActiveSigningProtocols: (session: Session) -> Vec<u32>, ActiveSigningProtocols: (session: Session) -> Vec<u32>,
Batches: (id: u32) -> Batch, Batches: (id: u32) -> Batch,
SignedBatches: (id: u32) -> SignedBatch, SignedBatches: (id: u32) -> SignedBatch,

View file

@ -6,7 +6,7 @@ use frost::dkg::ThresholdKeys;
use serai_validator_sets_primitives::Session; use serai_validator_sets_primitives::Session;
use serai_in_instructions_primitives::{SignedBatch, batch_message}; use serai_in_instructions_primitives::{SignedBatch, batch_message};
use serai_db::{DbTxn, Db}; use serai_db::{Get, DbTxn, Db};
use messages::sign::VariantSignId; use messages::sign::VariantSignId;
@ -23,6 +23,14 @@ use crate::{
mod db; mod db;
use db::*; use db::*;
pub(crate) fn last_acknowledged_batch(getter: &impl Get) -> Option<u32> {
LastAcknowledgedBatch::get(getter)
}
pub(crate) fn signed_batch(getter: &impl Get, id: u32) -> Option<SignedBatch> {
SignedBatches::get(getter, id)
}
// Fetches batches to sign and signs them. // Fetches batches to sign and signs them.
pub(crate) struct BatchSignerTask<D: Db, E: GroupEncoding> { pub(crate) struct BatchSignerTask<D: Db, E: GroupEncoding> {
db: D, db: D,

View file

@ -0,0 +1,7 @@
use serai_db::{Get, DbTxn, create_db};
create_db! {
SignersCoordinator {
LastPublishedBatch: () -> u32,
}
}

View file

@ -10,6 +10,8 @@ use crate::{
Coordinator, Coordinator,
}; };
mod db;
// Fetches messages to send the coordinator and sends them. // Fetches messages to send the coordinator and sends them.
pub(crate) struct CoordinatorTask<D: Db, C: Coordinator> { pub(crate) struct CoordinatorTask<D: Db, C: Coordinator> {
db: D, db: D,
@ -93,7 +95,26 @@ impl<D: Db, C: Coordinator> ContinuallyRan for CoordinatorTask<D, C> {
} }
} }
// TODO: For max(last acknowledged batch, last published batch) onwards, publish every batch // Publish the signed Batches
{
let mut txn = self.db.txn();
// The last acknowledged Batch may exceed the last Batch we published if we didn't sign for
// the prior Batch(es) (and accordingly didn't publish them)
let last_batch =
crate::batch::last_acknowledged_batch(&txn).max(db::LastPublishedBatch::get(&txn));
let mut next_batch = last_batch.map_or(0, |id| id + 1);
while let Some(batch) = crate::batch::signed_batch(&txn, next_batch) {
iterated = true;
db::LastPublishedBatch::set(&mut txn, &batch.batch.id);
self
.coordinator
.publish_batch(batch)
.await
.map_err(|e| format!("couldn't publish Batch: {e:?}"))?;
next_batch += 1;
}
txn.commit();
}
Ok(iterated) Ok(iterated)
} }

View file

@ -169,7 +169,7 @@ impl<ST: SignableTransaction> Signers<ST> {
.push(ThresholdKeys::from(ThresholdCore::<ST::Ciphersuite>::read(&mut buf).unwrap())); .push(ThresholdKeys::from(ThresholdCore::<ST::Ciphersuite>::read(&mut buf).unwrap()));
} }
// TODO: Batch signer, cosigner, slash report signers // TODO: Cosigner and slash report signers
let (batch_task, batch_handle) = Task::new(); let (batch_task, batch_handle) = Task::new();
tokio::spawn( tokio::spawn(

View file

@ -3,7 +3,7 @@ use serai_validator_sets_primitives::Session;
use serai_db::{Get, DbTxn, create_db}; use serai_db::{Get, DbTxn, create_db};
create_db! { create_db! {
TransactionSigner { SignersTransaction {
ActiveSigningProtocols: (session: Session) -> Vec<[u8; 32]>, ActiveSigningProtocols: (session: Session) -> Vec<[u8; 32]>,
SerializedSignableTransactions: (id: [u8; 32]) -> Vec<u8>, SerializedSignableTransactions: (id: [u8; 32]) -> Vec<u8>,
SerializedTransactions: (id: [u8; 32]) -> Vec<u8>, SerializedTransactions: (id: [u8; 32]) -> Vec<u8>,