Skip to content
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

[Pools] Refactors and runtime apis for DelegateStake #4537

Merged
merged 351 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
351 commits
Select commit Hold shift + click to select a range
a48b651
fix imports
Ank4n Apr 9, 2024
8df0f0f
Revert log level changes (#3913)
bkchr Mar 31, 2024
8cd50d0
Fix two typos (#3812)
gemini132 Mar 31, 2024
398eb18
Removed `pallet::getter` usage from `pallet-alliance` (#3738)
muraca Apr 1, 2024
140b0f5
network:bridge: fix peer_count metric (#3711)
alexggh Apr 1, 2024
01d0b52
[parachain-template] pallet configurations into `mod configs` (#3809)
asiniscalchi Apr 1, 2024
c861b78
Improve `HostConfiguration` consistency check (#3897)
sandreim Apr 1, 2024
2d82d2b
Pools: Make `PermissionlessWithdraw` the default claim permission (#3…
Apr 1, 2024
780e29d
Fix 0007-dispute-freshly-finalized.zndsl failing (#3893)
alexggh Apr 1, 2024
5a8f14b
primitives: Move out of staging released APIs (#3925)
alexggh Apr 1, 2024
b4cb8d1
Fix links (#3928)
serban300 Apr 1, 2024
be8bd2d
pallet-scheduler: fix test (#3923)
sandreim Apr 1, 2024
5e3d97e
`im-online` removal final cleanup (#3902)
s0me0ne-unkn0wn Apr 1, 2024
8f2e654
Update derive syn parse 0.2.0 (+ docify) (#3920)
sam0x17 Apr 2, 2024
00529bc
pallet-xcm: fix weights for all XTs and deprecate unlimited weight on…
acatangiu Apr 2, 2024
14603f2
Fix parachain upgrade scheduling when done by the owner/root (#3341)
bkchr Apr 2, 2024
e43f54f
chore(zombienet): bump version (#3933)
pepoviola Apr 2, 2024
ff1007e
Update bridges subtree (#3938)
serban300 Apr 2, 2024
3021cbc
beefy: error logs for validators with dummy keys (#3939)
acatangiu Apr 2, 2024
a1e6f04
chainHead: Allow methods to be called from within a single connection…
lexnv Apr 2, 2024
8164280
Align dependencies with `parity-bridges-common` (#3937)
serban300 Apr 2, 2024
b659b7d
migrations: prevent accidentally using unversioned migrations instead…
dastansam Apr 2, 2024
0a98610
Snowbridge: Synchronize from Snowfork repository (#3761)
claravanstaden Apr 2, 2024
7d6679e
sp_runtime: TryFrom<RuntimeString> for &str (#3942)
michalkucharczyk Apr 2, 2024
67de6ed
SortedMembers::add for pallet-membership benchmarks (#3729)
Dinonard Apr 2, 2024
c47d5f4
Remove nextest filtration (#3885)
AndreiEres Apr 2, 2024
e4cd533
statement-distribution: fix filtering of statements for elastic parac…
sandreim Apr 3, 2024
5536d86
sp-wasm-interface: `wasmtime` should not be enabled by `std` (#3954)
bkchr Apr 3, 2024
7e437ad
Added tests for XCM barriers: `AllowSubscriptions`, `WithUniqueTopic`…
bkontur Apr 3, 2024
743cfee
chainHead: Ensure reasonable distance between leaf and finalized bloc…
lexnv Apr 3, 2024
c5a043f
Enable pov-reclaim on rococo and westend parachains (#3858)
skunert Apr 3, 2024
5a1b92d
Add ClaimQueue wrapper (#3950)
sandreim Apr 3, 2024
8518593
Renames `frame` crate to `polkadot-sdk-frame` (#3813)
codekitz Apr 4, 2024
23860fc
Convince GitLab not to crop collapsed multiline strings (#3971)
rcny Apr 4, 2024
73fdff8
Use 0.1.0 as minimum version for crates (#3941)
Morganamilo Apr 4, 2024
63064e6
Fix Mermaid diagram rendering (#3875)
liamaharon Apr 4, 2024
2f49bf6
[doc] Example MBM pallet (#2119)
juangirini Apr 4, 2024
fa02ada
XCM builder pattern improvement - Accept `impl Into<T>` instead of ju…
franciscoaguirre Apr 4, 2024
d199fd3
Migrate fee payment from `Currency` to `fungible` (#2292)
liamaharon Apr 4, 2024
e8db4e2
Added support for coretime-kusama/polkadot and people-kusama/polkadot…
bkontur Apr 4, 2024
569a318
Make `BlockNumberProvider::set_block_number` available in tests / std…
shawntabrizi Apr 4, 2024
b159df1
`GenesisConfig` presets for runtime (#2714)
michalkucharczyk Apr 4, 2024
bb373ea
Add Helikon boot nodes for Coretime Westend and People Westend. (#3922)
kukabi Apr 4, 2024
1ae6ec0
Update pr_3844.prdoc (#3988)
ermalkaleci Apr 4, 2024
bfd7ae2
Elastic scaling: add e2e test (#3929)
sandreim Apr 5, 2024
04119b3
Revert "[prdoc] Require SemVer bump level" (#3987)
ggwpez Apr 5, 2024
76f0ce7
Update pr_3302.prdoc (#3985)
ordian Apr 5, 2024
047cfa8
[prdoc] Support multiple audiences (#3990)
ggwpez Apr 5, 2024
a961eb0
[pallet-broker] Fix claim revenue behaviour for zero timeslices (#3997)
seadanda Apr 5, 2024
9d0a455
[parachain-template] benchmarks into `mod benchmarks` (#3818)
asiniscalchi Apr 5, 2024
03ca23d
Rococo/Westend: publish `claim_queue` Runtime API (#4005)
sandreim Apr 5, 2024
a03040f
chore: fix some comments (#4004)
divdeploy Apr 5, 2024
ac4cd56
Bump h2 from 0.3.24 to 0.3.26 (#4008)
dependabot[bot] Apr 5, 2024
65d1bb5
Broker: sale price runtime api (#3485)
Szegoo Apr 5, 2024
d9d4250
`pallet-uniques`: decrement `total_deposit` when clearing collection …
liamaharon Apr 6, 2024
c405c93
Improve frame umbrella crate doc experience (#4007)
liamaharon Apr 6, 2024
b7342b3
Major bump of tracing-subscriber version (#3891)
gilescope Apr 6, 2024
b95e605
Fix some typos (#4018)
HongKuang Apr 8, 2024
7daeaca
Deprecate `para_id()` from `CoreState` in polkadot primitives (#3979)
tdimitrov Apr 8, 2024
70fc335
sc-beefy-consensus: Remove unneeded stream. (#4015)
bkchr Apr 8, 2024
7f2a59b
adder-collator: add velocity measurement and make elastic scaling tes…
sandreim Apr 8, 2024
4db2dca
Add best block indicator to informant message + print parent block on…
skunert Apr 8, 2024
561bfdd
Github workflow to automate release draft creation (#3978)
EgorPopelyaev Apr 8, 2024
65a5d7b
[FRAME] Runtime Omni Bencher (#3512)
ggwpez Apr 8, 2024
527e039
Integrate litep2p into Polkadot SDK (#2944)
altonen Apr 8, 2024
0cc0af3
Adapt `RemoteExternalities` and its related types to be used with gen…
lean-apple Apr 8, 2024
6284289
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 9, 2024
d0d7977
add prdoc
Ank4n Apr 9, 2024
765278a
prdoc
Ank4n Apr 9, 2024
e46b01b
prdoc
Ank4n Apr 9, 2024
0376db7
mark strategy migration in storage
Ank4n Apr 9, 2024
3ee339a
pre post upgrade checks for strategy adapter migration
Ank4n Apr 9, 2024
0e41b01
Merge branch 'master' into ankan/01-prep-staking-for-delegation
Ank4n Apr 10, 2024
67a541c
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 10, 2024
5457c40
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 10, 2024
17a4cf1
bench apply slash
Ank4n Apr 10, 2024
4d48232
weights
Ank4n Apr 10, 2024
b9bd68a
fmt
Ank4n Apr 10, 2024
09b85b3
apply slash pass with transfer stake strategy
Ank4n Apr 10, 2024
6bf7432
fmt
Ank4n Apr 10, 2024
92c9ef4
switch back to DelegateStake for bench
Ank4n Apr 10, 2024
5886704
fix delegated staking
Ank4n Apr 10, 2024
b8d9739
add dummy weights
Ank4n Apr 10, 2024
82f4a00
todo test
Ank4n Apr 10, 2024
49fb272
fix bench
Ank4n Apr 11, 2024
87d0bce
bench pool migration
Ank4n Apr 11, 2024
749b729
claim delegation bench
Ank4n Apr 11, 2024
c6771ab
update weights for migration of pool
Ank4n Apr 11, 2024
444dc76
add migrate to direct staker for testing
Ank4n Apr 11, 2024
9e5bdfa
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 11, 2024
b1312d7
minor refactor
Ank4n Apr 11, 2024
49cfce1
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 11, 2024
9079d82
add migrate to direct staker for testing
Ank4n Apr 11, 2024
616dfa7
doc comment
Ank4n Apr 11, 2024
6bcf0ab
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 11, 2024
c07a473
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 11, 2024
3579a88
fix import
Ank4n Apr 11, 2024
84dd24f
move drop agent to stake adapter
Ank4n Apr 11, 2024
99d34a2
fix compile
Ank4n Apr 11, 2024
afe8c87
pr feedback
Ank4n Apr 11, 2024
e7d65e2
add try state checks for virtual ledger
Ank4n Apr 11, 2024
474c1de
fmt
Ank4n Apr 11, 2024
6a019d6
Update substrate/frame/delegated-staking/src/lib.rs
kianenigma Apr 12, 2024
8d481a6
Apply suggestions from code review
Ank4n Apr 16, 2024
6940f88
Merge branch 'master' into ankan/01-prep-staking-for-delegation
Ank4n Apr 17, 2024
a884846
safe maths
Ank4n Apr 17, 2024
d4633c2
fix docs based on feedback
Ank4n Apr 17, 2024
c013cde
rename StakingUnsafe to StakingUnchecked
Ank4n Apr 17, 2024
b2588a5
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 17, 2024
22594af
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 17, 2024
ac3cadf
use static mutate
Ank4n Apr 17, 2024
8cee25c
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 17, 2024
0537e9c
Rename StakingUnsafe to StakingUnchecked
Ank4n Apr 17, 2024
fb5d64c
pr feedbacks
Ank4n Apr 17, 2024
bb93c8c
pr feedbacks
Ank4n Apr 17, 2024
cba250e
feedbacks
Ank4n Apr 17, 2024
9897437
feedback
Ank4n Apr 17, 2024
43d06b0
use static mutate
Ank4n Apr 17, 2024
abbc24d
Rename StakingUnsafe to StakingUnchecked
Ank4n Apr 17, 2024
b5fcc2f
pr feedbacks
Ank4n Apr 17, 2024
839e294
pr feedbacks
Ank4n Apr 17, 2024
53fab5b
feedbacks
Ank4n Apr 17, 2024
3bb99b2
feedback
Ank4n Apr 17, 2024
b430f63
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 17, 2024
5895afb
fix tests
Ank4n Apr 18, 2024
09d3359
Merge branch 'master' into ankan/01-prep-staking-for-delegation
Ank4n Apr 18, 2024
e75c2e6
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 18, 2024
383593c
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 18, 2024
9bcfb17
add license to inner
Ank4n Apr 18, 2024
8fe83ca
adapters tested separately
Ank4n Apr 19, 2024
9409c74
add migration for westend
Ank4n Apr 19, 2024
5a3b8b2
add apply slash test to NP
Ank4n Apr 19, 2024
e31866e
inline locking
Ank4n Apr 19, 2024
078cf5f
optimize stash kill
Ank4n Apr 19, 2024
3790a40
Merge branch 'master' into ankan/01-prep-staking-for-delegation
Ank4n Apr 19, 2024
796c848
Merge branch 'ankan/01-prep-staking-for-delegation' into ankan/02-pal…
Ank4n Apr 19, 2024
666be52
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n Apr 20, 2024
ca232cd
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 20, 2024
be76a6b
pr feedbacks
Ank4n Apr 22, 2024
c6070d8
check stash is killed before cleaning up agent
Ank4n Apr 22, 2024
886a1a7
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n Apr 22, 2024
7ca660d
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 22, 2024
a69d620
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n Apr 24, 2024
b511a30
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 24, 2024
4b2daa2
withdraw delegation requires num slashing spans
Ank4n Apr 24, 2024
0e17037
separate trait for migration
Ank4n Apr 24, 2024
4e3b8cd
add a separate slash reward fraction for agent slashing
Ank4n Apr 24, 2024
ef10f48
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 24, 2024
804fa95
fix compile
Ank4n Apr 24, 2024
d3cf1b8
store only migration status
Ank4n Apr 25, 2024
a12f4c3
remove default strategy type
Ank4n Apr 25, 2024
b444c0e
rename claim_delegation to migrate_delegation
Ank4n Apr 25, 2024
a4ddc76
additional check for account destroy
Ank4n Apr 25, 2024
b09f8fb
less retricted trait bounds for bench balance conversion
Ank4n Apr 25, 2024
e848d8d
pr feedbacks
Ank4n Apr 25, 2024
2a0b5c2
fix pool weight westend
Ank4n Apr 25, 2024
b1b1e1d
better docs pr feedback
Ank4n Apr 25, 2024
1e6cdad
rename claim delegation to migrate delegation
Ank4n Apr 25, 2024
3cef018
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n Apr 25, 2024
44503ba
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 25, 2024
619858d
Merge branch 'ankan/02-pallet-delegated-staking' of https://github.co…
Apr 25, 2024
2f65014
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 25, 2024
24d05ad
fix docs
Ank4n Apr 25, 2024
72b50da
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n Apr 25, 2024
495aa24
not allow reap stash for virtual stakers
Ank4n Apr 26, 2024
732569a
fix test
Ank4n Apr 26, 2024
142e3c7
full slash test
Ank4n Apr 26, 2024
7dacae3
not passing yet
Ank4n Apr 26, 2024
bd56eb3
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n May 2, 2024
a988ec8
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n May 2, 2024
d4ef271
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n May 7, 2024
fe0b657
fix migration, move free funds as well when migrating a nominator to …
Ank4n May 7, 2024
ca77189
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n May 7, 2024
0f6a3a0
fix migration errors, make it idempotent
Ank4n May 7, 2024
36e9972
fix imports
Ank4n May 7, 2024
6bf808a
remove slash test that will be fixed as a separate PR
Ank4n May 7, 2024
a1c5698
assert against right err
Ank4n May 7, 2024
464cea0
Merge branch 'master' into ankan/02-pallet-delegated-staking
Ank4n May 13, 2024
7782cab
pr feedbacks
Ank4n May 13, 2024
6e3045f
use system events for pallet
Ank4n May 13, 2024
0ff52fd
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n May 13, 2024
70e9b1f
fix mock config
Ank4n May 13, 2024
159d1bf
run try state for staking
Ank4n May 13, 2024
4b5e4fe
Merge branch 'ankan/02-pallet-delegated-staking' into ankan/03-np-del…
Ank4n May 13, 2024
7323dd6
Merge branch 'master' into ankan/03-np-delegation-integration
Ank4n May 15, 2024
587a2f1
restore Cargo.lock
Ank4n May 15, 2024
978c02c
Merge branch 'master' into ankan/03-np-delegation-integration
Ank4n May 15, 2024
31d4c6a
bump parity scale codec in delegate stake integration test
Ank4n May 15, 2024
2d5fd2e
pr feedbacks
Ank4n May 16, 2024
c6d6f0f
fmt
Ank4n May 16, 2024
f9db499
update prdoc withh all crates changed
Ank4n May 16, 2024
d2ee1e9
Merge branch 'master' into ankan/03-np-delegation-integration
Ank4n May 17, 2024
1634110
fix test
Ank4n May 17, 2024
62df281
Contracts: Remove topics for internal events (#4510)
pgherveou May 17, 2024
a1a6c2e
chore: fix typos (#4515)
jimwfs May 19, 2024
ead90d1
`remote-externalities`: `rpc_child_get_keys` to use paged scraping (#…
liamaharon May 19, 2024
c7e9b9b
Remove usage of the pallet::getter macro from pallet-fast-unstake (#4…
PolkadotDom May 20, 2024
a771851
Remove the prospective-parachains subsystem from collators (#4471)
alindima May 21, 2024
bd35913
Merge branch 'master' into ankan/03-np-delegation-integration
Ank4n May 21, 2024
a2f984e
add fully unbonding and partially unbonding scenarios to pool migrati…
Ank4n May 21, 2024
7a06567
fmt
Ank4n May 21, 2024
9e89aa0
ensure migrate delegation is only called once
Ank4n May 21, 2024
318d1a7
add new api to check if staker is virtual
Ank4n May 21, 2024
d0a9393
add extrinsic to migrate pool
Ank4n May 21, 2024
20bbf18
fix compile and gate delegation related dispatchables
Ank4n May 21, 2024
a66beff
add test to ensure delegate stake dispatchables are gated
Ank4n May 21, 2024
5eb6cfb
some more gate tests
Ank4n May 21, 2024
7efdbf7
fix bench
Ank4n May 22, 2024
b9a7236
update migration with max pool bound
Ank4n May 22, 2024
9bc3998
convert transferrable balance to need a PoolAccount type
Ank4n May 22, 2024
7813afe
make field pub
Ank4n May 22, 2024
c58300d
fmt
Ank4n May 22, 2024
452314f
wip
Ank4n May 22, 2024
8cf6896
tests run
Ank4n May 22, 2024
3759ba7
seems to compile everything
Ank4n May 22, 2024
f31e33a
Merge branch 'master' into ankan/np-newtype
Ank4n May 23, 2024
eb7292c
fmt
Ank4n May 23, 2024
0e61f5a
revert bad merge changes
Ank4n May 23, 2024
11792ce
clippy fix
Ank4n May 23, 2024
508bc82
Merge branch 'master' into ankan/np-newtype
Ank4n May 23, 2024
967f73f
make delegated staking apis type safe
Ank4n May 24, 2024
a9dc3ae
Merge branch 'master' into ankan/np-newtype
Ank4n May 24, 2024
35a16cf
fix clippy errors
Ank4n May 24, 2024
14d5f5e
add runtime apis
Ank4n May 24, 2024
4d37e2a
Merge branch 'master' into ankan/np-newtype
Ank4n May 24, 2024
dd3cbf7
return none if agent or delegator does not exist
Ank4n May 24, 2024
121cbdd
add runtime api to kitchensink runtime
Ank4n May 24, 2024
9e47b75
hope everything passes now
Ank4n May 24, 2024
31ca372
second hope ;)
Ank4n May 24, 2024
91ed77f
only one of legacy adapter and actual assertion is true always
Ank4n May 24, 2024
4817861
rust doc
Ank4n May 24, 2024
c7deb30
small cleanup
Ank4n May 24, 2024
db3740e
Merge branch 'master' into ankan/np-newtype
Ank4n May 25, 2024
c422b40
Merge branch 'master' into ankan/np-newtype
Ank4n May 27, 2024
b4eaa22
Merge branch 'master' into ankan/np-newtype
Ank4n May 28, 2024
27e8081
add prdoc
Ank4n May 29, 2024
a9916f3
Merge branch 'master' into ankan/np-newtype
Ank4n May 29, 2024
d01d737
fix prdoc
Ank4n May 29, 2024
85242bc
Update substrate/frame/nomination-pools/src/lib.rs
Ank4n May 29, 2024
256098e
Update prdoc/pr_4537.prdoc
Ank4n May 29, 2024
6f4e49b
use T for type param
Ank4n May 29, 2024
c265024
update prdoc
Ank4n May 29, 2024
005f522
rename Agent to AgentLedgerOuter
Ank4n May 30, 2024
f437436
drop Account from Agent/Delegator
Ank4n May 30, 2024
5eb311a
drop account from pool/member newtype
Ank4n May 30, 2024
9c3a4ac
fmt
Ank4n May 30, 2024
c5bd9e7
make inner type private
Ank4n May 30, 2024
92a17ac
minor
Ank4n May 30, 2024
9c5712c
Merge branch 'master' into ankan/np-newtype
Ank4n May 30, 2024
f714587
Merge branch 'master' into ankan/np-newtype
Ank4n Jun 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,22 @@ sp_api::impl_runtime_apis! {
fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
NominationPools::api_balance_to_points(pool_id, new_funds)
}

fn pool_pending_slash(pool_id: pallet_nomination_pools::PoolId) -> Balance {
NominationPools::api_pool_pending_slash(pool_id)
}

fn member_pending_slash(member: AccountId) -> Balance {
NominationPools::api_member_pending_slash(member)
}

fn pool_needs_delegate_migration(pool_id: pallet_nomination_pools::PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

fn member_needs_delegate_migration(member: AccountId) -> bool {
NominationPools::api_member_needs_delegate_migration(member)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
27 changes: 27 additions & 0 deletions prdoc/pr_4537.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Runtime apis to help with delegate-stake based Nomination Pools.

doc:
- audience: Runtime User
description: |
Introduces a new set of runtime apis to facilitate dapps and wallets to integrate with delegate-stake
functionalities of Nomination Pools. These apis support pool and member migration, as well as lazy application of
pending slashes of the pool members.

crates:
- name: pallet-nomination-pools
bump: minor
- name: westend-runtime
bump: minor
- name: kitchensink-runtime
bump: minor
- name: pallet-delegated-staking
bump: minor
- name: sp-staking
bump: minor
- name: pallet-nomination-pools-benchmarking
bump: patch
- name: pallet-nomination-pools-runtime-api
bump: minor
16 changes: 16 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,22 @@ impl_runtime_apis! {
fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
NominationPools::api_balance_to_points(pool_id, new_funds)
}

fn pool_pending_slash(pool_id: pallet_nomination_pools::PoolId) -> Balance {
NominationPools::api_pool_pending_slash(pool_id)
}

fn member_pending_slash(member: AccountId) -> Balance {
NominationPools::api_member_pending_slash(member)
}

fn pool_needs_delegate_migration(pool_id: pallet_nomination_pools::PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

fn member_needs_delegate_migration(member: AccountId) -> bool {
NominationPools::api_member_needs_delegate_migration(member)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
75 changes: 33 additions & 42 deletions substrate/frame/delegated-staking/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,78 @@
//! Implementations of public traits, namely [`DelegationInterface`] and [`OnStakingUpdate`].

use super::*;
use sp_staking::{DelegationInterface, DelegationMigrator, OnStakingUpdate};
use sp_staking::{
AgentAccount, DelegationInterface, DelegationMigrator, DelegatorAccount, OnStakingUpdate,
};

impl<T: Config> DelegationInterface for Pallet<T> {
type Balance = BalanceOf<T>;
type AccountId = T::AccountId;

/// Effective balance of the `Agent` account.
fn agent_balance(who: &Self::AccountId) -> Self::Balance {
Agent::<T>::get(who)
.map(|agent| agent.ledger.effective_balance())
.unwrap_or_default()
fn agent_balance(who: AgentAccount<Self::AccountId>) -> Option<Self::Balance> {
Agent::<T>::get(&who.0).map(|agent| agent.ledger.effective_balance()).ok()
}

fn delegator_balance(delegator: &Self::AccountId) -> Self::Balance {
Delegation::<T>::get(delegator).map(|d| d.amount).unwrap_or_default()
fn delegator_balance(delegator: DelegatorAccount<Self::AccountId>) -> Option<Self::Balance> {
Delegation::<T>::get(&delegator.0).map(|d| d.amount)
}

/// Delegate funds to an `Agent`.
fn delegate(
who: &Self::AccountId,
agent: &Self::AccountId,
who: DelegatorAccount<Self::AccountId>,
agent: AgentAccount<Self::AccountId>,
reward_account: &Self::AccountId,
amount: Self::Balance,
) -> DispatchResult {
Pallet::<T>::register_agent(
RawOrigin::Signed(agent.clone()).into(),
RawOrigin::Signed(agent.0.clone()).into(),
reward_account.clone(),
)?;

// Delegate the funds from who to the `Agent` account.
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.clone()).into(), agent.clone(), amount)
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.0).into(), agent.0, amount)
}

/// Add more delegation to the `Agent` account.
fn delegate_extra(
who: &Self::AccountId,
agent: &Self::AccountId,
who: DelegatorAccount<Self::AccountId>,
agent: AgentAccount<Self::AccountId>,
amount: Self::Balance,
) -> DispatchResult {
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.clone()).into(), agent.clone(), amount)
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.0).into(), agent.0, amount)
}

/// Withdraw delegation of `delegator` to `Agent`.
///
/// If there are funds in `Agent` account that can be withdrawn, then those funds would be
/// unlocked/released in the delegator's account.
fn withdraw_delegation(
delegator: &Self::AccountId,
agent: &Self::AccountId,
delegator: DelegatorAccount<Self::AccountId>,
agent: AgentAccount<Self::AccountId>,
amount: Self::Balance,
num_slashing_spans: u32,
) -> DispatchResult {
Pallet::<T>::release_delegation(
RawOrigin::Signed(agent.clone()).into(),
delegator.clone(),
RawOrigin::Signed(agent.0).into(),
delegator.0,
amount,
num_slashing_spans,
)
}

/// Returns true if the `Agent` have any slash pending to be applied.
fn has_pending_slash(agent: &Self::AccountId) -> bool {
Agent::<T>::get(agent)
.map(|d| !d.ledger.pending_slash.is_zero())
.unwrap_or(false)
/// Returns pending slash of the `agent`.
fn pending_slash(agent: AgentAccount<Self::AccountId>) -> Option<Self::Balance> {
Agent::<T>::get(&agent.0).map(|d| d.ledger.pending_slash).ok()
}

fn delegator_slash(
agent: &Self::AccountId,
delegator: &Self::AccountId,
agent: AgentAccount<Self::AccountId>,
delegator: DelegatorAccount<Self::AccountId>,
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>,
) -> sp_runtime::DispatchResult {
Pallet::<T>::do_slash(agent.clone(), delegator.clone(), value, maybe_reporter)
Pallet::<T>::do_slash(agent, delegator, value, maybe_reporter)
}
}

Expand All @@ -101,32 +99,25 @@ impl<T: Config> DelegationMigrator for Pallet<T> {
type AccountId = T::AccountId;

fn migrate_nominator_to_agent(
agent: &Self::AccountId,
agent: AgentAccount<Self::AccountId>,
reward_account: &Self::AccountId,
) -> DispatchResult {
Pallet::<T>::migrate_to_agent(
RawOrigin::Signed(agent.clone()).into(),
reward_account.clone(),
)
Pallet::<T>::migrate_to_agent(RawOrigin::Signed(agent.0).into(), reward_account.clone())
}
fn migrate_delegation(
agent: &Self::AccountId,
delegator: &Self::AccountId,
agent: AgentAccount<Self::AccountId>,
delegator: DelegatorAccount<Self::AccountId>,
value: Self::Balance,
) -> DispatchResult {
Pallet::<T>::migrate_delegation(
RawOrigin::Signed(agent.clone()).into(),
delegator.clone(),
value,
)
Pallet::<T>::migrate_delegation(RawOrigin::Signed(agent.0).into(), delegator.0, value)
}

/// Only used for testing.
#[cfg(feature = "runtime-benchmarks")]
fn drop_agent(agent: &T::AccountId) {
<Agents<T>>::remove(agent);
fn drop_agent(agent: AgentAccount<Self::AccountId>) {
<Agents<T>>::remove(agent.0.clone());
<Delegators<T>>::iter()
.filter(|(_, delegation)| delegation.agent == *agent)
.filter(|(_, delegation)| delegation.agent == agent.0)
.for_each(|(delegator, _)| {
let _ = T::Currency::release_all(
&HoldReason::StakingDelegation.into(),
Expand All @@ -136,7 +127,7 @@ impl<T: Config> DelegationMigrator for Pallet<T> {
<Delegators<T>>::remove(&delegator);
});

T::CoreStaking::migrate_to_direct_staker(agent);
T::CoreStaking::migrate_to_direct_staker(&agent.0);
}
}

Expand Down
Loading
Loading