-
Notifications
You must be signed in to change notification settings - Fork 1
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
No unbonding when signer or next signer #1031
Merged
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a3f6c12
No unbonding when signer or next signer
JesseAbram cef400f
test for chill and unbond
JesseAbram 612efcf
fix bench
JesseAbram 8af8e2e
add unbond and chill benches
JesseAbram 4c8e089
update benchmarks
JesseAbram 8edf952
Apply suggestions from code review
JesseAbram 1730efb
clean
JesseAbram ae86a75
lint
JesseAbram e83597d
changelog
JesseAbram 13af928
clean
JesseAbram f185d77
add in nominating check
JesseAbram b3d4f2c
Update pallets/staking/src/benchmarking.rs
JesseAbram 135632f
add tests for nominators
JesseAbram f689ca7
clean function
JesseAbram 468418a
fmt
JesseAbram 35d1aab
fmt
JesseAbram 316b6c8
Merge branch 'master' of github.com:entropyxyz/entropy-core into no-u…
JesseAbram cfa6e3f
fmt
JesseAbram c83c99b
Apply suggestions from code review
JesseAbram 069c9ce
clean
JesseAbram 2f9aac0
Merge branch 'master' of github.com:entropyxyz/entropy-core into no-u…
JesseAbram 82c3314
add nominator to benchmarks
JesseAbram fc381d8
fmt
JesseAbram ba76d4b
Merge branch 'master' of github.com:entropyxyz/entropy-core into no-u…
JesseAbram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,8 @@ pub mod pallet { | |
NotNextSigner, | ||
ReshareNotInProgress, | ||
AlreadyConfirmed, | ||
NoUnbodingWhenSigner, | ||
JesseAbram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NoUnbodingWhenNextSigner, | ||
JesseAbram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[pallet::event] | ||
|
@@ -397,9 +399,74 @@ pub mod pallet { | |
Ok(()) | ||
} | ||
|
||
/// Wraps's substrate withdraw unbonded but clears extra state if fully unbonded | ||
/// Wraps's substrate unbond but checks to make targeted validator sure not signer or next signe | ||
JesseAbram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[pallet::call_index(2)] | ||
#[pallet::weight(<T as Config>::WeightInfo::withdraw_unbonded())] | ||
#[pallet::weight(<T as Config>::WeightInfo::unbond(MAX_SIGNERS as u32))] | ||
pub fn unbond( | ||
origin: OriginFor<T>, | ||
#[pallet::compact] value: BalanceOf<T>, | ||
) -> DispatchResultWithPostInfo { | ||
let controller = ensure_signed(origin.clone())?; | ||
let ledger = | ||
pallet_staking::Pallet::<T>::ledger(StakingAccount::Controller(controller.clone())) | ||
.map_err(|_| Error::<T>::NoThresholdKey)?; | ||
|
||
let validator_id = <T as pallet_session::Config>::ValidatorId::try_from(ledger.stash) | ||
.or(Err(Error::<T>::InvalidValidatorId))?; | ||
|
||
let signers = Self::signers(); | ||
ensure!(!signers.contains(&validator_id), Error::<T>::NoUnbodingWhenSigner); | ||
|
||
let next_signers = Self::next_signers(); | ||
if next_signers.is_some() { | ||
ensure!( | ||
!next_signers | ||
.ok_or(Error::<T>::ReshareNotInProgress)? | ||
.next_signers | ||
.contains(&validator_id), | ||
Error::<T>::NoUnbodingWhenNextSigner | ||
); | ||
} | ||
|
||
pallet_staking::Pallet::<T>::unbond(origin, value)?; | ||
|
||
Ok(Some(<T as Config>::WeightInfo::unbond(signers.len() as u32)).into()) | ||
} | ||
|
||
/// Wraps's substrate chill but checks to make targeted validator sure not signer or next signer | ||
JesseAbram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[pallet::call_index(3)] | ||
#[pallet::weight(<T as Config>::WeightInfo::chill(MAX_SIGNERS as u32))] | ||
pub fn chill(origin: OriginFor<T>) -> DispatchResultWithPostInfo { | ||
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. Call it fate, but I was listening to this while reviewing 😆 |
||
let controller = ensure_signed(origin.clone())?; | ||
let ledger = | ||
pallet_staking::Pallet::<T>::ledger(StakingAccount::Controller(controller.clone())) | ||
.map_err(|_| Error::<T>::NoThresholdKey)?; | ||
HCastano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let validator_id = <T as pallet_session::Config>::ValidatorId::try_from(ledger.stash) | ||
.or(Err(Error::<T>::InvalidValidatorId))?; | ||
|
||
let signers = Self::signers(); | ||
ensure!(!signers.contains(&validator_id), Error::<T>::NoUnbodingWhenSigner); | ||
|
||
let next_signers = Self::next_signers(); | ||
if next_signers.is_some() { | ||
ensure!( | ||
!next_signers | ||
.ok_or(Error::<T>::ReshareNotInProgress)? | ||
.next_signers | ||
.contains(&validator_id), | ||
Error::<T>::NoUnbodingWhenNextSigner | ||
); | ||
} | ||
|
||
pallet_staking::Pallet::<T>::chill(origin)?; | ||
|
||
Ok(Some(<T as Config>::WeightInfo::chill(signers.len() as u32)).into()) | ||
} | ||
|
||
/// Wraps's substrate withdraw unbonded but clears extra state if fully unbonded | ||
JesseAbram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[pallet::call_index(4)] | ||
#[pallet::weight(<T as Config>::WeightInfo::withdraw_unbonded(MAX_SIGNERS as u32))] | ||
pub fn withdraw_unbonded( | ||
origin: OriginFor<T>, | ||
num_slashing_spans: u32, | ||
|
@@ -412,6 +479,19 @@ pub mod pallet { | |
let validator_id = <T as pallet_session::Config>::ValidatorId::try_from(ledger.stash) | ||
.or(Err(Error::<T>::InvalidValidatorId))?; | ||
|
||
let signers = Self::signers(); | ||
ensure!(!signers.contains(&validator_id), Error::<T>::NoUnbodingWhenSigner); | ||
let next_signers = Self::next_signers(); | ||
if next_signers.is_some() { | ||
ensure!( | ||
!next_signers | ||
.ok_or(Error::<T>::ReshareNotInProgress)? | ||
.next_signers | ||
.contains(&validator_id), | ||
Error::<T>::NoUnbodingWhenNextSigner | ||
); | ||
} | ||
|
||
pallet_staking::Pallet::<T>::withdraw_unbonded(origin, num_slashing_spans)?; | ||
// TODO: do not allow unbonding of validator if not enough validators https://github.com/entropyxyz/entropy-core/issues/942 | ||
if pallet_staking::Pallet::<T>::bonded(&controller).is_none() { | ||
|
@@ -421,15 +501,15 @@ pub mod pallet { | |
IsValidatorSynced::<T>::remove(&validator_id); | ||
Self::deposit_event(Event::NodeInfoRemoved(controller)); | ||
} | ||
Ok(().into()) | ||
Ok(Some(<T as Config>::WeightInfo::withdraw_unbonded(signers.len() as u32)).into()) | ||
} | ||
|
||
/// Wrap's Substrate's `staking_pallet::validate()` extrinsic, but enforces that | ||
/// information about a validator's threshold server is provided. | ||
/// | ||
/// Note that - just like the original `validate()` extrinsic - the effects of this are | ||
/// only applied in the following era. | ||
#[pallet::call_index(3)] | ||
#[pallet::call_index(5)] | ||
#[pallet::weight(<T as Config>::WeightInfo::validate())] | ||
pub fn validate( | ||
origin: OriginFor<T>, | ||
|
@@ -468,7 +548,7 @@ pub mod pallet { | |
|
||
/// Let a validator declare if their kvdb is synced or not synced | ||
/// `synced`: State of validator's kvdb | ||
#[pallet::call_index(4)] | ||
#[pallet::call_index(6)] | ||
#[pallet::weight(<T as Config>::WeightInfo::declare_synced())] | ||
pub fn declare_synced(origin: OriginFor<T>, synced: bool) -> DispatchResult { | ||
let who = ensure_signed(origin.clone())?; | ||
|
@@ -478,7 +558,7 @@ pub mod pallet { | |
Ok(()) | ||
} | ||
|
||
#[pallet::call_index(5)] | ||
#[pallet::call_index(7)] | ||
#[pallet::weight(({ | ||
<T as Config>::WeightInfo::confirm_key_reshare_confirmed(MAX_SIGNERS as u32) | ||
.max(<T as Config>::WeightInfo::confirm_key_reshare_completed()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HCastano marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you take the body of this (and all the other benches added in this PR) and manually RustFmt it using the Rust Playground? This isn't done by the
fmt
script since it's since a decl macro.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.
Bumping this