Minor work on the transaction signing task

This commit is contained in:
Luke Parker
2024-09-05 14:42:06 -04:00
parent 8380653855
commit b62fc3a1fa
14 changed files with 169 additions and 2 deletions

View File

@@ -20,3 +20,13 @@ ignored = ["borsh", "scale"]
workspace = true
[dependencies]
group = { version = "0.13", default-features = false }
log = { version = "0.4", default-features = false, features = ["std"] }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "sync", "time", "macros"] }
primitives = { package = "serai-processor-primitives", path = "../primitives" }
scanner = { package = "serai-processor-scanner", path = "../scanner" }
scheduler = { package = "serai-scheduler-primitives", path = "../scheduler/primitives" }
frost-attempt-manager = { package = "serai-processor-frost-attempt-manager", path = "../frost-attempt-manager" }

View File

@@ -0,0 +1,56 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
mod transaction;
/*
// The signers used by a Processor, key-scoped.
struct KeySigners<D: Db, T: Clone + PreprocessMachine> {
transaction: AttemptManager<D, T>,
substrate: AttemptManager<D, AlgorithmMachine<Ristretto, Schnorrkel>>,
cosigner: AttemptManager<D, AlgorithmMachine<Ristretto, Schnorrkel>>,
}
/// The signers used by a protocol.
pub struct Signers<D: Db, T: Clone + PreprocessMachine>(HashMap<Vec<u8>, KeySigners<D, T>>);
impl<D: Db, T: Clone + PreprocessMachine> Signers<D, T> {
/// Create a new set of signers.
pub fn new(db: D) -> Self {
// TODO: Load the registered keys
// TODO: Load the transactions being signed
// TODO: Load the batches being signed
todo!("TODO")
}
/// Register a transaction to sign.
pub fn sign_transaction(&mut self) -> Vec<ProcessorMessage> {
todo!("TODO")
}
/// Mark a transaction as signed.
pub fn signed_transaction(&mut self) { todo!("TODO") }
/// Register a batch to sign.
pub fn sign_batch(&mut self, key: KeyFor<S>, batch: Batch) -> Vec<ProcessorMessage> {
todo!("TODO")
}
/// Mark a batch as signed.
pub fn signed_batch(&mut self, batch: u32) { todo!("TODO") }
/// Register a slash report to sign.
pub fn sign_slash_report(&mut self) -> Vec<ProcessorMessage> {
todo!("TODO")
}
/// Mark a slash report as signed.
pub fn signed_slash_report(&mut self) { todo!("TODO") }
/// Start a cosigning protocol.
pub fn cosign(&mut self) { todo!("TODO") }
/// Handle a message for a signing protocol.
pub fn handle(&mut self, msg: CoordinatorMessage) -> Vec<ProcessorMessage> {
todo!("TODO")
}
}
*/

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,70 @@
use serai_db::{Get, DbTxn, Db};
use primitives::task::ContinuallyRan;
use scanner::ScannerFeed;
use scheduler::TransactionsToSign;
mod db;
use db::IndexDb;
// Fetches transactions to sign and signs them.
pub(crate) struct TransactionTask<D: Db, S: ScannerFeed, Sch: Scheduler> {
db: D,
keys: ThresholdKeys<<Sch::SignableTransaction as SignableTransaction>::Ciphersuite>,
attempt_manager:
AttemptManager<D, <Sch::SignableTransaction as SignableTransaction>::PreprocessMachine>,
}
impl<D: Db, S: ScannerFeed> TransactionTask<D, S> {
pub(crate) async fn new(
db: D,
keys: ThresholdKeys<<Sch::SignableTransaction as SignableTransaction>::Ciphersuite>,
) -> Self {
Self { db, keys, attempt_manager: AttemptManager::new() }
}
}
#[async_trait::async_trait]
impl<D: Db, S: ScannerFeed> ContinuallyRan for TransactionTask<D, S> {
async fn run_iteration(&mut self) -> Result<bool, String> {
let mut iterated = false;
// Check for new transactions to sign
loop {
let mut txn = self.db.txn();
let Some(tx) = TransactionsToSign::try_recv(&mut txn, self.key) else { break };
iterated = true;
let mut machines = Vec::with_capacity(self.keys.len());
for keys in &self.keys {
machines.push(tx.clone().sign(keys.clone()));
}
let messages = self.attempt_manager.register(tx.id(), machines);
todo!("TODO");
txn.commit();
}
// Check for completed Eventualities (meaning we should no longer sign for these transactions)
loop {
let mut txn = self.db.txn();
let Some(tx) = CompletedEventualities::try_recv(&mut txn, self.key) else { break };
iterated = true;
self.attempt_manager.retire(tx);
txn.commit();
}
loop {
let mut txn = self.db.txn();
let Some(msg) = TransactionSignMessages::try_recv(&mut txn, self.key) else { break };
iterated = true;
match self.attempt_manager.handle(msg) {
Response::Messages(messages) => todo!("TODO"),
Response::Signature(signature) => todo!("TODO"),
}
}
Ok(iterated)
}
}