Redo coordinator's Substrate scanner

This commit is contained in:
Luke Parker
2024-12-31 10:37:19 -05:00
parent 5a42f66dc2
commit 8c9441a1a5
25 changed files with 792 additions and 743 deletions

View File

@@ -5,9 +5,8 @@ use tokio::sync::mpsc;
use scale::Encode;
use serai_client::{
primitives::Signature,
validator_sets::primitives::Session,
in_instructions::primitives::{Batch, SignedBatch},
primitives::Signature, validator_sets::primitives::Session,
in_instructions::primitives::SignedBatch,
};
use serai_db::{Get, DbTxn, Db, create_db, db_channel};

View File

@@ -272,20 +272,17 @@ pub async fn main_loop<
}
messages::substrate::CoordinatorMessage::Block {
serai_block_number: _,
batches,
batch,
mut burns,
} => {
let scanner = scanner.as_mut().unwrap();
// Substrate sets this limit to prevent DoSs from malicious validator sets
// That bound lets us consume this txn in the following loop body, as an optimization
assert!(batches.len() <= 1);
for messages::substrate::ExecutedBatch {
if let Some(messages::substrate::ExecutedBatch {
id,
publisher,
in_instructions_hash,
in_instruction_results,
} in batches
}) = batch
{
let key_to_activate =
KeyToActivate::<KeyFor<S>>::try_recv(txn.as_mut().unwrap()).map(|key| key.0);

View File

@@ -145,7 +145,7 @@ pub mod sign {
pub mod coordinator {
use super::*;
// TODO: Why does this not simply take the block hash?
// TODO: Remove this for the one defined in serai-cosign
pub fn cosign_block_msg(block_number: u64, block: [u8; 32]) -> Vec<u8> {
const DST: &[u8] = b"Cosign";
let mut res = vec![u8::try_from(DST.len()).unwrap()];
@@ -203,7 +203,7 @@ pub mod substrate {
/// A block from Serai with relevance to this processor.
Block {
serai_block_number: u64,
batches: Vec<ExecutedBatch>,
batch: Option<ExecutedBatch>,
burns: Vec<OutInstructionWithBalance>,
},
}

View File

@@ -12,7 +12,7 @@ use frost::dkg::{ThresholdCore, ThresholdKeys};
use serai_primitives::Signature;
use serai_validator_sets_primitives::{Session, Slash};
use serai_in_instructions_primitives::{Batch, SignedBatch};
use serai_in_instructions_primitives::SignedBatch;
use serai_db::{DbTxn, Db};