MAX_VALIDATORS_PER_SET -> MAX_KEY_SHARES_PER_SET

This commit is contained in:
Luke Parker 2023-10-13 00:50:07 -04:00
parent ed7300b406
commit 013a0cddfc
No known key found for this signature in database
3 changed files with 10 additions and 10 deletions

View file

@ -143,7 +143,7 @@ parameter_types! {
NORMAL_DISPATCH_RATIO, NORMAL_DISPATCH_RATIO,
); );
pub const MaxAuthorities: u32 = validator_sets::primitives::MAX_VALIDATORS_PER_SET; pub const MaxAuthorities: u32 = validator_sets::primitives::MAX_KEY_SHARES_PER_SET;
} }
pub struct CallFilter; pub struct CallFilter;

View file

@ -77,7 +77,7 @@ pub mod pallet {
_, _,
Identity, Identity,
NetworkId, NetworkId,
BoundedVec<Public, ConstU32<{ MAX_VALIDATORS_PER_SET }>>, BoundedVec<Public, ConstU32<{ MAX_KEY_SHARES_PER_SET }>>,
ValueQuery, ValueQuery,
>; >;
/// The validators selected to be in-set, yet with the ability to perform a check for presence. /// The validators selected to be in-set, yet with the ability to perform a check for presence.
@ -195,15 +195,15 @@ pub mod pallet {
top = Some(key_shares); top = Some(key_shares);
} }
if key_shares > u64::from(MAX_VALIDATORS_PER_SET) { if key_shares > u64::from(MAX_KEY_SHARES_PER_SET) {
break; break;
} }
} }
let Some(top) = top else { return false }; let Some(top) = top else { return false };
// key_shares may be over MAX_VALIDATORS_PER_SET, which will cause an off-chain reduction of // key_shares may be over MAX_KEY_SHARES_PER_SET, which will cause an off-chain reduction of
// each validator's key shares until their sum is MAX_VALIDATORS_PER_SET // each validator's key shares until their sum is MAX_KEY_SHARES_PER_SET
// That isn't modeled here, allowing an inaccuracy in an extreme edge case // That isn't modeled here, allowing an inaccuracy in an extreme edge case
// This may cause mis-reporting as BFT when not BFT (TODO: Investigate impact of this) // This may cause mis-reporting as BFT when not BFT (TODO: Investigate impact of this)
(top * 3) < key_shares (top * 3) < key_shares
@ -258,7 +258,7 @@ pub mod pallet {
let mut in_set_key = InSet::<T>::final_prefix().to_vec(); let mut in_set_key = InSet::<T>::final_prefix().to_vec();
in_set_key.extend(network.encode()); in_set_key.extend(network.encode());
assert!(matches!( assert!(matches!(
sp_io::storage::clear_prefix(&in_set_key, Some(MAX_VALIDATORS_PER_SET)), sp_io::storage::clear_prefix(&in_set_key, Some(MAX_KEY_SHARES_PER_SET)),
sp_io::KillStorageResult::AllRemoved(_) sp_io::KillStorageResult::AllRemoved(_)
)); ));
} }
@ -268,13 +268,13 @@ pub mod pallet {
let mut iter = SortedAllocationsIter::<T>::new(network); let mut iter = SortedAllocationsIter::<T>::new(network);
let mut participants = vec![]; let mut participants = vec![];
let mut key_shares = 0; let mut key_shares = 0;
while key_shares < u64::from(MAX_VALIDATORS_PER_SET) { while key_shares < u64::from(MAX_KEY_SHARES_PER_SET) {
let Some((key, amount)) = iter.next() else { break }; let Some((key, amount)) = iter.next() else { break };
InSet::<T>::set(Self::in_set_key(network, key), Some(())); InSet::<T>::set(Self::in_set_key(network, key), Some(()));
participants.push(key); participants.push(key);
// This can technically set key_shares to a value exceeding MAX_VALIDATORS_PER_SET // This can technically set key_shares to a value exceeding MAX_KEY_SHARES_PER_SET
// Off-chain, the key shares per validator will be accordingly adjusted // Off-chain, the key shares per validator will be accordingly adjusted
key_shares += amount.0 / allocation_per_key_share; key_shares += amount.0 / allocation_per_key_share;
} }

View file

@ -15,8 +15,8 @@ use sp_std::vec::Vec;
use serai_primitives::NetworkId; use serai_primitives::NetworkId;
/// The maximum amount of validators per set. /// The maximum amount of key shares per set.
pub const MAX_VALIDATORS_PER_SET: u32 = 150; pub const MAX_KEY_SHARES_PER_SET: u32 = 150;
// Support keys up to 96 bytes (BLS12-381 G2). // Support keys up to 96 bytes (BLS12-381 G2).
const MAX_KEY_LEN: u32 = 96; const MAX_KEY_LEN: u32 = 96;