mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-12 05:59:23 +00:00
bug fixes
This commit is contained in:
@@ -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,51 +123,6 @@ 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");
|
||||
|
||||
let network = NetworkId::Bitcoin;
|
||||
let amount = Amount(1_000_000 * 10_u64.pow(8));
|
||||
let serai = processors[0].serai().await;
|
||||
|
||||
// add the last participant into validator set for btc network
|
||||
let block = allocate_stake(&serai, network, amount, &pair5, 0).await;
|
||||
|
||||
// wait until next session to see the effect on coordinator
|
||||
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.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(
|
||||
@@ -180,10 +131,30 @@ async fn set_rotation_test() {
|
||||
let excluded = processors.pop().unwrap();
|
||||
assert_eq!(processors.len(), COORDINATORS);
|
||||
|
||||
let (processor_is, substrate_key, _) =
|
||||
key_gen::<Secp256k1>(&mut processors, Session(0)).await;
|
||||
// genesis keygen
|
||||
let _ = key_gen::<Secp256k1>(&mut processors, Session(0)).await;
|
||||
|
||||
rotate(&mut processors, excluded, &processor_is, &substrate_key).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;
|
||||
|
||||
// add the last participant into validator set for btc network
|
||||
let block = allocate_stake(&serai, network, amount, &pair5, 0).await;
|
||||
|
||||
// wait until next session to see the effect on coordinator
|
||||
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 } })
|
||||
);
|
||||
|
||||
// add the last participant & do the keygen
|
||||
processors.push(excluded);
|
||||
let _ = key_gen::<Secp256k1>(&mut processors, session).await;
|
||||
},
|
||||
true,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user