mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add BatchSignerTask
Uses a wrapper around AlgorithmMachine Schnorrkel to let the message be &[].
This commit is contained in:
@@ -548,36 +548,36 @@ mod _public_db {
|
||||
|
||||
db_channel! {
|
||||
ScannerPublic {
|
||||
BatchToSign: (key: &[u8]) -> Batch,
|
||||
AcknowledgedBatch: (key: &[u8]) -> u32,
|
||||
BatchesToSign: (key: &[u8]) -> Batch,
|
||||
AcknowledgedBatches: (key: &[u8]) -> u32,
|
||||
CompletedEventualities: (key: &[u8]) -> [u8; 32],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The batches to sign and publish.
|
||||
pub struct BatchToSign<K: GroupEncoding>(PhantomData<K>);
|
||||
impl<K: GroupEncoding> BatchToSign<K> {
|
||||
pub struct BatchesToSign<K: GroupEncoding>(PhantomData<K>);
|
||||
impl<K: GroupEncoding> BatchesToSign<K> {
|
||||
pub(crate) fn send(txn: &mut impl DbTxn, key: &K, batch: &Batch) {
|
||||
_public_db::BatchToSign::send(txn, key.to_bytes().as_ref(), batch);
|
||||
_public_db::BatchesToSign::send(txn, key.to_bytes().as_ref(), batch);
|
||||
}
|
||||
|
||||
/// Receive a batch to sign and publish.
|
||||
pub fn try_recv(txn: &mut impl DbTxn, key: &K) -> Option<Batch> {
|
||||
_public_db::BatchToSign::try_recv(txn, key.to_bytes().as_ref())
|
||||
_public_db::BatchesToSign::try_recv(txn, key.to_bytes().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
/// The batches which were acknowledged on-chain.
|
||||
pub struct AcknowledgedBatch<K: GroupEncoding>(PhantomData<K>);
|
||||
impl<K: GroupEncoding> AcknowledgedBatch<K> {
|
||||
pub struct AcknowledgedBatches<K: GroupEncoding>(PhantomData<K>);
|
||||
impl<K: GroupEncoding> AcknowledgedBatches<K> {
|
||||
pub(crate) fn send(txn: &mut impl DbTxn, key: &K, batch: u32) {
|
||||
_public_db::AcknowledgedBatch::send(txn, key.to_bytes().as_ref(), &batch);
|
||||
_public_db::AcknowledgedBatches::send(txn, key.to_bytes().as_ref(), &batch);
|
||||
}
|
||||
|
||||
/// Receive the ID of a batch which was acknowledged.
|
||||
pub fn try_recv(txn: &mut impl DbTxn, key: &K) -> Option<u32> {
|
||||
_public_db::AcknowledgedBatch::try_recv(txn, key.to_bytes().as_ref())
|
||||
_public_db::AcknowledgedBatches::try_recv(txn, key.to_bytes().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ pub use lifetime::LifetimeStage;
|
||||
// Database schema definition and associated functions.
|
||||
mod db;
|
||||
use db::ScannerGlobalDb;
|
||||
pub use db::{BatchToSign, AcknowledgedBatch, CompletedEventualities};
|
||||
pub use db::{BatchesToSign, AcknowledgedBatches, CompletedEventualities};
|
||||
// Task to index the blockchain, ensuring we don't reorganize finalized blocks.
|
||||
mod index;
|
||||
// Scans blocks for received coins.
|
||||
|
||||
@@ -8,7 +8,7 @@ use serai_in_instructions_primitives::{MAX_BATCH_SIZE, Batch};
|
||||
|
||||
use primitives::task::ContinuallyRan;
|
||||
use crate::{
|
||||
db::{Returnable, ScannerGlobalDb, InInstructionData, ScanToReportDb, BatchToSign},
|
||||
db::{Returnable, ScannerGlobalDb, InInstructionData, ScanToReportDb, BatchesToSign},
|
||||
index,
|
||||
scan::next_to_scan_for_outputs_block,
|
||||
ScannerFeed, KeyFor,
|
||||
@@ -160,7 +160,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for ReportTask<D, S> {
|
||||
}
|
||||
|
||||
for batch in batches {
|
||||
BatchToSign::send(&mut txn, &external_key_for_session_to_sign_batch, &batch);
|
||||
BatchesToSign::send(&mut txn, &external_key_for_session_to_sign_batch, &batch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use serai_coins_primitives::{OutInstruction, OutInstructionWithBalance};
|
||||
|
||||
use primitives::task::ContinuallyRan;
|
||||
use crate::{
|
||||
db::{ScannerGlobalDb, SubstrateToEventualityDb, AcknowledgedBatch},
|
||||
db::{ScannerGlobalDb, SubstrateToEventualityDb, AcknowledgedBatches},
|
||||
report, ScannerFeed, KeyFor,
|
||||
};
|
||||
|
||||
@@ -82,7 +82,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SubstrateTask<D, S> {
|
||||
{
|
||||
let external_key_for_session_to_sign_batch =
|
||||
report::take_external_key_for_session_to_sign_batch::<S>(&mut txn, batch_id).unwrap();
|
||||
AcknowledgedBatch::send(&mut txn, &external_key_for_session_to_sign_batch, batch_id);
|
||||
AcknowledgedBatches::send(&mut txn, &external_key_for_session_to_sign_batch, batch_id);
|
||||
}
|
||||
|
||||
// Mark we made progress and handle this
|
||||
|
||||
Reference in New Issue
Block a user