mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Use a MuSig signature to publish validator set key pairs to Serai
The processor/coordinator flow still has to be rewritten.
This commit is contained in:
@@ -33,7 +33,7 @@ impl Serai {
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn execute_batch(&self, batch: SignedBatch) -> Encoded {
|
||||
self.unsigned::<InInstructions, _>(&in_instructions::Call::<Runtime>::execute_batch { batch })
|
||||
pub fn execute_batch(batch: SignedBatch) -> Encoded {
|
||||
Self::unsigned::<InInstructions, _>(&in_instructions::Call::<Runtime>::execute_batch { batch })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ impl Serai {
|
||||
.map_err(SeraiError::RpcError)
|
||||
}
|
||||
|
||||
fn unsigned<P: 'static, C: Encode>(&self, call: &C) -> Encoded {
|
||||
fn unsigned<P: 'static, C: Encode>(call: &C) -> Encoded {
|
||||
// TODO: Should Serai purge the old transaction code AND set this to 0/1?
|
||||
const TRANSACTION_VERSION: u8 = 4;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use sp_core::sr25519::Signature;
|
||||
|
||||
use serai_runtime::{validator_sets, ValidatorSets, Runtime};
|
||||
pub use validator_sets::primitives;
|
||||
use primitives::{ValidatorSet, ValidatorSetData, KeyPair};
|
||||
|
||||
use subxt::tx::Payload;
|
||||
use subxt::utils::Encoded;
|
||||
|
||||
use crate::{primitives::NetworkId, Serai, SeraiError, Composite, scale_value, scale_composite};
|
||||
use crate::{primitives::NetworkId, Serai, SeraiError, scale_value};
|
||||
|
||||
const PALLET: &str = "ValidatorSets";
|
||||
|
||||
@@ -20,15 +22,6 @@ impl Serai {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_vote_events(
|
||||
&self,
|
||||
block: [u8; 32],
|
||||
) -> Result<Vec<ValidatorSetsEvent>, SeraiError> {
|
||||
self
|
||||
.events::<ValidatorSets, _>(block, |event| matches!(event, ValidatorSetsEvent::Vote { .. }))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_key_gen_events(
|
||||
&self,
|
||||
block: [u8; 32],
|
||||
@@ -52,17 +45,35 @@ impl Serai {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_validator_set_musig_key(
|
||||
&self,
|
||||
set: ValidatorSet,
|
||||
) -> Result<Option<[u8; 32]>, SeraiError> {
|
||||
self
|
||||
.storage(
|
||||
PALLET,
|
||||
"MuSigKeys",
|
||||
Some(vec![scale_value(set)]),
|
||||
self.get_latest_block_hash().await?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_keys(&self, set: ValidatorSet) -> Result<Option<KeyPair>, SeraiError> {
|
||||
self
|
||||
.storage(PALLET, "Keys", Some(vec![scale_value(set)]), self.get_latest_block_hash().await?)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn vote(network: NetworkId, key_pair: KeyPair) -> Payload<Composite<()>> {
|
||||
Payload::new(
|
||||
PALLET,
|
||||
"vote",
|
||||
scale_composite(validator_sets::Call::<Runtime>::vote { network, key_pair }),
|
||||
)
|
||||
pub fn set_validator_set_keys(
|
||||
network: NetworkId,
|
||||
key_pair: KeyPair,
|
||||
signature: Signature,
|
||||
) -> Encoded {
|
||||
Self::unsigned::<ValidatorSets, _>(&validator_sets::Call::<Runtime>::set_keys {
|
||||
network,
|
||||
key_pair,
|
||||
signature,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user