Skip to content

Commit

Permalink
fix derivation of pool account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed Jul 18, 2024
1 parent 3dee9c4 commit a52f819
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions substrate/frame/delegated-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ scale-info = { features = ["derive"], workspace = true }
sp-std = { workspace = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }
sp-io = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/delegated-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ use frame_support::{
},
};
use sp_runtime::{
traits::{AccountIdConversion, CheckedAdd, CheckedSub, Zero},
traits::{AccountIdConversion, CheckedAdd, CheckedSub, Zero, TrailingZeroInput},
ArithmeticError, DispatchResult, Perbill, RuntimeDebug, Saturating,
};
use sp_staking::{Agent, Delegator, EraIndex, StakingInterface, StakingUnchecked};
use sp_std::{convert::TryInto, prelude::*};
use sp_io::hashing::blake2_256;

pub type BalanceOf<T> =
<<T as Config>::Currency as FunInspect<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down Expand Up @@ -437,7 +438,9 @@ impl<T: Config> Pallet<T> {

/// Derive a (keyless) pot account from the given agent account and account type.
fn sub_account(account_type: AccountType, acc: T::AccountId) -> T::AccountId {
T::PalletId::get().into_sub_account_truncating((account_type, acc.clone()))
let entropy = (T::PalletId::get(), acc, account_type).using_encoded(blake2_256);
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
}

/// Held balance of a delegator.
Expand Down

0 comments on commit a52f819

Please sign in to comment.