From 23bb7cc808e1e846d9951302954e0c774be83ad7 Mon Sep 17 00:00:00 2001 From: OnyxSkyscape Date: Wed, 22 Mar 2023 12:54:02 +0100 Subject: [PATCH 1/8] feat: remove v102 storage migrations and arm validator manager, v103 --- gn-runtime/src/lib.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/gn-runtime/src/lib.rs b/gn-runtime/src/lib.rs index f18b2306..699f3786 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -79,15 +79,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 +100,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 +277,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 +381,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,7 +437,6 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - UpgradeSessionKeys, >; #[cfg(feature = "runtime-benchmarks")] From 294d93f91f0320d905948c0433d6d9d184654f39 Mon Sep 17 00:00:00 2001 From: PopcornPaws Date: Thu, 30 Mar 2023 10:06:41 +0200 Subject: [PATCH 2/8] WIP trying to run pre and post upgrade checks to see if they fail. Onyx you may try to finish this if you want, otherwise I'll be available briefly in the afternoon and then the evening to finish this. I just want to see whether calling a specific trait method on the replaced type change. --- gn-runtime/Cargo.toml | 2 ++ gn-runtime/src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) 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 699f3786..b06f8995 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -28,6 +28,7 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, SaturatedConversion, }; +use sp_staking::offence::ReportOffence; use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -437,8 +438,41 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + ActivateImOnlinePallet, >; +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, + >>::is_known_offence(&[], &0u8) + ); + 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::is_known_offence( + &[], + &0u8 + ) + ); + Ok(()) + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; From b23302c7d3d3bd07e1bc19b1e0b33f935688f326 Mon Sep 17 00:00:00 2001 From: PopcornPaws Date: Thu, 30 Mar 2023 13:48:05 +0200 Subject: [PATCH 3/8] Tests build, but also fail. --- gn-runtime/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gn-runtime/src/lib.rs b/gn-runtime/src/lib.rs index b06f8995..57503ae7 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -455,8 +455,8 @@ impl frame_support::traits::OnRuntimeUpgrade for ActivateImOnlinePallet { <::ReportUnresponsiveness as ReportOffence< AccountId, (AccountId, AccountId), - pallet_im_online::UnresponsivenessOffence, - >>::is_known_offence(&[], &0u8) + pallet_im_online::UnresponsivenessOffence<(AccountId, AccountId)>, + >>::is_known_offence(&[], &1u32) ); Ok(Vec::new()) } @@ -464,10 +464,11 @@ impl frame_support::traits::OnRuntimeUpgrade for ActivateImOnlinePallet { fn post_upgrade(_state: Vec) -> Result<(), &'static str> { // ValidatorManager returns hard-coded false in `is_known_offence` assert!( - !::ReportUnresponsiveness::is_known_offence( - &[], - &0u8 - ) + !<::ReportUnresponsiveness as ReportOffence< + AccountId, + (AccountId, AccountId), + pallet_im_online::UnresponsivenessOffence<(AccountId, AccountId)>, + >>::is_known_offence(&[], &0u32) ); Ok(()) } From b55d30a21f7464ff7149c365a88e1b43e7b127cd Mon Sep 17 00:00:00 2001 From: PopcornPaws Date: Thu, 30 Mar 2023 14:08:53 +0200 Subject: [PATCH 4/8] Pre upgrade hook also compiled `ValidatorManager` instead of () into the test. Now it passes. --- gn-runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gn-runtime/src/lib.rs b/gn-runtime/src/lib.rs index 57503ae7..29dbe8b9 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -452,7 +452,7 @@ impl frame_support::traits::OnRuntimeUpgrade for ActivateImOnlinePallet { fn pre_upgrade() -> Result, &'static str> { // () returns hard-coded true in `is_known_offence` assert!( - <::ReportUnresponsiveness as ReportOffence< + !<::ReportUnresponsiveness as ReportOffence< AccountId, (AccountId, AccountId), pallet_im_online::UnresponsivenessOffence<(AccountId, AccountId)>, From fd5a9b4850b567786fcedf6ee27bd52e73bb0f35 Mon Sep 17 00:00:00 2001 From: OnyxSkyscape Date: Thu, 30 Mar 2023 19:13:28 +0200 Subject: [PATCH 5/8] Fix dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 66551a6f..cc696750 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,10 +32,10 @@ RUN apt update -y \ EXPOSE 30333 30333/udp 9944 9933 -FROM runtime as gn-oracle -COPY --from=builder /opt/app/target/release/gn-oracle /usr/local/bin/ +FROM runtime as gn-cli +COPY --from=builder /opt/app/target/release/gn-cli /usr/local/bin/ -CMD ["gn-oracle"] +CMD ["gn-cli"] FROM runtime AS gn-node COPY --from=builder /opt/app/target/release/gn-node /usr/local/bin/ From bc5839839d1b5418bd6349f7b198fe26d365d354 Mon Sep 17 00:00:00 2001 From: OnyxSkyscape Date: Wed, 22 Mar 2023 12:54:02 +0100 Subject: [PATCH 6/8] feat: remove v102 storage migrations and arm validator manager, v103 --- gn-runtime/src/lib.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/gn-runtime/src/lib.rs b/gn-runtime/src/lib.rs index f18b2306..699f3786 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -79,15 +79,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 +100,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 +277,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 +381,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,7 +437,6 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - UpgradeSessionKeys, >; #[cfg(feature = "runtime-benchmarks")] From 26ded6d46c0d5da8b98040d2334b0c5a95eba933 Mon Sep 17 00:00:00 2001 From: PopcornPaws Date: Fri, 31 Mar 2023 09:01:06 +0200 Subject: [PATCH 7/8] Fixed unused import and added runtime upgrade description. --- docs/runtime-upgrades.md | 23 +++++++++++++++++++++++ gn-runtime/src/lib.rs | 3 +++ 2 files changed, 26 insertions(+) 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/src/lib.rs b/gn-runtime/src/lib.rs index 29dbe8b9..ed46afa2 100644 --- a/gn-runtime/src/lib.rs +++ b/gn-runtime/src/lib.rs @@ -28,6 +28,7 @@ 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")] @@ -441,6 +442,8 @@ pub type Executive = frame_executive::Executive< ActivateImOnlinePallet, >; +// TODO remove this before the next upgrade +// also remove the `sp_staking` dependency pub struct ActivateImOnlinePallet; impl frame_support::traits::OnRuntimeUpgrade for ActivateImOnlinePallet { From 4d72c3d67882e9e2d896ac960c39815b92b2654f Mon Sep 17 00:00:00 2001 From: PopcornPaws Date: Fri, 31 Mar 2023 09:03:05 +0200 Subject: [PATCH 8/8] Dockerfile fix. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cc696750..705ce2a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN apt update -y \ EXPOSE 30333 30333/udp 9944 9933 -FROM runtime as gn-cli +FROM runtime as gn-oracle COPY --from=builder /opt/app/target/release/gn-cli /usr/local/bin/ CMD ["gn-cli"]