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,
|
nonce: u32,
|
||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
// get the call
|
// 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
|
publish_tx(serai, &tx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +86,6 @@ pub async fn deallocate_stake(
|
|||||||
nonce: u32,
|
nonce: u32,
|
||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
// get the call
|
// 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
|
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
|
// we start the chain with 4 default participants that has a single key share each
|
||||||
participants.sort();
|
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
|
// add 1 participant & verify
|
||||||
let hash =
|
let hash =
|
||||||
@@ -190,7 +190,7 @@ async fn validator_set_rotation() {
|
|||||||
&serai,
|
&serai,
|
||||||
network,
|
network,
|
||||||
get_active_session(&serai, network, hash).await,
|
get_active_session(&serai, network, hash).await,
|
||||||
&participants,
|
participants,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ async fn validator_set_rotation() {
|
|||||||
participants.swap_remove(participants.iter().position(|k| *k == pair2.public()).unwrap());
|
participants.swap_remove(participants.iter().position(|k| *k == pair2.public()).unwrap());
|
||||||
let active_session = get_active_session(&serai, network, hash).await;
|
let active_session = get_active_session(&serai, network, hash).await;
|
||||||
participants.sort();
|
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
|
// check pending deallocations
|
||||||
let pending = serai
|
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
|
// If not Serai, check the prior session had its keys cleared, which happens once its
|
||||||
// retired
|
// retired
|
||||||
return (network == NetworkId::Serai) ||
|
return (network == NetworkId::Serai) ||
|
||||||
(Keys::<T>::contains_key(ValidatorSet {
|
(!Keys::<T>::contains_key(ValidatorSet {
|
||||||
network,
|
network,
|
||||||
session: Session(current_session.0 - 1),
|
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.0 .0, substrate_key);
|
||||||
assert_eq!(&key_pair.1, &network_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);
|
message = Some(msg);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ mod sign;
|
|||||||
pub use sign::sign;
|
pub use sign::sign;
|
||||||
|
|
||||||
mod rotation;
|
mod rotation;
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use rotation::rotate;
|
|
||||||
|
|
||||||
pub(crate) const COORDINATORS: usize = 4;
|
pub(crate) const COORDINATORS: usize = 4;
|
||||||
pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1;
|
pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
|
|
||||||
use zeroize::Zeroizing;
|
use ciphersuite::Secp256k1;
|
||||||
use ciphersuite::{Ciphersuite, Ristretto, Secp256k1};
|
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{insecure_pair_from_name, NetworkId},
|
primitives::{insecure_pair_from_name, NetworkId},
|
||||||
@@ -64,7 +63,7 @@ async fn allocate_stake(
|
|||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
// get the call
|
// get the call
|
||||||
let tx =
|
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
|
publish_tx(serai, &tx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ async fn deallocate_stake(
|
|||||||
) -> [u8; 32] {
|
) -> [u8; 32] {
|
||||||
// get the call
|
// get the call
|
||||||
let tx =
|
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
|
publish_tx(serai, &tx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,8 +94,6 @@ async fn wait_till_next_epoch(serai: &Serai, current_epoch: u32) -> Session {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("current session: {} ", session.0);
|
|
||||||
}
|
}
|
||||||
session
|
session
|
||||||
}
|
}
|
||||||
@@ -114,8 +111,7 @@ async fn new_set_events(
|
|||||||
let mut current_session = get_session(serai, current_block.hash(), network).await;
|
let mut current_session = get_session(serai, current_block.hash(), network).await;
|
||||||
|
|
||||||
while current_session == session {
|
while current_session == session {
|
||||||
let mut events =
|
let events = serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap();
|
||||||
serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap();
|
|
||||||
if !events.is_empty() {
|
if !events.is_empty() {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@@ -127,51 +123,6 @@ async fn new_set_events(
|
|||||||
panic!("can't find the new set events for session: {} ", session.0);
|
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]
|
#[tokio::test]
|
||||||
async fn set_rotation_test() {
|
async fn set_rotation_test() {
|
||||||
new_test(
|
new_test(
|
||||||
@@ -180,10 +131,30 @@ async fn set_rotation_test() {
|
|||||||
let excluded = processors.pop().unwrap();
|
let excluded = processors.pop().unwrap();
|
||||||
assert_eq!(processors.len(), COORDINATORS);
|
assert_eq!(processors.len(), COORDINATORS);
|
||||||
|
|
||||||
let (processor_is, substrate_key, _) =
|
// genesis keygen
|
||||||
key_gen::<Secp256k1>(&mut processors, Session(0)).await;
|
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,
|
true,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user