From 0d38dc96b6b0ff6025f712764dfb5c237a5e698d Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 1 Sep 2025 21:04:57 -0400 Subject: [PATCH] Use `serai-primitives`, not `serai-client`, when possible in `coordinator/*` Also updates `serai-coordinator-tributary` to prefer `borsh` to SCALE. --- Cargo.lock | 3 ++- coordinator/p2p/Cargo.toml | 2 +- coordinator/p2p/src/heartbeat.rs | 2 +- coordinator/p2p/src/lib.rs | 2 +- coordinator/tributary/Cargo.toml | 3 +-- coordinator/tributary/src/db.rs | 7 +++--- coordinator/tributary/src/lib.rs | 6 +++--- coordinator/tributary/src/transaction.rs | 27 ++++++++++++------------ 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23cd88ef..35769653 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9934,10 +9934,10 @@ dependencies = [ "log", "rand_core 0.6.4", "schnorr-signatures", - "serai-client", "serai-coordinator-substrate", "serai-cosign", "serai-db", + "serai-primitives", "serai-processor-messages", "serai-task", "tributary-sdk", @@ -10315,6 +10315,7 @@ dependencies = [ "dkg-musig", "parity-scale-codec", "rand_core 0.6.4", + "scale-info", "sp-core", "zeroize", ] diff --git a/coordinator/p2p/Cargo.toml b/coordinator/p2p/Cargo.toml index b24532db..ec1e1e8e 100644 --- a/coordinator/p2p/Cargo.toml +++ b/coordinator/p2p/Cargo.toml @@ -22,7 +22,7 @@ borsh = { version = "1", default-features = false, features = ["std", "derive", serai-db = { path = "../../common/db", version = "0.1" } -serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] } +serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] } serai-cosign = { path = "../cosign" } tributary-sdk = { path = "../tributary-sdk" } diff --git a/coordinator/p2p/src/heartbeat.rs b/coordinator/p2p/src/heartbeat.rs index 7691abbd..81385e1b 100644 --- a/coordinator/p2p/src/heartbeat.rs +++ b/coordinator/p2p/src/heartbeat.rs @@ -1,7 +1,7 @@ use core::future::Future; use std::time::{Duration, SystemTime}; -use serai_client::validator_sets::primitives::{MAX_KEY_SHARES_PER_SET, ExternalValidatorSet}; +use serai_primitives::{MAX_KEY_SHARES_PER_SET, ExternalValidatorSet}; use futures_lite::FutureExt; diff --git a/coordinator/p2p/src/lib.rs b/coordinator/p2p/src/lib.rs index 68536b9d..4f3658ea 100644 --- a/coordinator/p2p/src/lib.rs +++ b/coordinator/p2p/src/lib.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use borsh::{BorshSerialize, BorshDeserialize}; -use serai_client::{primitives::ExternalNetworkId, validator_sets::primitives::ExternalValidatorSet}; +use serai_primitives::{network_id::ExternalNetworkId, validator_sets::ExternalValidatorSet}; use serai_db::Db; use tributary_sdk::{ReadWrite, TransactionTrait, Tributary, TributaryReader}; diff --git a/coordinator/tributary/Cargo.toml b/coordinator/tributary/Cargo.toml index 57471672..1926cf81 100644 --- a/coordinator/tributary/Cargo.toml +++ b/coordinator/tributary/Cargo.toml @@ -21,7 +21,6 @@ workspace = true zeroize = { version = "^1.5", default-features = false, features = ["std"] } rand_core = { version = "0.6", 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"] } blake2 = { version = "0.11.0-rc.0", default-features = false, features = ["alloc"] } @@ -30,7 +29,7 @@ dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = fals dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] } schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr", default-features = false, features = ["std"] } -serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] } +serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] } serai-db = { path = "../../common/db" } serai-task = { path = "../../common/task", version = "0.1" } diff --git a/coordinator/tributary/src/db.rs b/coordinator/tributary/src/db.rs index dc443168..acfe6a26 100644 --- a/coordinator/tributary/src/db.rs +++ b/coordinator/tributary/src/db.rs @@ -1,9 +1,8 @@ use std::collections::HashMap; -use scale::Encode; use borsh::{BorshSerialize, BorshDeserialize}; -use serai_client::{primitives::SeraiAddress, validator_sets::primitives::ExternalValidatorSet}; +use serai_primitives::{address::SeraiAddress, validator_sets::primitives::ExternalValidatorSet}; use messages::sign::{VariantSignId, SignId}; @@ -14,7 +13,7 @@ use serai_cosign::CosignIntent; use crate::transaction::SigningProtocolRound; /// A topic within the database which the group participates in -#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, BorshSerialize, BorshDeserialize)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)] pub enum Topic { /// Vote to remove a participant RemoveParticipant { @@ -123,7 +122,7 @@ impl Topic { Topic::DkgConfirmation { attempt, round: _ } => Some({ let id = { let mut id = [0; 32]; - let encoded_set = set.encode(); + let encoded_set = borsh::to_vec(set).unwrap(); id[.. encoded_set.len()].copy_from_slice(&encoded_set); VariantSignId::Batch(id) }; diff --git a/coordinator/tributary/src/lib.rs b/coordinator/tributary/src/lib.rs index a4fd3f2f..2fd9a334 100644 --- a/coordinator/tributary/src/lib.rs +++ b/coordinator/tributary/src/lib.rs @@ -8,9 +8,9 @@ use std::collections::HashMap; use ciphersuite::group::GroupEncoding; use dkg::Participant; -use serai_client::{ - primitives::SeraiAddress, - validator_sets::primitives::{ExternalValidatorSet, Slash}, +use serai_primitives::{ + address::SeraiAddress, + validator_sets::{ExternalValidatorSet, Slash}, }; use serai_db::*; diff --git a/coordinator/tributary/src/transaction.rs b/coordinator/tributary/src/transaction.rs index 11f77d7c..f73fe0cc 100644 --- a/coordinator/tributary/src/transaction.rs +++ b/coordinator/tributary/src/transaction.rs @@ -12,10 +12,9 @@ use ciphersuite::{ use dalek_ff_group::Ristretto; use schnorr::SchnorrSignature; -use scale::Encode; use borsh::{BorshSerialize, BorshDeserialize}; -use serai_client::{primitives::SeraiAddress, validator_sets::primitives::MAX_KEY_SHARES_PER_SET}; +use serai_primitives::{addess::SeraiAddress, validator_sets::MAX_KEY_SHARES_PER_SET}; use messages::sign::VariantSignId; @@ -29,7 +28,7 @@ use tributary_sdk::{ use crate::db::Topic; /// The round this data is for, within a signing protocol. -#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, BorshSerialize, BorshDeserialize)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)] pub enum SigningProtocolRound { /// A preprocess. Preprocess, @@ -242,19 +241,20 @@ impl TransactionTrait for Transaction { fn kind(&self) -> TransactionKind { match self { Transaction::RemoveParticipant { participant, signed } => TransactionKind::Signed( - (b"RemoveParticipant", participant).encode(), + borsh::to_vec(&(b"RemoveParticipant".as_slice(), participant)).unwrap(), signed.to_tributary_signed(0), ), - Transaction::DkgParticipation { signed, .. } => { - TransactionKind::Signed(b"DkgParticipation".encode(), signed.to_tributary_signed(0)) - } + Transaction::DkgParticipation { signed, .. } => TransactionKind::Signed( + borsh::to_vec(b"DkgParticipation".as_slice()).unwrap(), + signed.to_tributary_signed(0), + ), Transaction::DkgConfirmationPreprocess { attempt, signed, .. } => TransactionKind::Signed( - (b"DkgConfirmation", attempt).encode(), + borsh::to_vec(b"DkgConfirmation".as_slice(), attempt).unwrap(), signed.to_tributary_signed(0), ), Transaction::DkgConfirmationShare { attempt, signed, .. } => TransactionKind::Signed( - (b"DkgConfirmation", attempt).encode(), + borsh::to_vec(b"DkgConfirmation".as_slice(), attempt).unwrap(), signed.to_tributary_signed(1), ), @@ -264,13 +264,14 @@ impl TransactionTrait for Transaction { Transaction::Batch { .. } => TransactionKind::Provided("Batch"), Transaction::Sign { id, attempt, round, signed, .. } => TransactionKind::Signed( - (b"Sign", id, attempt).encode(), + borsh::to_vec(b"Sign".as_slice(), id, attempt).unwrap(), signed.to_tributary_signed(round.nonce()), ), - Transaction::SlashReport { signed, .. } => { - TransactionKind::Signed(b"SlashReport".encode(), signed.to_tributary_signed(0)) - } + Transaction::SlashReport { signed, .. } => TransactionKind::Signed( + borsh::to_vec(b"SlashReport".as_slice()).unwrap(), + signed.to_tributary_signed(0), + ), } }