Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
Signed-off-by: Jamie <[email protected]>
  • Loading branch information
Dengjianping committed Feb 13, 2025
1 parent 9dfc35c commit e396ec5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub mod pallet {
+ Inspect<Self::AccountId>;
/// The origin for monetary governance
type MonetaryGovernanceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// The origin for removing collators
type RemoveCollatorOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// Minimum number of blocks per round
#[pallet::constant]
type MinBlocksPerRound: Get<u32>;
Expand Down Expand Up @@ -1407,7 +1409,9 @@ pub mod pallet {
origin: OriginFor<T>,
candidates: Vec<T::AccountId>,
) -> DispatchResultWithPostInfo {
frame_system::ensure_root(origin)?;
T::RemoveCollatorOrigin::ensure_origin(origin)?;

let mut collators = <CandidatePool<T>>::get();
for candidate in candidates {
let state = <CandidateInfo<T>>::get(&candidate).ok_or(Error::<T>::CandidateDNE)?;
// ensure!(
Expand All @@ -1419,14 +1423,14 @@ pub mod pallet {
// remove delegation from delegator state
let mut delegator =
DelegatorState::<T>::get(&bond.owner).ok_or(Error::<T>::InvalidState)?;

if let Some(remaining) = delegator.rm_delegation::<T>(&candidate) {
Self::delegation_remove_request_with_state(
&candidate,
&bond.owner,
&mut delegator,
);

if remaining.is_zero() {
// we do not remove the scheduled delegation requests from other collators
// since it is assumed that they were removed incrementally before only the
Expand Down Expand Up @@ -1467,12 +1471,16 @@ pub mod pallet {
<BottomDelegations<T>>::remove(&candidate);
let new_total_staked = <Total<T>>::get().saturating_sub(total_backing);
<Total<T>>::put(new_total_staked);

collators.remove(&Bond::from_owner(candidate.clone()));

Self::deposit_event(Event::CandidateLeft {
ex_candidate: candidate,
unlocked_amount: total_backing,
new_total_amt_locked: new_total_staked,
});
}
<CandidatePool<T>>::put(collators);
Ok(().into())
}
}
Expand Down
9 changes: 8 additions & 1 deletion pallets/parachain-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{Everything, LockIdentifier, OnFinalize, OnInitialize},
traits::{EitherOfDiverse, Everything, LockIdentifier, OnFinalize, OnInitialize},
};
use manta_primitives::types::BlockNumber;
use sp_core::H256;
Expand Down Expand Up @@ -125,10 +125,17 @@ parameter_types! {
pub const MinDelegatorStk: u128 = 5;
pub const MinDelegation: u128 = 3;
}

ord_parameter_types! {
pub const One: AccountId = 1;
}

impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type MonetaryGovernanceOrigin = frame_system::EnsureRoot<AccountId>;
type RemoveCollatorOrigin =
EitherOfDiverse<frame_system::EnsureRoot<AccountId>, EnsureSignedBy<One, AccountId>>;
type MinBlocksPerRound = MinBlocksPerRound;
type DefaultBlocksPerRound = DefaultBlocksPerRound;
type LeaveCandidatesDelay = LeaveCandidatesDelay;
Expand Down
5 changes: 5 additions & 0 deletions runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ impl Contains<RuntimeCall> for BaseFilter {
| pallet_parachain_staking::Call::schedule_candidate_bond_less{..}
| pallet_parachain_staking::Call::execute_candidate_bond_less{..}
| pallet_parachain_staking::Call::cancel_candidate_bond_less{..}
| pallet_parachain_staking::Call::force_go_offline_collators{..}
// Delegator extrinsics
| pallet_parachain_staking::Call::delegate{..}
| pallet_parachain_staking::Call::schedule_leave_delegators{..}
Expand Down Expand Up @@ -741,6 +742,10 @@ impl pallet_parachain_staking::Config for Runtime {
type Currency = Balances;
type BlockAuthor = AuthorInherent;
type MonetaryGovernanceOrigin = EnsureRoot<AccountId>;
type RemoveCollatorOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>,
>;
/// Minimum round length is 2 minutes (10 * 12 second block times)
type MinBlocksPerRound = ConstU32<10>;
/// Blocks per round
Expand Down
1 change: 1 addition & 0 deletions runtime/manta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ impl pallet_parachain_staking::Config for Runtime {
type Currency = Balances;
type BlockAuthor = AuthorInherent;
type MonetaryGovernanceOrigin = EnsureRoot<AccountId>;
type RemoveCollatorOrigin = EnsureRoot<AccountId>;
/// Minimum round length is 2 minutes (10 * 12 second block times)
type MinBlocksPerRound = ConstU32<10>;
/// Blocks per round
Expand Down

0 comments on commit e396ec5

Please sign in to comment.