Staking pallet (#373)

* initial staking pallet

* add staking pallet to runtime

* support session rotation for serai

* optimizations & cleaning

* fix deny

* add serai network to initial networks

* a few tweaks & comments

* fix some pr comments

* Rewrite validator-sets with logarithmic algorithms

Uses the fact the underlying DB is sorted to achieve sorting of potential
validators by stake.

Removes release of deallocated stake for now.

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
akildemir
2023-10-10 13:53:24 +03:00
committed by GitHub
parent 2f45bba2d4
commit 98190b7b83
25 changed files with 635 additions and 149 deletions

View File

@@ -28,7 +28,11 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
let serai = serai().await;
let public_key = <Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut public.0.as_ref()).unwrap();
assert_eq!(
serai.get_validator_set_musig_key(set).await.unwrap().unwrap(),
serai
.get_validator_set_musig_key(set, serai.get_latest_block_hash().await.unwrap())
.await
.unwrap()
.unwrap(),
musig_key(set, &[public]).0
);
@@ -40,7 +44,11 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
let threshold_keys =
musig::<Ristretto>(&musig_context(set), &Zeroizing::new(secret_key), &[public_key]).unwrap();
assert_eq!(
serai.get_validator_set_musig_key(set).await.unwrap().unwrap(),
serai
.get_validator_set_musig_key(set, serai.get_latest_block_hash().await.unwrap())
.await
.unwrap()
.unwrap(),
threshold_keys.group_key().to_bytes()
);
@@ -66,7 +74,7 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
serai.get_key_gen_events(block).await.unwrap(),
vec![ValidatorSetsEvent::KeyGen { set, key_pair: key_pair.clone() }]
);
assert_eq!(serai.get_keys(set).await.unwrap(), Some(key_pair));
assert_eq!(serai.get_keys(set, block).await.unwrap(), Some(key_pair));
block
}