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

Arm validator-manager's offline node detection #123

Merged
merged 10 commits into from
Mar 31, 2023
23 changes: 23 additions & 0 deletions docs/runtime-upgrades.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions gn-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }
Expand Down
72 changes: 40 additions & 32 deletions gn-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,15 +81,6 @@ pub mod opaque {
/// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>;

// 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,
Expand All @@ -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,
Expand Down Expand Up @@ -286,7 +279,7 @@ impl pallet_im_online::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type ValidatorSet = ValidatorManager;
type ReportUnresponsiveness = ();
type ReportUnresponsiveness = ValidatorManager;
type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = pallet_im_online::weights::SubstrateWeight<Runtime>;
type MaxKeys = MaxKeys;
Expand Down Expand Up @@ -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::<opaque::OldSessionKeys, _>(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
Expand Down Expand Up @@ -466,9 +439,44 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
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<Vec<u8>, &'static str> {
// () returns hard-coded true in `is_known_offence`
assert!(
!<<Runtime as pallet_im_online::Config>::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<u8>) -> Result<(), &'static str> {
// ValidatorManager returns hard-coded false in `is_known_offence`
assert!(
!<<Runtime as pallet_im_online::Config>::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;
Expand Down