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] New runtime api that returns the pot accounts associated with the pool #6357

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use frame_support::{
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_identity::legacy::IdentityInfo;
use pallet_nomination_pools::PoolId;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo};
use polkadot_primitives::{
Expand Down Expand Up @@ -2494,23 +2495,23 @@ sp_api::impl_runtime_apis! {
NominationPools::api_pending_rewards(member).unwrap_or_default()
}

fn points_to_balance(pool_id: pallet_nomination_pools::PoolId, points: Balance) -> Balance {
fn points_to_balance(pool_id: PoolId, points: Balance) -> Balance {
NominationPools::api_points_to_balance(pool_id, points)
}

fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
fn balance_to_points(pool_id: 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 {
fn pool_pending_slash(pool_id: 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 {
fn pool_needs_delegate_migration(pool_id: PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

Expand All @@ -2522,9 +2523,13 @@ sp_api::impl_runtime_apis! {
NominationPools::api_member_total_balance(member)
}

fn pool_balance(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_balance(pool_id: PoolId) -> Balance {
NominationPools::api_pool_balance(pool_id)
}

fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId) {
NominationPools::api_pool_accounts(pool_id)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_6357.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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: New runtime api that returns the associated pool accounts with a nomination pool.

doc:
- audience: Runtime User
description: |
Each nomination pool has two associated pot accounts: the bonded account, where funds are pooled for staking, and
the reward account. This update introduces a runtime api that clients can query to retrieve these accounts.

crates:
- name: westend-runtime
bump: minor
- name: kitchensink-runtime
bump: minor
- name: pallet-nomination-pools
bump: minor
- name: pallet-nomination-pools-runtime-api
bump: minor
15 changes: 10 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ use pallet_identity::legacy::IdentityInfo;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
use pallet_nis::WithMaximumOf;
use pallet_nomination_pools::PoolId;
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
use pallet_session::historical as pallet_session_historical;
// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles
Expand Down Expand Up @@ -2968,23 +2969,23 @@ impl_runtime_apis! {
NominationPools::api_pending_rewards(who).unwrap_or_default()
}

fn points_to_balance(pool_id: pallet_nomination_pools::PoolId, points: Balance) -> Balance {
fn points_to_balance(pool_id: PoolId, points: Balance) -> Balance {
NominationPools::api_points_to_balance(pool_id, points)
}

fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
fn balance_to_points(pool_id: 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 {
fn pool_pending_slash(pool_id: 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 {
fn pool_needs_delegate_migration(pool_id: PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

Expand All @@ -2996,9 +2997,13 @@ impl_runtime_apis! {
NominationPools::api_member_total_balance(member)
}

fn pool_balance(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_balance(pool_id: PoolId) -> Balance {
NominationPools::api_pool_balance(pool_id)
}

fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId) {
NominationPools::api_pool_accounts(pool_id)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/nomination-pools/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@ sp_api::decl_runtime_apis! {

/// Total balance contributed to the pool.
fn pool_balance(pool_id: PoolId) -> Balance;

/// Returns the bonded account and reward account associated with the pool_id.
fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId);
}
}
7 changes: 7 additions & 0 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,13 @@ impl<T: Config> Pallet<T> {
T::StakeAdapter::total_balance(Pool::from(Self::generate_bonded_account(pool_id)))
.unwrap_or_default()
}

/// Returns the bonded account and reward account associated with the pool_id.
pub fn api_pool_accounts(pool_id: PoolId) -> (T::AccountId, T::AccountId) {
let bonded_account = Self::generate_bonded_account(pool_id);
let reward_account = Self::generate_reward_account(pool_id);
(bonded_account, reward_account)
}
}

impl<T: Config> sp_staking::OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> {
Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/panic-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{
cell::Cell,
io::{self, Write},
marker::PhantomData,
panic::{self, PanicHookInfo},
panic::{self, PanicInfo},
sync::LazyLock,
thread,
};
Expand Down Expand Up @@ -149,7 +149,7 @@ fn strip_control_codes(input: &str) -> std::borrow::Cow<str> {
}

/// Function being called when a panic happens.
fn panic_hook(info: &PanicHookInfo, report_url: &str, version: &str) {
fn panic_hook(info: &PanicInfo, report_url: &str, version: &str) {
let location = info.location();
let file = location.as_ref().map(|l| l.file()).unwrap_or("<unknown>");
let line = location.as_ref().map(|l| l.line()).unwrap_or(0);
Expand Down
Loading