diff --git a/docs/runtime-upgrades.md b/docs/runtime-upgrades.md index 2b6bdd20..6bb590c7 100644 --- a/docs/runtime-upgrades.md +++ b/docs/runtime-upgrades.md @@ -1,5 +1,28 @@ # Runtime upgrade history +## 2023-03-30 +Runtime version bumped from `102` to `103`. [Respective +PR](https://github.com/agoraxyz/guild-network/pull/123) + +### Detailed info +This [release](https://github.com/agoraxyz/guild-network/releases/tag/alpha-runtime-103) +simply changed the `pallet_im_online::Config::ReportUnresponsiveness` type from +`()` to `ValidatorManager`. This means that the `ValidatorManager` pallet is +now responsible for automatically removing unresponsive (offline) validators +after approximately two sessions. Validators consistently sending heartbeats +are safe. + +In case a validator gets removed from the active validator set due to going +offline, they can still join the active validator set once they come online +again; the operator just needs to submit a `ValidatorManager > +addValidatorAgain` transaction (from the explorer). + +### Required steps for node operators +#### Validator nodes +- no steps required +#### Oracle nodes +- no steps required + ## 2023-03-22 Runtime version bumped from `101` to `102`. [Respective PR](https://github.com/agoraxyz/guild-network/pull/114) diff --git a/gn-runtime/Cargo.toml b/gn-runtime/Cargo.toml index 1cf4b468..585aa1ea 100644 --- a/gn-runtime/Cargo.toml +++ b/gn-runtime/Cargo.toml @@ -52,6 +52,7 @@ std = [ "sp-offchain/std", "sp-runtime/std", "sp-session/std", + "sp-staking/std", "sp-std/std", "sp-transaction-pool/std", "sp-version/std", @@ -116,6 +117,7 @@ sp-inherents = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } sp-session = { workspace = true } +sp-staking = { workspace = true } sp-std = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } diff --git a/gn-runtime/src/lib.rs b/gn-runtime/src/lib.rs index f18b2306..ed46afa2 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -28,6 +28,8 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, SaturatedConversion, }; +#[cfg(feature = "try-runtime")] +use sp_staking::offence::ReportOffence; use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -79,15 +81,6 @@ pub mod opaque { /// Opaque block identifier type. pub type BlockId = generic::BlockId; - // TODO Remove after im_online runtime upgrade is done. - impl_opaque_keys! { - pub struct OldSessionKeys { - pub aura: Aura, - pub grandpa: Grandpa, - - } - } - impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, @@ -109,7 +102,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 102, + spec_version: 103, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -286,7 +279,7 @@ impl pallet_im_online::Config for Runtime { type RuntimeEvent = RuntimeEvent; type NextSessionRotation = pallet_session::PeriodicSessions; type ValidatorSet = ValidatorManager; - type ReportUnresponsiveness = (); + type ReportUnresponsiveness = ValidatorManager; type UnsignedPriority = ImOnlineUnsignedPriority; type WeightInfo = pallet_im_online::weights::SubstrateWeight; type MaxKeys = MaxKeys; @@ -390,26 +383,6 @@ impl pallet_validator_manager::Config for Runtime { type MinAuthorities = MinAuthorities; } -// should be removed along with UpgradeSessionKeys -fn transform_session_keys(_v: AccountId, old: opaque::OldSessionKeys) -> opaque::SessionKeys { - let dummy_id = pallet_im_online::sr25519::AuthorityId::try_from(old.aura.as_ref()).unwrap(); - - opaque::SessionKeys { - grandpa: old.grandpa, - aura: old.aura, - im_online: dummy_id, - } -} - -// When this is removed, should also remove `OldSessionKeys`. -pub struct UpgradeSessionKeys; -impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - Session::upgrade_keys::(transform_session_keys); - BlockWeights::get().max_block - } -} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -466,9 +439,44 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - UpgradeSessionKeys, + ActivateImOnlinePallet, >; +// TODO remove this before the next upgrade +// also remove the `sp_staking` dependency +pub struct ActivateImOnlinePallet; + +impl frame_support::traits::OnRuntimeUpgrade for ActivateImOnlinePallet { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + BlockWeights::get().max_block + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + // () returns hard-coded true in `is_known_offence` + assert!( + !<::ReportUnresponsiveness as ReportOffence< + AccountId, + (AccountId, AccountId), + pallet_im_online::UnresponsivenessOffence<(AccountId, AccountId)>, + >>::is_known_offence(&[], &1u32) + ); + Ok(Vec::new()) + } + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + // ValidatorManager returns hard-coded false in `is_known_offence` + assert!( + !<::ReportUnresponsiveness as ReportOffence< + AccountId, + (AccountId, AccountId), + pallet_im_online::UnresponsivenessOffence<(AccountId, AccountId)>, + >>::is_known_offence(&[], &0u32) + ); + Ok(()) + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking;