Remove final references to scale in coordinator/processor

Slight tweaks to processor
This commit is contained in:
Luke Parker
2025-09-02 02:41:20 -04:00
parent ada94e8c5d
commit 5736b87b57
10 changed files with 16 additions and 95 deletions

3
Cargo.lock generated
View File

@@ -9787,7 +9787,6 @@ dependencies = [
"hex", "hex",
"log", "log",
"modular-frost", "modular-frost",
"parity-scale-codec",
"rand_core 0.6.4", "rand_core 0.6.4",
"schnorr-signatures", "schnorr-signatures",
"schnorrkel", "schnorrkel",
@@ -9854,7 +9853,6 @@ dependencies = [
"dkg", "dkg",
"futures", "futures",
"log", "log",
"parity-scale-codec",
"serai-client", "serai-client",
"serai-cosign", "serai-cosign",
"serai-db", "serai-db",
@@ -9892,7 +9890,6 @@ dependencies = [
"blake2 0.11.0-rc.0", "blake2 0.11.0-rc.0",
"borsh", "borsh",
"log", "log",
"parity-scale-codec",
"schnorrkel", "schnorrkel",
"serai-client", "serai-client",
"serai-cosign-types", "serai-cosign-types",

View File

@@ -33,7 +33,6 @@ frost = { package = "modular-frost", path = "../crypto/frost" }
frost-schnorrkel = { path = "../crypto/schnorrkel" } frost-schnorrkel = { path = "../crypto/schnorrkel" }
hex = { version = "0.4", default-features = false, features = ["std"] } hex = { version = "0.4", default-features = false, features = ["std"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive", "bit-vec"] }
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
zalloc = { path = "../common/zalloc" } zalloc = { path = "../common/zalloc" }

View File

@@ -21,7 +21,6 @@ workspace = true
blake2 = { version = "0.11.0-rc.0", default-features = false, features = ["alloc"] } blake2 = { version = "0.11.0-rc.0", default-features = false, features = ["alloc"] }
schnorrkel = { version = "0.11", default-features = false, features = ["std"] } schnorrkel = { version = "0.11", default-features = false, features = ["std"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive"] }
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] } serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] }

View File

@@ -7,7 +7,6 @@ use std::{sync::Arc, collections::HashMap, time::Instant};
use blake2::{Digest, Blake2s256}; use blake2::{Digest, Blake2s256};
use scale::{Encode, Decode};
use borsh::{BorshSerialize, BorshDeserialize}; use borsh::{BorshSerialize, BorshDeserialize};
use serai_client::{ use serai_client::{
@@ -80,68 +79,6 @@ enum HasEvents {
No, No,
} }
/// An intended cosign.
#[derive(Clone, Copy, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
pub struct CosignIntent {
/// The global session this cosign is being performed under.
pub global_session: [u8; 32],
/// The number of the block to cosign.
pub block_number: u64,
/// The hash of the block to cosign.
pub block_hash: [u8; 32],
/// If this cosign must be handled before further cosigns are.
pub notable: bool,
}
/// A cosign.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, BorshSerialize, BorshDeserialize)]
pub struct Cosign {
/// The global session this cosign is being performed under.
pub global_session: [u8; 32],
/// The number of the block to cosign.
pub block_number: u64,
/// The hash of the block to cosign.
pub block_hash: [u8; 32],
/// The actual cosigner.
pub cosigner: ExternalNetworkId,
}
impl CosignIntent {
/// Convert this into a `Cosign`.
pub fn into_cosign(self, cosigner: ExternalNetworkId) -> Cosign {
let CosignIntent { global_session, block_number, block_hash, notable: _ } = self;
Cosign { global_session, block_number, block_hash, cosigner }
}
}
impl Cosign {
/// The message to sign to sign this cosign.
///
/// This must be signed with schnorrkel, the context set to `COSIGN_CONTEXT`.
pub fn signature_message(&self) -> Vec<u8> {
// We use a schnorrkel context to domain-separate this
self.encode()
}
}
/// A signed cosign.
#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)]
pub struct SignedCosign {
/// The cosign.
pub cosign: Cosign,
/// The signature for the cosign.
pub signature: [u8; 64],
}
impl SignedCosign {
fn verify_signature(&self, signer: serai_client::Public) -> bool {
let Ok(signer) = schnorrkel::PublicKey::from_bytes(&signer.0) else { return false };
let Ok(signature) = schnorrkel::Signature::from_bytes(&self.signature) else { return false };
signer.verify_simple(COSIGN_CONTEXT, &self.cosign.signature_message(), &signature).is_ok()
}
}
create_db! { create_db! {
Cosign { Cosign {
// The following are populated by the intend task and used throughout the library // The following are populated by the intend task and used throughout the library

View File

@@ -11,7 +11,6 @@ use tokio::sync::mpsc;
use serai_db::{Get, DbTxn, Db as DbTrait, create_db, db_channel}; use serai_db::{Get, DbTxn, Db as DbTrait, create_db, db_channel};
use scale::Encode;
use serai_client::validator_sets::primitives::ExternalValidatorSet; use serai_client::validator_sets::primitives::ExternalValidatorSet;
use tributary_sdk::{TransactionKind, TransactionError, ProvidedError, TransactionTrait, Tributary}; use tributary_sdk::{TransactionKind, TransactionError, ProvidedError, TransactionTrait, Tributary};
@@ -479,7 +478,8 @@ pub(crate) async fn spawn_tributary<P: P2p>(
return; return;
} }
let genesis = <[u8; 32]>::from(Blake2s::<U32>::digest((set.serai_block, set.set).encode())); let genesis =
<[u8; 32]>::from(Blake2s::<U32>::digest(borsh::to_vec(&(set.serai_block, set.set)).unwrap()));
// Since the Serai block will be finalized, then cosigned, before we handle this, this time will // Since the Serai block will be finalized, then cosigned, before we handle this, this time will
// be a couple of minutes stale. While the Tributary will still function with a start time in the // be a couple of minutes stale. While the Tributary will still function with a start time in the

View File

@@ -20,7 +20,6 @@ workspace = true
[dependencies] [dependencies]
bitvec = { version = "1", default-features = false, features = ["std"] } bitvec = { version = "1", default-features = false, features = ["std"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive", "bit-vec"] }
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] } dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] }

View File

@@ -4,7 +4,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use scale::{Encode, Decode};
use borsh::{BorshSerialize, BorshDeserialize}; use borsh::{BorshSerialize, BorshDeserialize};
use dkg::Participant; use dkg::Participant;
@@ -178,14 +177,13 @@ impl Keys {
signature_participants, signature_participants,
signature, signature,
); );
_public_db::Keys::set(txn, set.network, &(set.session, tx.encode())); _public_db::Keys::set(txn, set.network, &(set.session, tx));
} }
pub(crate) fn take( pub(crate) fn take(
txn: &mut impl DbTxn, txn: &mut impl DbTxn,
network: ExternalNetworkId, network: ExternalNetworkId,
) -> Option<(Session, Transaction)> { ) -> Option<(Session, Transaction)> {
let (session, tx) = _public_db::Keys::take(txn, network)?; _public_db::Keys::take(txn, network)
Some((session, <_>::decode(&mut tx.as_slice()).unwrap()))
} }
} }
@@ -226,13 +224,12 @@ impl SlashReports {
slash_report, slash_report,
signature, signature,
); );
_public_db::SlashReports::set(txn, set.network, &(set.session, tx.encode())); _public_db::SlashReports::set(txn, set.network, &(set.session, tx));
} }
pub(crate) fn take( pub(crate) fn take(
txn: &mut impl DbTxn, txn: &mut impl DbTxn,
network: ExternalNetworkId, network: ExternalNetworkId,
) -> Option<(Session, Transaction)> { ) -> Option<(Session, Transaction)> {
let (session, tx) = _public_db::SlashReports::take(txn, network)?; _public_db::SlashReports::take(txn, network)
Some((session, <_>::decode(&mut tx.as_slice()).unwrap()))
} }
} }

View File

@@ -34,7 +34,7 @@ static SEND_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
db_channel! { db_channel! {
ProcessorBinCoordinator { ProcessorBinCoordinator {
SentCoordinatorMessages: () -> Vec<u8>, SentCoordinatorMessages: () -> messages::ProcessorMessage,
} }
} }
@@ -48,7 +48,7 @@ impl CoordinatorSend {
fn send(&mut self, msg: &messages::ProcessorMessage) { fn send(&mut self, msg: &messages::ProcessorMessage) {
let _lock = SEND_LOCK.lock().unwrap(); let _lock = SEND_LOCK.lock().unwrap();
let mut txn = self.db.txn(); let mut txn = self.db.txn();
SentCoordinatorMessages::send(&mut txn, &borsh::to_vec(msg).unwrap()); SentCoordinatorMessages::send(&mut txn, msg);
txn.commit(); txn.commit();
self self
.sent_message .sent_message
@@ -114,12 +114,9 @@ impl Coordinator {
let mut txn = db.txn(); let mut txn = db.txn();
match SentCoordinatorMessages::try_recv(&mut txn) { match SentCoordinatorMessages::try_recv(&mut txn) {
Some(msg) => { Some(msg) => {
let metadata = Metadata { let metadata =
from: service, Metadata { from: service, to: Service::Coordinator, intent: msg.intent() };
to: Service::Coordinator, message_queue.queue_with_retry(metadata, borsh::to_vec(&msg).unwrap()).await;
intent: borsh::from_slice::<messages::ProcessorMessage>(&msg).unwrap().intent(),
};
message_queue.queue_with_retry(metadata, msg).await;
txn.commit(); txn.commit();
} }
None => { None => {

View File

@@ -7,7 +7,6 @@ use serai_primitives::{
balance::{Amount, ExternalBalance}, balance::{Amount, ExternalBalance},
}; };
use borsh::BorshDeserialize;
use serai_db::{Get, DbTxn, create_db, db_channel}; use serai_db::{Get, DbTxn, create_db, db_channel};
use primitives::{Payment, ReceivedOutput}; use primitives::{Payment, ReceivedOutput};
@@ -22,9 +21,10 @@ create_db! {
} }
} }
#[rustfmt::skip]
db_channel! { db_channel! {
UtxoScheduler { UtxoScheduler {
PendingBranch: (key: &[u8], balance: ExternalBalance) -> Vec<u8>, PendingBranch: <S: ScannerFeed>(key: &[u8], balance: ExternalBalance) -> TreeTransaction<AddressFor<S>>,
} }
} }
@@ -103,14 +103,13 @@ impl<S: ScannerFeed> Db<S> {
balance: ExternalBalance, balance: ExternalBalance,
child: &TreeTransaction<AddressFor<S>>, child: &TreeTransaction<AddressFor<S>>,
) { ) {
PendingBranch::send(txn, key.to_bytes().as_ref(), balance, &borsh::to_vec(child).unwrap()) PendingBranch::<S>::send(txn, key.to_bytes().as_ref(), balance, child)
} }
pub(crate) fn take_pending_branch( pub(crate) fn take_pending_branch(
txn: &mut impl DbTxn, txn: &mut impl DbTxn,
key: KeyFor<S>, key: KeyFor<S>,
balance: ExternalBalance, balance: ExternalBalance,
) -> Option<TreeTransaction<AddressFor<S>>> { ) -> Option<TreeTransaction<AddressFor<S>>> {
PendingBranch::try_recv(txn, key.to_bytes().as_ref(), balance) PendingBranch::<S>::try_recv(txn, key.to_bytes().as_ref(), balance)
.map(|bytes| TreeTransaction::<AddressFor<S>>::deserialize(&mut bytes.as_slice()).unwrap())
} }
} }

View File

@@ -123,10 +123,7 @@ impl<D: Db> ContinuallyRan for CosignerTask<D> {
let cosign = self.current_cosign.take().unwrap(); let cosign = self.current_cosign.take().unwrap();
LatestCosigned::set(&mut txn, self.session, &cosign.block_number); LatestCosigned::set(&mut txn, self.session, &cosign.block_number);
let cosign = SignedCosign { let cosign = SignedCosign { cosign, signature: Signature::from(signature).0 };
cosign,
signature: borsh::to_vec(&Signature::from(signature)).unwrap().try_into().unwrap(),
};
// Send the cosign // Send the cosign
Cosign::send(&mut txn, self.session, &cosign); Cosign::send(&mut txn, self.session, &cosign);
} }