mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Give one weight per key share to validators in Tributary
This commit is contained in:
@@ -9,7 +9,7 @@ use serai_client::{
|
|||||||
SeraiError, Block, Serai,
|
SeraiError, Block, Serai,
|
||||||
primitives::{BlockHash, NetworkId},
|
primitives::{BlockHash, NetworkId},
|
||||||
validator_sets::{
|
validator_sets::{
|
||||||
primitives::{ValidatorSet, KeyPair},
|
primitives::{ValidatorSet, KeyPair, amortize_excess_key_shares},
|
||||||
ValidatorSetsEvent,
|
ValidatorSetsEvent,
|
||||||
},
|
},
|
||||||
in_instructions::InInstructionsEvent,
|
in_instructions::InInstructionsEvent,
|
||||||
@@ -61,6 +61,23 @@ async fn handle_new_set<D: Db, CNT: Clone + Fn(&mut D, TributarySpec)>(
|
|||||||
.await?
|
.await?
|
||||||
.expect("NewSet for set which doesn't exist");
|
.expect("NewSet for set which doesn't exist");
|
||||||
|
|
||||||
|
let allocation_per_key_share = serai
|
||||||
|
.get_allocation_per_key_share(set.network, block.hash())
|
||||||
|
.await?
|
||||||
|
.expect("NewSet for set which didn't have an allocation per key share")
|
||||||
|
.0;
|
||||||
|
|
||||||
|
let mut set_data = vec![];
|
||||||
|
for participant in set_participants {
|
||||||
|
let allocation = serai
|
||||||
|
.get_allocation(set.network, participant, block.hash())
|
||||||
|
.await?
|
||||||
|
.expect("validator selected for set yet didn't have an allocation")
|
||||||
|
.0;
|
||||||
|
set_data.push((participant, allocation / allocation_per_key_share));
|
||||||
|
}
|
||||||
|
amortize_excess_key_shares(&mut set_data);
|
||||||
|
|
||||||
let time = if let Ok(time) = block.time() {
|
let time = if let Ok(time) = block.time() {
|
||||||
time
|
time
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +99,7 @@ async fn handle_new_set<D: Db, CNT: Clone + Fn(&mut D, TributarySpec)>(
|
|||||||
const SUBSTRATE_TO_TRIBUTARY_TIME_DELAY: u64 = 120;
|
const SUBSTRATE_TO_TRIBUTARY_TIME_DELAY: u64 = 120;
|
||||||
let time = time + SUBSTRATE_TO_TRIBUTARY_TIME_DELAY;
|
let time = time + SUBSTRATE_TO_TRIBUTARY_TIME_DELAY;
|
||||||
|
|
||||||
let spec = TributarySpec::new(block.hash(), time, set, set_participants);
|
let spec = TributarySpec::new(block.hash(), time, set, set_data);
|
||||||
create_new_tributary(db, spec.clone());
|
create_new_tributary(db, spec.clone());
|
||||||
} else {
|
} else {
|
||||||
log::info!("not present in set {:?}", set);
|
log::info!("not present in set {:?}", set);
|
||||||
|
|||||||
@@ -51,16 +51,15 @@ impl TributarySpec {
|
|||||||
serai_block: [u8; 32],
|
serai_block: [u8; 32],
|
||||||
start_time: u64,
|
start_time: u64,
|
||||||
set: ValidatorSet,
|
set: ValidatorSet,
|
||||||
set_participants: Vec<PublicKey>,
|
set_participants: Vec<(PublicKey, u64)>,
|
||||||
) -> TributarySpec {
|
) -> TributarySpec {
|
||||||
let mut validators = vec![];
|
let mut validators = vec![];
|
||||||
for participant in set_participants {
|
for (participant, shares) in set_participants {
|
||||||
// TODO: Ban invalid keys from being validators on the Serai side
|
// TODO: Ban invalid keys from being validators on the Serai side
|
||||||
// (make coordinator key a session key?)
|
// (make coordinator key a session key?)
|
||||||
let participant = <Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut participant.0.as_ref())
|
let participant = <Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut participant.0.as_ref())
|
||||||
.expect("invalid key registered as participant");
|
.expect("invalid key registered as participant");
|
||||||
// TODO: Give one weight on Tributary per bond instance
|
validators.push((participant, shares));
|
||||||
validators.push((participant, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { serai_block, start_time, set, validators }
|
Self { serai_block, start_time, set, validators }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use sp_core::sr25519::{Public, Signature};
|
use sp_core::sr25519::{Public, Signature};
|
||||||
|
|
||||||
use serai_runtime::{validator_sets, ValidatorSets, Runtime};
|
use serai_runtime::{primitives::Amount, validator_sets, ValidatorSets, Runtime};
|
||||||
pub use validator_sets::primitives;
|
pub use validator_sets::primitives;
|
||||||
use primitives::{Session, ValidatorSet, KeyPair};
|
use primitives::{Session, ValidatorSet, KeyPair};
|
||||||
|
|
||||||
@@ -47,6 +47,23 @@ impl Serai {
|
|||||||
self.storage(PALLET, "Participants", Some(vec![scale_value(network)]), at_hash).await
|
self.storage(PALLET, "Participants", Some(vec![scale_value(network)]), at_hash).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_allocation_per_key_share(
|
||||||
|
&self,
|
||||||
|
network: NetworkId,
|
||||||
|
at_hash: [u8; 32],
|
||||||
|
) -> Result<Option<Amount>, SeraiError> {
|
||||||
|
self.storage(PALLET, "AllocationPerKeyShare", Some(vec![scale_value(network)]), at_hash).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_allocation(
|
||||||
|
&self,
|
||||||
|
network: NetworkId,
|
||||||
|
key: Public,
|
||||||
|
at_hash: [u8; 32],
|
||||||
|
) -> Result<Option<Amount>, SeraiError> {
|
||||||
|
self.storage(PALLET, "Allocations", Some(vec![scale_value(network), scale_value(key)]), at_hash).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_validator_set_musig_key(
|
pub async fn get_validator_set_musig_key(
|
||||||
&self,
|
&self,
|
||||||
set: ValidatorSet,
|
set: ValidatorSet,
|
||||||
|
|||||||
Reference in New Issue
Block a user