Skip to content

Commit 4424c13

Browse files
authored
Merge pull request #669 from Cerebellum-Network/release/v7.3.12.1
Changes for fixing nomination pool withdraw issue
2 parents 81b9e26 + 8429891 commit 4424c13

File tree

9 files changed

+216
-9
lines changed

9 files changed

+216
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- [C] Changes is `Cere` Runtime
1111
- [D] Changes is `Cere Dev` Runtime
1212

13+
## [7.3.12]
14+
15+
- [C,D] Fix Nomination Pool withdrawal issue.
16+
1317
## [7.3.11]
1418

1519
- [C,D] Fixed low Transaction fee issue, removed deprecated dependencies and implemented.

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ members = [
2121
"pallets/erc721",
2222
"pallets/ddc-clusters-gov",
2323
"pallets/origins",
24+
"pallets/pool-withdrawal-fix",
2425
"pallets/fee-handler",
2526
"primitives",
2627
"runtime/cere",
@@ -197,6 +198,7 @@ pallet-ddc-staking = { path = "pallets/ddc-staking", default-features = false }
197198
pallet-erc20 = { path = "pallets/erc20", default-features = false }
198199
pallet-erc721 = { path = "pallets/erc721", default-features = false }
199200
pallet-origins = { path = "pallets/origins", default-features = false }
201+
pallet-pool-withdrawal-fix = { path = "pallets/pool-withdrawal-fix", default-features = false }
200202
pallet-fee-handler = { path = "pallets/fee-handler", default-features = false }
201203

202204
# Hyperbridge
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[package]
2+
name = "pallet-pool-withdrawal-fix"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
homepage.workspace = true
7+
license.workspace = true
8+
readme.workspace = true
9+
repository.workspace = true
10+
11+
[dependencies]
12+
# 3rd-party dependencies
13+
codec = { workspace = true }
14+
scale-info = { workspace = true }
15+
serde = { workspace = true }
16+
17+
# Substrate dependencies
18+
frame-benchmarking = { workspace = true, optional = true }
19+
frame-support = { workspace = true }
20+
frame-system = { workspace = true }
21+
sp-core = { workspace = true }
22+
sp-runtime = { workspace = true }
23+
sp-staking = { workspace = true }
24+
sp-std = { workspace = true }
25+
26+
[features]
27+
default = ["std"]
28+
std = [
29+
"codec/std",
30+
"frame-benchmarking/std",
31+
"frame-support/std",
32+
"frame-system/std",
33+
"scale-info/std",
34+
"sp-runtime/std",
35+
"sp-std/std",
36+
"sp-core/std",
37+
"serde/std",
38+
"sp-staking/std",
39+
]
40+
runtime-benchmarks = [
41+
"frame-benchmarking/runtime-benchmarks",
42+
"frame-support/runtime-benchmarks",
43+
"frame-system/runtime-benchmarks",
44+
"sp-runtime/runtime-benchmarks",
45+
]
46+
try-runtime = [
47+
"frame-support/try-runtime",
48+
"frame-system/try-runtime",
49+
]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//! # Pool Withdrawal Fix Pallet
2+
//!
3+
//! A pallet for handling pool withdrawal operations through delegation pallet connector.
4+
//! This pallet provides withdrawal functionality that can be called by root or governance.
5+
6+
#![cfg_attr(not(feature = "std"), no_std)]
7+
8+
use frame_support::pallet_prelude::Weight;
9+
pub use pallet::*;
10+
11+
#[frame_support::pallet]
12+
pub mod pallet {
13+
use frame_support::{
14+
pallet_prelude::*,
15+
traits::{Currency, EnsureOrigin, LockableCurrency},
16+
};
17+
use frame_system::pallet_prelude::*;
18+
use sp_staking::OnStakingUpdate;
19+
20+
use crate::WeightInfo;
21+
22+
pub type BalanceOf<T> =
23+
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
24+
25+
#[pallet::pallet]
26+
pub struct Pallet<T>(_);
27+
28+
/// Configure the pallet by specifying the parameters and types on which it depends.
29+
#[pallet::config]
30+
pub trait Config: frame_system::Config {
31+
/// Because this pallet emits events, it depends on the runtime's definition of an event.
32+
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
33+
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>;
34+
/// Integrate Delegated Pallet
35+
type DelegationPalletConnector: OnStakingUpdate<Self::AccountId, BalanceOf<Self>>;
36+
/// Governance origin for withdrawal calls
37+
type GovernanceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
38+
/// Type representing the weight of this pallet
39+
type WeightInfo: WeightInfo;
40+
}
41+
42+
/// Pallets use events to inform users when important changes are made.
43+
/// https://docs.substrate.io/main-docs/build/events-errors/
44+
#[pallet::event]
45+
#[pallet::generate_deposit(pub(super) fn deposit_event)]
46+
pub enum Event<T: Config> {
47+
/// Withdrawal was called for a stash account. [stash_account, amount]
48+
WithdrawCalled { stash_account: T::AccountId, amount: BalanceOf<T> },
49+
}
50+
51+
#[pallet::error]
52+
pub enum Error<T> {
53+
/// Withdrawal failed due to insufficient balance or other staking constraints.
54+
WithdrawalFailed,
55+
}
56+
57+
/// Dispatchable functions allows users to interact with the pallet and invoke state changes.
58+
/// These functions materialize as "extrinsics", which are often compared to transactions.
59+
/// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
60+
#[pallet::call]
61+
impl<T: Config> Pallet<T> {
62+
/// Call withdrawal for a stash account through the delegation pallet connector.
63+
/// This function can be called by root or governance.
64+
#[pallet::call_index(0)]
65+
#[pallet::weight(T::WeightInfo::call_withdraw())]
66+
pub fn call_withdraw(
67+
origin: OriginFor<T>,
68+
stash_account: T::AccountId,
69+
amount: BalanceOf<T>,
70+
) -> DispatchResult {
71+
T::GovernanceOrigin::ensure_origin(origin)?;
72+
73+
// Call the delegation pallet connector to handle withdrawal
74+
T::DelegationPalletConnector::on_withdraw(&stash_account, amount);
75+
76+
// Emit an event.
77+
Self::deposit_event(Event::WithdrawCalled { stash_account, amount });
78+
79+
Ok(())
80+
}
81+
}
82+
}
83+
84+
/// Weight functions needed for pallet_pool_withdrawal_fix.
85+
pub trait WeightInfo {
86+
fn call_withdraw() -> Weight;
87+
}
88+
89+
/// Default weight implementation for the pallet.
90+
impl WeightInfo for () {
91+
fn call_withdraw() -> Weight {
92+
Weight::from_parts(10_000, 0)
93+
}
94+
}

runtime/cere-dev/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pallet-erc20 = { workspace = true }
107107
pallet-erc721 = { workspace = true }
108108
pallet-fee-handler = { workspace = true }
109109
pallet-origins = { workspace = true }
110+
pallet-pool-withdrawal-fix = { workspace = true }
110111

111112
# Hyperbridge Depedencies
112113
anyhow = { workspace = true }
@@ -206,6 +207,7 @@ std = [
206207
"pallet-ddc-clusters-gov/std",
207208
"sp-arithmetic/std",
208209
"pallet-origins/std",
210+
"pallet-pool-withdrawal-fix/std",
209211
"pallet-hyperbridge/std",
210212
"ismp/std",
211213
"pallet-ismp/std",
@@ -269,6 +271,7 @@ runtime-benchmarks = [
269271
"pallet-preimage/runtime-benchmarks",
270272
"pallet-ddc-clusters-gov/runtime-benchmarks",
271273
"pallet-origins/runtime-benchmarks",
274+
"pallet-pool-withdrawal-fix/runtime-benchmarks",
272275
"pallet-token-gateway/runtime-benchmarks",
273276
"pallet-migrations/runtime-benchmarks",
274277
"pallet-delegated-staking/runtime-benchmarks",
@@ -325,6 +328,7 @@ try-runtime = [
325328
"pallet-whitelist/try-runtime",
326329
"pallet-preimage/try-runtime",
327330
"pallet-origins/try-runtime",
331+
"pallet-pool-withdrawal-fix/try-runtime",
328332
"pallet-ddc-clusters-gov/try-runtime",
329333
"pallet-ismp/try-runtime",
330334
"pallet-hyperbridge/try-runtime",

runtime/cere-dev/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
162162
// and set impl_version to 0. If only runtime
163163
// implementation changes and behavior does not, then leave spec_version as
164164
// is and increment impl_version.
165-
spec_version: 73151,
165+
spec_version: 73152,
166166
impl_version: 0,
167167
apis: RUNTIME_API_VERSIONS,
168168
transaction_version: 25,
@@ -447,13 +447,18 @@ impl pallet_babe::Config for Runtime {
447447
type EpochDuration = EpochDuration;
448448
type ExpectedBlockTime = ExpectedBlockTime;
449449
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
450+
451+
// In normal builds, respect session's disabled list.
452+
#[cfg(not(feature = "try-runtime"))]
450453
type DisabledValidators = Session;
451454

452-
type KeyOwnerProof = sp_session::MembershipProof;
455+
// In try-runtime builds, bypass disabled validators to unblock simulation.
456+
#[cfg(feature = "try-runtime")]
457+
type DisabledValidators = ();
453458

459+
type KeyOwnerProof = sp_session::MembershipProof;
454460
type EquivocationReportSystem =
455461
pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
456-
457462
type WeightInfo = ();
458463
type MaxAuthorities = MaxAuthorities;
459464
type MaxNominators = MaxNominatorRewardedPerValidator;
@@ -664,13 +669,21 @@ impl pallet_staking::Config for Runtime {
664669
type MaxUnlockingChunks = ConstU32<32>;
665670
type MaxControllersInDeprecationBatch = MaxControllersInDeprecationBatch;
666671
type HistoryDepth = frame_support::traits::ConstU32<84>;
667-
type EventListeners = NominationPools;
672+
type EventListeners = (NominationPools, DelegatedStaking);
668673
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
669674
type BenchmarkingConfig = StakingBenchmarkingConfig;
670675
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
671676
type Filter = Nothing;
672677
}
673678

679+
impl pallet_pool_withdrawal_fix::Config for Runtime {
680+
type RuntimeEvent = RuntimeEvent;
681+
type Currency = Balances;
682+
type DelegationPalletConnector = DelegatedStaking;
683+
type GovernanceOrigin = EnsureRoot<AccountId>;
684+
type WeightInfo = ();
685+
}
686+
674687
impl pallet_fast_unstake::Config for Runtime {
675688
type RuntimeEvent = RuntimeEvent;
676689
type ControlOrigin = EnsureRoot<AccountId>;
@@ -1636,6 +1649,9 @@ mod runtime {
16361649
pub type MultiBlockMigrations = pallet_migrations;
16371650
#[runtime::pallet_index(52)]
16381651
pub type DelegatedStaking = pallet_delegated_staking;
1652+
1653+
#[runtime::pallet_index(53)]
1654+
pub type PoolWithdrawalFix = pallet_pool_withdrawal_fix::Pallet<Runtime>;
16391655
}
16401656

16411657
/// The address format for describing accounts.

runtime/cere/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pallet-erc20 = { workspace = true }
105105
pallet-erc721 = { workspace = true }
106106
pallet-fee-handler = { workspace = true }
107107
pallet-origins = { workspace = true }
108+
pallet-pool-withdrawal-fix = { workspace = true }
108109
pallet-referenda = { workspace = true }
109110
pallet-whitelist = { workspace = true }
110111

@@ -204,6 +205,7 @@ std = [
204205
"pallet-whitelist/std",
205206
"pallet-preimage/std",
206207
"pallet-origins/std",
208+
"pallet-pool-withdrawal-fix/std",
207209
"pallet-hyperbridge/std",
208210
"ismp/std",
209211
"pallet-ismp/std",
@@ -267,6 +269,7 @@ runtime-benchmarks = [
267269
"pallet-preimage/runtime-benchmarks",
268270
"pallet-ddc-clusters-gov/runtime-benchmarks",
269271
"pallet-origins/runtime-benchmarks",
272+
"pallet-pool-withdrawal-fix/runtime-benchmarks",
270273
"pallet-token-gateway/runtime-benchmarks",
271274
"pallet-migrations/runtime-benchmarks",
272275
"pallet-delegated-staking/runtime-benchmarks",
@@ -323,6 +326,7 @@ try-runtime = [
323326
"pallet-whitelist/try-runtime",
324327
"pallet-preimage/try-runtime",
325328
"pallet-origins/try-runtime",
329+
"pallet-pool-withdrawal-fix/try-runtime",
326330
"pallet-ddc-clusters-gov/try-runtime",
327331
"pallet-ismp/try-runtime",
328332
"pallet-hyperbridge/try-runtime",

0 commit comments

Comments
 (0)