mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Remove final references to scale in coordinator/processor
Slight tweaks to processor
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -9787,7 +9787,6 @@ dependencies = [
|
||||
"hex",
|
||||
"log",
|
||||
"modular-frost",
|
||||
"parity-scale-codec",
|
||||
"rand_core 0.6.4",
|
||||
"schnorr-signatures",
|
||||
"schnorrkel",
|
||||
@@ -9854,7 +9853,6 @@ dependencies = [
|
||||
"dkg",
|
||||
"futures",
|
||||
"log",
|
||||
"parity-scale-codec",
|
||||
"serai-client",
|
||||
"serai-cosign",
|
||||
"serai-db",
|
||||
@@ -9892,7 +9890,6 @@ dependencies = [
|
||||
"blake2 0.11.0-rc.0",
|
||||
"borsh",
|
||||
"log",
|
||||
"parity-scale-codec",
|
||||
"schnorrkel",
|
||||
"serai-client",
|
||||
"serai-cosign-types",
|
||||
|
||||
@@ -33,7 +33,6 @@ frost = { package = "modular-frost", path = "../crypto/frost" }
|
||||
frost-schnorrkel = { path = "../crypto/schnorrkel" }
|
||||
|
||||
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"] }
|
||||
|
||||
zalloc = { path = "../common/zalloc" }
|
||||
|
||||
@@ -21,7 +21,6 @@ workspace = true
|
||||
blake2 = { version = "0.11.0-rc.0", default-features = false, features = ["alloc"] }
|
||||
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"] }
|
||||
serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] }
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::{sync::Arc, collections::HashMap, time::Instant};
|
||||
|
||||
use blake2::{Digest, Blake2s256};
|
||||
|
||||
use scale::{Encode, Decode};
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
|
||||
use serai_client::{
|
||||
@@ -80,68 +79,6 @@ enum HasEvents {
|
||||
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! {
|
||||
Cosign {
|
||||
// The following are populated by the intend task and used throughout the library
|
||||
|
||||
@@ -11,7 +11,6 @@ use tokio::sync::mpsc;
|
||||
|
||||
use serai_db::{Get, DbTxn, Db as DbTrait, create_db, db_channel};
|
||||
|
||||
use scale::Encode;
|
||||
use serai_client::validator_sets::primitives::ExternalValidatorSet;
|
||||
|
||||
use tributary_sdk::{TransactionKind, TransactionError, ProvidedError, TransactionTrait, Tributary};
|
||||
@@ -479,7 +478,8 @@ pub(crate) async fn spawn_tributary<P: P2p>(
|
||||
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
|
||||
// be a couple of minutes stale. While the Tributary will still function with a start time in the
|
||||
|
||||
@@ -20,7 +20,6 @@ workspace = true
|
||||
[dependencies]
|
||||
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"] }
|
||||
|
||||
dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] }
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use scale::{Encode, Decode};
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
|
||||
use dkg::Participant;
|
||||
@@ -178,14 +177,13 @@ impl Keys {
|
||||
signature_participants,
|
||||
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(
|
||||
txn: &mut impl DbTxn,
|
||||
network: ExternalNetworkId,
|
||||
) -> Option<(Session, Transaction)> {
|
||||
let (session, tx) = _public_db::Keys::take(txn, network)?;
|
||||
Some((session, <_>::decode(&mut tx.as_slice()).unwrap()))
|
||||
_public_db::Keys::take(txn, network)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,13 +224,12 @@ impl SlashReports {
|
||||
slash_report,
|
||||
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(
|
||||
txn: &mut impl DbTxn,
|
||||
network: ExternalNetworkId,
|
||||
) -> Option<(Session, Transaction)> {
|
||||
let (session, tx) = _public_db::SlashReports::take(txn, network)?;
|
||||
Some((session, <_>::decode(&mut tx.as_slice()).unwrap()))
|
||||
_public_db::SlashReports::take(txn, network)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ static SEND_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
|
||||
|
||||
db_channel! {
|
||||
ProcessorBinCoordinator {
|
||||
SentCoordinatorMessages: () -> Vec<u8>,
|
||||
SentCoordinatorMessages: () -> messages::ProcessorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ impl CoordinatorSend {
|
||||
fn send(&mut self, msg: &messages::ProcessorMessage) {
|
||||
let _lock = SEND_LOCK.lock().unwrap();
|
||||
let mut txn = self.db.txn();
|
||||
SentCoordinatorMessages::send(&mut txn, &borsh::to_vec(msg).unwrap());
|
||||
SentCoordinatorMessages::send(&mut txn, msg);
|
||||
txn.commit();
|
||||
self
|
||||
.sent_message
|
||||
@@ -114,12 +114,9 @@ impl Coordinator {
|
||||
let mut txn = db.txn();
|
||||
match SentCoordinatorMessages::try_recv(&mut txn) {
|
||||
Some(msg) => {
|
||||
let metadata = Metadata {
|
||||
from: service,
|
||||
to: Service::Coordinator,
|
||||
intent: borsh::from_slice::<messages::ProcessorMessage>(&msg).unwrap().intent(),
|
||||
};
|
||||
message_queue.queue_with_retry(metadata, msg).await;
|
||||
let metadata =
|
||||
Metadata { from: service, to: Service::Coordinator, intent: msg.intent() };
|
||||
message_queue.queue_with_retry(metadata, borsh::to_vec(&msg).unwrap()).await;
|
||||
txn.commit();
|
||||
}
|
||||
None => {
|
||||
|
||||
@@ -7,7 +7,6 @@ use serai_primitives::{
|
||||
balance::{Amount, ExternalBalance},
|
||||
};
|
||||
|
||||
use borsh::BorshDeserialize;
|
||||
use serai_db::{Get, DbTxn, create_db, db_channel};
|
||||
|
||||
use primitives::{Payment, ReceivedOutput};
|
||||
@@ -22,9 +21,10 @@ create_db! {
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
db_channel! {
|
||||
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,
|
||||
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(
|
||||
txn: &mut impl DbTxn,
|
||||
key: KeyFor<S>,
|
||||
balance: ExternalBalance,
|
||||
) -> Option<TreeTransaction<AddressFor<S>>> {
|
||||
PendingBranch::try_recv(txn, key.to_bytes().as_ref(), balance)
|
||||
.map(|bytes| TreeTransaction::<AddressFor<S>>::deserialize(&mut bytes.as_slice()).unwrap())
|
||||
PendingBranch::<S>::try_recv(txn, key.to_bytes().as_ref(), balance)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +123,7 @@ impl<D: Db> ContinuallyRan for CosignerTask<D> {
|
||||
|
||||
let cosign = self.current_cosign.take().unwrap();
|
||||
LatestCosigned::set(&mut txn, self.session, &cosign.block_number);
|
||||
let cosign = SignedCosign {
|
||||
cosign,
|
||||
signature: borsh::to_vec(&Signature::from(signature)).unwrap().try_into().unwrap(),
|
||||
};
|
||||
let cosign = SignedCosign { cosign, signature: Signature::from(signature).0 };
|
||||
// Send the cosign
|
||||
Cosign::send(&mut txn, self.session, &cosign);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user