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

[pallet-staking] Additional check for virtual stakers #5985

Merged
merged 7 commits into from
Nov 5, 2024
Merged
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
10 changes: 9 additions & 1 deletion substrate/frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,8 +1881,12 @@ impl<T: Config> StakingInterface for Pallet<T> {
}

/// Whether `who` is a virtual staker whose funds are managed by another pallet.
///
/// There is an assumption that, this account is keyless and managed by another pallet in the
/// runtime. Hence, it can never sign its own transactions.
fn is_virtual_staker(who: &T::AccountId) -> bool {
VirtualStakers::<T>::contains_key(who)
frame_system::Pallet::<T>::account_nonce(who).is_zero() &&
VirtualStakers::<T>::contains_key(who)
}

fn slash_reward_fraction() -> Perbill {
Expand Down Expand Up @@ -2103,6 +2107,10 @@ impl<T: Config> Pallet<T> {
Ledger::<T>::get(stash.clone()).unwrap().stash == stash,
"ledger corrupted for virtual staker"
);
ensure!(
frame_system::Pallet::<T>::account_nonce(&stash).is_zero(),
"virtual stakers are keyless and should not have any nonce"
);
let reward_destination = <Payee<T>>::get(stash.clone()).unwrap();
if let RewardDestination::Account(payee) = reward_destination {
ensure!(
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