Remove signed Substrate TXs from Coordinator

This commit is contained in:
Luke Parker 2023-05-13 22:43:13 -04:00
parent 47f8766da6
commit 40b2920412
No known key found for this signature in database
3 changed files with 17 additions and 55 deletions

View file

@ -12,22 +12,11 @@ use std::{
use zeroize::Zeroizing; use zeroize::Zeroizing;
use rand_core::OsRng; use rand_core::OsRng;
use blake2::Digest; use ciphersuite::{group::ff::Field, Ciphersuite, Ristretto};
use ciphersuite::{
group::{
ff::{Field, PrimeField},
GroupEncoding,
},
Ciphersuite, Ristretto,
};
use serai_db::{DbTxn, Db, MemDb}; use serai_db::{DbTxn, Db, MemDb};
use serai_client::{ use serai_client::{Public, Signature, Serai};
subxt::{config::extrinsic_params::BaseExtrinsicParamsBuilder, tx::Signer},
Public, PairSigner, Serai,
};
use tokio::{ use tokio::{
sync::{ sync::{
@ -385,19 +374,6 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
) { ) {
let pub_key = Ristretto::generator() * key.deref(); let pub_key = Ristretto::generator() * key.deref();
// TODO: This is cursed. serai_client has to handle this for us
let substrate_signer = {
let mut bytes = Zeroizing::new([0; 96]);
// Private key
bytes[.. 32].copy_from_slice(&key.to_repr());
// Nonce
let nonce = Zeroizing::new(blake2::Blake2s256::digest(&bytes));
bytes[32 .. 64].copy_from_slice(nonce.as_ref());
// Public key
bytes[64 ..].copy_from_slice(&pub_key.to_bytes());
PairSigner::new(schnorrkel::keys::Keypair::from_bytes(bytes.as_ref()).unwrap().into())
};
loop { loop {
let msg = processors.recv().await; let msg = processors.recv().await;
@ -429,30 +405,17 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
); );
// TODO: Also check the other KeyGenId fields // TODO: Also check the other KeyGenId fields
// TODO: Publish an unsigned TX with a Musig signature here, instead of on-chain voting // TODO: Sign a MuSig signature here
// That removes the need for this nonce
let Ok(nonce) = serai.get_nonce(&substrate_signer.address()).await else {
log::error!("couldn't get nonce from Serai node");
todo!()
};
let tx = serai let tx = Serai::set_validator_set_keys(
.sign( id.set.network,
&substrate_signer,
&Serai::vote(
msg.network,
( (
Public(substrate_key), Public(substrate_key),
coin_key coin_key
.try_into() .try_into()
.expect("external key from processor exceeded max external key length"), .expect("external key from processor exceeded max external key length"),
), ),
), Signature([0; 64]), // TODO
nonce,
BaseExtrinsicParamsBuilder::new(),
)
.expect(
"tried to sign an invalid payload despite creating the payload via serai_client",
); );
match serai.publish(&tx).await { match serai.publish(&tx).await {
@ -547,7 +510,7 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
// TODO: Check this key's key pair's substrate key is authorized to publish batches // TODO: Check this key's key pair's substrate key is authorized to publish batches
// TODO: Check the batch ID is an atomic increment // TODO: Check the batch ID is an atomic increment
match serai.publish(&serai.execute_batch(batch.clone())).await { match serai.publish(&Serai::execute_batch(batch.clone())).await {
Ok(hash) => { Ok(hash) => {
log::info!( log::info!(
"executed batch {:?} {} (block {}) in TX {}", "executed batch {:?} {} (block {}) in TX {}",

View file

@ -24,7 +24,7 @@ use subxt::{
}; };
pub use serai_runtime::primitives; pub use serai_runtime::primitives;
use primitives::{Signature, SeraiAddress}; pub use primitives::{Signature, SeraiAddress};
use serai_runtime::{ use serai_runtime::{
system::Config, support::traits::PalletInfo as PalletInfoTrait, PalletInfo, Runtime, system::Config, support::traits::PalletInfo as PalletInfoTrait, PalletInfo, Runtime,

View file

@ -7,7 +7,8 @@ use scale_info::TypeInfo;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use sp_core::sr25519::{Public, Signature as RistrettoSignature}; use sp_core::sr25519::Public;
pub use sp_core::sr25519::Signature;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use sp_core::{Pair as PairTrait, sr25519::Pair}; use sp_core::{Pair as PairTrait, sr25519::Pair};
@ -76,8 +77,6 @@ impl StaticLookup for AccountLookup {
} }
} }
pub type Signature = RistrettoSignature;
pub const fn pallet_address(pallet: &'static [u8]) -> SeraiAddress { pub const fn pallet_address(pallet: &'static [u8]) -> SeraiAddress {
let mut address = [0; 32]; let mut address = [0; 32];
let mut set = false; let mut set = false;