-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate signer changes dynamically #978
Changes from all commits
4f6a1ba
f96e25a
b0c6016
dba0a95
842d108
a0299f7
d39cb86
d7c5c5f
5864614
426bca8
fc3b1ed
0942869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ pub const NETWORK_PARENT_KEY: &str = "NETWORK_PARENT_KEY_FOR_ENTROPY_"; | |
/// Total signers on the network with the parent key | ||
pub const TOTAL_SIGNERS: u8 = 3; | ||
|
||
/// Max signers, for bounding of total signers for benches, | ||
/// Can be changed but requires a re-run of benches | ||
pub const MAX_SIGNERS: u8 = 15; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/// Threshold for those signers | ||
pub const SIGNER_THRESHOLD: u8 = 2; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![allow(clippy::unused_unit)] | ||
|
||
use entropy_shared::MAX_SIGNERS; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
use sp_runtime::DispatchResult; | ||
|
@@ -56,7 +57,7 @@ pub mod module { | |
use super::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
pub trait Config: frame_system::Config + pallet_session::Config { | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The origin which may set filter. | ||
|
@@ -84,8 +85,11 @@ pub mod module { | |
assert!(self.total_signers >= self.threshold, "Threshold is larger then signer"); | ||
RequestLimit::<T>::put(self.request_limit); | ||
MaxInstructionsPerPrograms::<T>::put(self.max_instructions_per_programs); | ||
let signer_info = | ||
SignersSize { total_signers: self.total_signers, threshold: self.threshold }; | ||
let signer_info = SignersSize { | ||
total_signers: self.total_signers, | ||
threshold: self.threshold, | ||
last_session_change: 0, | ||
}; | ||
SignersInfo::<T>::put(signer_info); | ||
} | ||
} | ||
|
@@ -96,12 +100,23 @@ pub mod module { | |
ThresholdGreaterThenSigners, | ||
/// Threhsold has to be more than 0 | ||
ThrehsoldTooLow, | ||
/// Signers over max signers, can happen however needs a benchmark rerun | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What benchmark are you referring to here? If it's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any bench that we loop over the signers, a few, like confirm_jump_start, confirm_reshare, anything with confirm mainly because it has to check if the current signer is in the signers struct which is O(n) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JesseAbram so these actually don't scale with the number of signers. In the case of Maybe can you point me to where the |
||
TooManySigners, | ||
/// Signers can only change by one at a time | ||
SignerDiffTooLarge, | ||
/// Can only do one change per session | ||
OneChangePerSession, | ||
} | ||
|
||
/// Signer info for the next reshare | ||
#[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebug, TypeInfo, Default)] | ||
pub struct SignersSize { | ||
/// Next threshold amount | ||
pub threshold: u8, | ||
/// Total signers in signer party | ||
pub total_signers: u8, | ||
/// Last time it was changed (one change allowed per session) | ||
pub last_session_change: u32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A doccomment would be nice. If i understood right this is the session index number of the last session in which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya but then I would have to pull in sp-staking pallet, a whole new crate for one type does not seem worth it |
||
} | ||
|
||
#[pallet::event] | ||
|
@@ -137,7 +152,7 @@ pub mod module { | |
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(T::WeightInfo::change_request_limit())] | ||
#[pallet::weight( <T as Config>::WeightInfo::change_request_limit())] | ||
pub fn change_request_limit(origin: OriginFor<T>, request_limit: u32) -> DispatchResult { | ||
T::UpdateOrigin::ensure_origin(origin)?; | ||
RequestLimit::<T>::put(request_limit); | ||
|
@@ -146,7 +161,7 @@ pub mod module { | |
} | ||
|
||
#[pallet::call_index(1)] | ||
#[pallet::weight(T::WeightInfo::max_instructions_per_programs())] | ||
#[pallet::weight( <T as Config>::WeightInfo::max_instructions_per_programs())] | ||
pub fn change_max_instructions_per_programs( | ||
origin: OriginFor<T>, | ||
max_instructions_per_programs: u64, | ||
|
@@ -161,7 +176,7 @@ pub mod module { | |
|
||
/// Changes the threshold related parameters for signing. | ||
#[pallet::call_index(2)] | ||
#[pallet::weight(T::WeightInfo::change_signers_info())] | ||
#[pallet::weight( <T as Config>::WeightInfo::change_signers_info())] | ||
pub fn change_signers_info( | ||
origin: OriginFor<T>, | ||
total_signers: u8, | ||
|
@@ -170,7 +185,22 @@ pub mod module { | |
T::UpdateOrigin::ensure_origin(origin)?; | ||
ensure!(total_signers >= threshold, Error::<T>::ThresholdGreaterThenSigners); | ||
ensure!(threshold > 0, Error::<T>::ThrehsoldTooLow); | ||
let signer_info = SignersSize { total_signers, threshold }; | ||
ensure!(total_signers <= MAX_SIGNERS, Error::<T>::TooManySigners); | ||
|
||
let old_signer_info = Self::signers_info(); | ||
ensure!( | ||
old_signer_info.total_signers.abs_diff(total_signers) <= 1, | ||
Error::<T>::SignerDiffTooLarge | ||
); | ||
|
||
let current_session = pallet_session::Pallet::<T>::current_index(); | ||
ensure!( | ||
current_session > old_signer_info.last_session_change, | ||
Error::<T>::OneChangePerSession | ||
); | ||
|
||
let signer_info = | ||
SignersSize { total_signers, threshold, last_session_change: current_session }; | ||
SignersInfo::<T>::put(&signer_info); | ||
Self::deposit_event(Event::SignerInfoChanged { signer_info }); | ||
Ok(()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,13 @@ | |
|
||
#![cfg(test)] | ||
|
||
use super::*; | ||
use crate::SignersInfo; | ||
use entropy_shared::MAX_SIGNERS; | ||
use frame_support::{assert_noop, assert_ok}; | ||
use mock::*; | ||
use sp_runtime::traits::BadOrigin; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn request_limit_changed() { | ||
new_test_ext().execute_with(|| { | ||
|
@@ -65,8 +66,10 @@ fn max_instructions_per_programs_changed() { | |
#[test] | ||
fn signer_info_changed() { | ||
new_test_ext().execute_with(|| { | ||
let signer_info = SignersSize { total_signers: 5, threshold: 3 }; | ||
let new_signer_info = SignersSize { total_signers: 6, threshold: 4 }; | ||
pallet_session::CurrentIndex::<Runtime>::put(1); | ||
let signer_info = SignersSize { total_signers: 5, threshold: 3, last_session_change: 0 }; | ||
let new_signer_info = | ||
SignersSize { total_signers: 6, threshold: 4, last_session_change: 1 }; | ||
|
||
assert_eq!(Parameters::signers_info(), signer_info, "Inital signer info set"); | ||
|
||
|
@@ -99,5 +102,30 @@ fn signer_info_changed() { | |
Parameters::change_signers_info(RuntimeOrigin::root(), 0, 0), | ||
Error::<Runtime>::ThrehsoldTooLow, | ||
); | ||
|
||
// Fails too many signers | ||
assert_noop!( | ||
Parameters::change_signers_info(RuntimeOrigin::root(), MAX_SIGNERS + 1, 1), | ||
Error::<Runtime>::TooManySigners, | ||
); | ||
|
||
assert_noop!( | ||
Parameters::change_signers_info( | ||
RuntimeOrigin::root(), | ||
new_signer_info.total_signers + 2, | ||
signer_info.threshold | ||
), | ||
Error::<Runtime>::SignerDiffTooLarge, | ||
); | ||
SignersInfo::<Runtime>::put(new_signer_info); | ||
|
||
assert_noop!( | ||
Parameters::change_signers_info( | ||
RuntimeOrigin::root(), | ||
signer_info.total_signers, | ||
signer_info.threshold | ||
), | ||
Error::<Runtime>::OneChangePerSession, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If i understood right this tests that you cannot make a change when the current session is older than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed as per your previous comment, good catch |
||
); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -53,7 +53,7 @@ pub mod weights; | |||||
|
||||||
#[frame_support::pallet] | ||||||
pub mod pallet { | ||||||
use entropy_shared::{NETWORK_PARENT_KEY, TOTAL_SIGNERS, VERIFICATION_KEY_LENGTH}; | ||||||
use entropy_shared::{MAX_SIGNERS, NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH}; | ||||||
use frame_support::{ | ||||||
dispatch::{DispatchResultWithPostInfo, Pays}, | ||||||
pallet_prelude::*, | ||||||
|
@@ -286,8 +286,8 @@ pub mod pallet { | |||||
/// Allows validators to signal a successful network jumpstart | ||||||
#[pallet::call_index(1)] | ||||||
#[pallet::weight({ | ||||||
<T as Config>::WeightInfo::confirm_jump_start_confirm(TOTAL_SIGNERS as u32) | ||||||
.max(<T as Config>::WeightInfo::confirm_jump_start_done(TOTAL_SIGNERS as u32)) | ||||||
<T as Config>::WeightInfo::confirm_jump_start_confirm(MAX_SIGNERS as u32) | ||||||
.max(<T as Config>::WeightInfo::confirm_jump_start_done(MAX_SIGNERS as u32)) | ||||||
})] | ||||||
pub fn confirm_jump_start( | ||||||
origin: OriginFor<T>, | ||||||
|
@@ -327,7 +327,8 @@ pub mod pallet { | |||||
// ensure that registration was indeed successful. | ||||||
// | ||||||
// If it fails we'll need to allow another jumpstart. | ||||||
if jump_start_info.confirmations.len() == (TOTAL_SIGNERS as usize - 1) { | ||||||
let signers_amount = pallet_parameters::Pallet::<T>::signers_info().total_signers; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For consistency |
||||||
if jump_start_info.confirmations.len() == (signers_amount as usize - 1) { | ||||||
// registration finished, lock call | ||||||
jump_start_info.confirmations.push(validator_stash); | ||||||
let confirmations = jump_start_info.confirmations.len(); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar thing here, if I'm thinking of the right extrinsic it's constant time