mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 21:49:26 +00:00
bug fixes
This commit is contained in:
@@ -73,7 +73,7 @@ pub async fn allocate_stake(
|
||||
nonce: u32,
|
||||
) -> [u8; 32] {
|
||||
// get the call
|
||||
let tx = serai.sign(&pair, SeraiValidatorSets::allocate(network, amount), nonce, 0);
|
||||
let tx = serai.sign(pair, SeraiValidatorSets::allocate(network, amount), nonce, 0);
|
||||
publish_tx(serai, &tx).await
|
||||
}
|
||||
|
||||
@@ -86,6 +86,6 @@ pub async fn deallocate_stake(
|
||||
nonce: u32,
|
||||
) -> [u8; 32] {
|
||||
// get the call
|
||||
let tx = serai.sign(&pair, SeraiValidatorSets::deallocate(network, amount), nonce, 0);
|
||||
let tx = serai.sign(pair, SeraiValidatorSets::deallocate(network, amount), nonce, 0);
|
||||
publish_tx(serai, &tx).await
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ async fn validator_set_rotation() {
|
||||
|
||||
// we start the chain with 4 default participants that has a single key share each
|
||||
participants.sort();
|
||||
verify_session_and_active_validators(&serai, network, 0, &participants).await;
|
||||
verify_session_and_active_validators(&serai, network, 0, participants).await;
|
||||
|
||||
// add 1 participant & verify
|
||||
let hash =
|
||||
@@ -190,7 +190,7 @@ async fn validator_set_rotation() {
|
||||
&serai,
|
||||
network,
|
||||
get_active_session(&serai, network, hash).await,
|
||||
&participants,
|
||||
participants,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -201,7 +201,7 @@ async fn validator_set_rotation() {
|
||||
participants.swap_remove(participants.iter().position(|k| *k == pair2.public()).unwrap());
|
||||
let active_session = get_active_session(&serai, network, hash).await;
|
||||
participants.sort();
|
||||
verify_session_and_active_validators(&serai, network, active_session, &participants).await;
|
||||
verify_session_and_active_validators(&serai, network, active_session, participants).await;
|
||||
|
||||
// check pending deallocations
|
||||
let pending = serai
|
||||
|
||||
@@ -652,7 +652,7 @@ pub mod pallet {
|
||||
// If not Serai, check the prior session had its keys cleared, which happens once its
|
||||
// retired
|
||||
return (network == NetworkId::Serai) ||
|
||||
(Keys::<T>::contains_key(ValidatorSet {
|
||||
(!Keys::<T>::contains_key(ValidatorSet {
|
||||
network,
|
||||
session: Session(current_session.0 - 1),
|
||||
}));
|
||||
|
||||
@@ -200,7 +200,7 @@ pub async fn key_gen<C: Ciphersuite>(
|
||||
assert_eq!(key_pair.0 .0, substrate_key);
|
||||
assert_eq!(&key_pair.1, &network_key);
|
||||
}
|
||||
_ => panic!("coordinator didn't respond with ConfirmKeyPair msg: {:?} ", msg),
|
||||
_ => panic!("coordinator didn't respond with ConfirmKeyPair msg: {msg:?}"),
|
||||
}
|
||||
message = Some(msg);
|
||||
} else {
|
||||
|
||||
@@ -23,8 +23,6 @@ mod sign;
|
||||
pub use sign::sign;
|
||||
|
||||
mod rotation;
|
||||
#[allow(unused_imports)]
|
||||
pub use rotation::rotate;
|
||||
|
||||
pub(crate) const COORDINATORS: usize = 4;
|
||||
pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
use zeroize::Zeroizing;
|
||||
use ciphersuite::{Ciphersuite, Ristretto, Secp256k1};
|
||||
use ciphersuite::Secp256k1;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{insecure_pair_from_name, NetworkId},
|
||||
@@ -64,7 +63,7 @@ async fn allocate_stake(
|
||||
) -> [u8; 32] {
|
||||
// get the call
|
||||
let tx =
|
||||
serai.sign(&pair, validator_sets::SeraiValidatorSets::allocate(network, amount), nonce, 0);
|
||||
serai.sign(pair, validator_sets::SeraiValidatorSets::allocate(network, amount), nonce, 0);
|
||||
publish_tx(serai, &tx).await
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ async fn deallocate_stake(
|
||||
) -> [u8; 32] {
|
||||
// get the call
|
||||
let tx =
|
||||
serai.sign(&pair, validator_sets::SeraiValidatorSets::deallocate(network, amount), nonce, 0);
|
||||
serai.sign(pair, validator_sets::SeraiValidatorSets::deallocate(network, amount), nonce, 0);
|
||||
publish_tx(serai, &tx).await
|
||||
}
|
||||
|
||||
@@ -95,8 +94,6 @@ async fn wait_till_next_epoch(serai: &Serai, current_epoch: u32) -> Session {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
println!("current session: {} ", session.0);
|
||||
}
|
||||
session
|
||||
}
|
||||
@@ -114,8 +111,7 @@ async fn new_set_events(
|
||||
let mut current_session = get_session(serai, current_block.hash(), network).await;
|
||||
|
||||
while current_session == session {
|
||||
let mut events =
|
||||
serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap();
|
||||
let events = serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap();
|
||||
if !events.is_empty() {
|
||||
return events;
|
||||
}
|
||||
@@ -127,16 +123,18 @@ async fn new_set_events(
|
||||
panic!("can't find the new set events for session: {} ", session.0);
|
||||
}
|
||||
|
||||
pub async fn rotate(
|
||||
processors: &mut Vec<Processor>,
|
||||
excluded: Processor,
|
||||
_: &[u8],
|
||||
_: &Zeroizing<<Ristretto as Ciphersuite>::F>,
|
||||
) {
|
||||
// accounts
|
||||
let pair1 = insecure_pair_from_name("Alice");
|
||||
let pair5 = insecure_pair_from_name("Eve");
|
||||
#[tokio::test]
|
||||
async fn set_rotation_test() {
|
||||
new_test(
|
||||
|mut processors: Vec<Processor>| async move {
|
||||
// exclude the last processor from keygen since we will add him later
|
||||
let excluded = processors.pop().unwrap();
|
||||
assert_eq!(processors.len(), COORDINATORS);
|
||||
|
||||
// genesis keygen
|
||||
let _ = key_gen::<Secp256k1>(&mut processors, Session(0)).await;
|
||||
|
||||
let pair5 = insecure_pair_from_name("Eve");
|
||||
let network = NetworkId::Bitcoin;
|
||||
let amount = Amount(1_000_000 * 10_u64.pow(8));
|
||||
let serai = processors[0].serai().await;
|
||||
@@ -150,40 +148,13 @@ pub async fn rotate(
|
||||
|
||||
// verfiy that coordinator received new_set
|
||||
let events = new_set_events(&serai, session, network).await;
|
||||
assert!(events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } }));
|
||||
assert!(
|
||||
events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } })
|
||||
);
|
||||
|
||||
// do the keygen
|
||||
// add the last participant & do the keygen
|
||||
processors.push(excluded);
|
||||
let _ = key_gen::<Secp256k1>(processors, session).await;
|
||||
|
||||
// pop 1 participant
|
||||
let block = deallocate_stake(&serai, network, amount, &pair1, 0).await;
|
||||
|
||||
// wait for this epoch to end
|
||||
let current_epoch = get_session(&serai, block, NetworkId::Serai).await;
|
||||
let session = wait_till_next_epoch(&serai, current_epoch.0).await;
|
||||
|
||||
// verfiy that coordinator received new_set
|
||||
let events = new_set_events(&serai, session, network).await;
|
||||
assert!(events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } }));
|
||||
|
||||
// do the keygen
|
||||
processors.remove(0);
|
||||
let _ = key_gen::<Secp256k1>(processors, session).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn set_rotation_test() {
|
||||
new_test(
|
||||
|mut processors: Vec<Processor>| async move {
|
||||
// exclude the last processor from keygen since we will add him later
|
||||
let excluded = processors.pop().unwrap();
|
||||
assert_eq!(processors.len(), COORDINATORS);
|
||||
|
||||
let (processor_is, substrate_key, _) =
|
||||
key_gen::<Secp256k1>(&mut processors, Session(0)).await;
|
||||
|
||||
rotate(&mut processors, excluded, &processor_is, &substrate_key).await;
|
||||
let _ = key_gen::<Secp256k1>(&mut processors, session).await;
|
||||
},
|
||||
true,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user