diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 0d809e5741..16fdfb0ce0 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -498,6 +498,11 @@ impl_opaque_keys! { } } +parameter_types! { + // all keys are 32 bytes, except beefy being 33 + pub KeyDeposit: Balance = deposit(1, 5 * 32 + 33); +} + impl pallet_session::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ValidatorId = AccountId; @@ -510,7 +515,7 @@ impl pallet_session::Config for Runtime { type WeightInfo = weights::pallet_session::WeightInfo; type DisablingStrategy = pallet_session::disabling::UpToLimitWithReEnablingDisablingStrategy; type Currency = Balances; - type KeyDeposit = (); + type KeyDeposit = KeyDeposit; } impl pallet_session::historical::Config for Runtime { @@ -3146,21 +3151,15 @@ mod remote_tests { use super::*; use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, UpgradeCheckSelect}; use remote_externalities::{ - Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport, + Builder, Mode, OfflineConfig, OnlineConfig, RemoteExternalities, SnapshotConfig, Transport, }; use std::env::var; - #[tokio::test] - async fn run_migrations() { - if var("RUN_MIGRATION_TESTS").is_err() { - return; - } - - sp_tracing::try_init_simple(); + async fn remote_ext_test_setup() -> RemoteExternalities { let transport: Transport = - var("WS").unwrap_or("wss://kusama-rpc.polkadot.io:443".to_string()).into(); + var("WS").unwrap_or("wss://kusama-rpc.dwellir.com".to_string()).into(); let maybe_state_snapshot: Option = var("SNAP").map(|s| s.into()).ok(); - let mut ext = Builder::::default() + Builder::::default() .mode(if let Some(state_snapshot) = maybe_state_snapshot { Mode::OfflineOrElseOnline( OfflineConfig { state_snapshot: state_snapshot.clone() }, @@ -3175,7 +3174,39 @@ mod remote_tests { }) .build() .await - .unwrap(); + .unwrap() + } + + #[tokio::test] + #[ignore = "this test is meant to be executed manually"] + async fn validators_who_cannot_afford_session_key_deposit() { + use frame_support::traits::fungible::InspectHold; + sp_tracing::try_init_simple(); + let mut ext = remote_ext_test_setup().await; + ext.execute_with(|| { + let amount = ::KeyDeposit::get(); + let reason = pallet_session::HoldReason::Keys; + let cannot_pay = pallet_staking::Validators::::iter() + .map(|(v, _prefs)| v) + .filter(|v| { + pallet_balances::Pallet::::ensure_can_hold(&reason.into(), &v, amount) + .is_err() + }) + .collect::>(); + + for v in cannot_pay { + log::warn!(target: "runtime", "validator {:?} cannot pay a deposit of {:?}", v, amount) + } + }) + } + + #[tokio::test] + async fn run_migrations() { + if var("RUN_MIGRATION_TESTS").is_err() { + return; + } + sp_tracing::try_init_simple(); + let mut ext = remote_ext_test_setup().await; ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost)); } diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index dee1223175..d1f66fab1c 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -475,6 +475,11 @@ impl_opaque_keys! { } } +parameter_types! { + // all keys are 32 bytes, except beefy being 33 + pub KeyDeposit: Balance = deposit(1, 5 * 32 + 33); +} + impl pallet_session::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ValidatorId = AccountId; @@ -487,7 +492,7 @@ impl pallet_session::Config for Runtime { type WeightInfo = weights::pallet_session::WeightInfo; type DisablingStrategy = pallet_session::disabling::UpToLimitWithReEnablingDisablingStrategy; type Currency = Balances; - type KeyDeposit = (); + type KeyDeposit = KeyDeposit; } impl pallet_session::historical::Config for Runtime { @@ -3195,7 +3200,7 @@ mod remote_tests { async fn remote_ext_test_setup() -> RemoteExternalities { let transport: Transport = - var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into(); + var("WS").unwrap_or("wss://polkadot-rpc.dwellir.com".to_string()).into(); let maybe_state_snapshot: Option = var("SNAP").map(|s| s.into()).ok(); Builder::::default() .mode(if let Some(state_snapshot) = maybe_state_snapshot { @@ -3215,6 +3220,29 @@ mod remote_tests { .unwrap() } + #[tokio::test] + #[ignore = "this test is meant to be executed manually"] + async fn validators_who_cannot_afford_session_key_deposit() { + use frame_support::traits::fungible::InspectHold; + sp_tracing::try_init_simple(); + let mut ext = remote_ext_test_setup().await; + ext.execute_with(|| { + let amount = ::KeyDeposit::get(); + let reason = pallet_session::HoldReason::Keys; + let cannot_pay = pallet_staking::Validators::::iter() + .map(|(v, _prefs)| v) + .filter(|v| { + pallet_balances::Pallet::::ensure_can_hold(&reason.into(), &v, amount) + .is_err() + }) + .collect::>(); + + for v in cannot_pay { + log::warn!(target: "runtime", "validator {:?} cannot pay a deposit of {:?}", v, amount) + } + }) + } + #[tokio::test] async fn dispatch_all_proposals() { if var("RUN_OPENGOV_TEST").is_err() { @@ -3276,25 +3304,7 @@ mod remote_tests { #[ignore = "this test is meant to be executed manually"] async fn try_fast_unstake_all() { sp_tracing::try_init_simple(); - let transport: Transport = - var("WS").unwrap_or("wss://rpc.polkadot.io:443".to_string()).into(); - let maybe_state_snapshot: Option = var("SNAP").map(|s| s.into()).ok(); - let mut ext = Builder::::default() - .mode(if let Some(state_snapshot) = maybe_state_snapshot { - Mode::OfflineOrElseOnline( - OfflineConfig { state_snapshot: state_snapshot.clone() }, - OnlineConfig { - transport, - state_snapshot: Some(state_snapshot), - ..Default::default() - }, - ) - } else { - Mode::Online(OnlineConfig { transport, ..Default::default() }) - }) - .build() - .await - .unwrap(); + let mut ext = remote_ext_test_setup().await; ext.execute_with(|| { pallet_fast_unstake::ErasToCheckPerBlock::::put(1); polkadot_runtime_common::try_runtime::migrate_all_inactive_nominators::()