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

Migrate pallet-im-online to umbrella crate #6736

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 4 additions & 19 deletions substrate/frame/im-online/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = ["derive"], workspace = true }
log = { workspace = true }
scale-info = { features = ["derive", "serde"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-authorship = { workspace = true }
sp-application-crypto = { features = ["serde"], workspace = true }
sp-core = { features = ["serde"], workspace = true }
sp-io = { workspace = true }
sp-runtime = { features = ["serde"], workspace = true }
sp-staking = { features = ["serde"], workspace = true }

[dev-dependencies]
Expand All @@ -36,30 +31,20 @@ pallet-session = { workspace = true, default-features = true }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-authorship/std",
"pallet-session/std",
"scale-info/std",
"sp-application-crypto/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-staking/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-authorship/try-runtime",
"pallet-session/try-runtime",
"sp-runtime/try-runtime",
]
9 changes: 1 addition & 8 deletions substrate/frame/im-online/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@

#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::v2::*;
use frame_support::{traits::UnfilteredDispatchable, WeakBoundedVec};
use frame_system::RawOrigin;
use sp_runtime::{
traits::{ValidateUnsigned, Zero},
transaction_validity::TransactionSource,
};

use crate::*;
use frame::{benchmarking::prelude::*, traits::UnfilteredDispatchable};

const MAX_KEYS: u32 = 1000;

Expand Down
41 changes: 21 additions & 20 deletions substrate/frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
//!
//! ```
//! use pallet_im_online::{self as im_online};
//! use frame::prelude::*;
//!
//! #[frame_support::pallet]
//! #[frame::pallet]
//! pub mod pallet {
//! use super::*;
//! use frame_support::pallet_prelude::*;
//! use frame_system::pallet_prelude::*;
//!
//! #[pallet::pallet]
//! pub struct Pallet<T>(_);
Expand Down Expand Up @@ -86,26 +85,28 @@ extern crate alloc;

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
pallet_prelude::*,
use frame::{
arithmetic::{PerThing, Perbill, Permill},
deps::{
frame_support::{BoundedSlice, WeakBoundedVec},
frame_system::offchain::{CreateInherent, SubmitTransaction},
sp_io,
sp_runtime::{
offchain::storage::{MutateStorageError, StorageRetrievalError, StorageValueRef},
print, BoundToRuntimeAppPublic,
},
},
derive::RuntimeDebug,
prelude::*,
traits::{
EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet,
AtLeast32BitUnsigned, Convert, EstimateNextSessionRotation, OneSessionHandler,
SaturatedConversion, Saturating, TrailingZeroInput, ValidatorSet,
ValidatorSetWithIdentification,
},
BoundedSlice, WeakBoundedVec,
};
use frame_system::{
offchain::{CreateInherent, SubmitTransaction},
pallet_prelude::*,
};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_application_crypto::RuntimeAppPublic;
use sp_runtime::{
offchain::storage::{MutateStorageError, StorageRetrievalError, StorageValueRef},
traits::{AtLeast32BitUnsigned, Convert, Saturating, TrailingZeroInput},
PerThing, Perbill, Permill, RuntimeDebug, SaturatedConversion,
};
use sp_staking::{
offence::{Kind, Offence, ReportOffence},
SessionIndex,
Expand Down Expand Up @@ -249,7 +250,7 @@ pub type IdentificationTuple<T> = (

type OffchainResult<T, A> = Result<A, OffchainErr<BlockNumberFor<T>>>;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -366,7 +367,7 @@ pub mod pallet {
>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(frame::derive::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub keys: Vec<T::AuthorityId>,
}
Expand Down Expand Up @@ -735,7 +736,7 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
impl<T: Config> BoundToRuntimeAppPublic for Pallet<T> {
type Public = T::AuthorityId;
}

Expand Down Expand Up @@ -805,7 +806,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
let validator_set_count = keys.len() as u32;
let offence = UnresponsivenessOffence { session_index, validator_set_count, offenders };
if let Err(e) = T::ReportUnresponsiveness::report_offence(vec![], offence) {
sp_runtime::print(e);
print(e);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions substrate/frame/im-online/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@

use super::*;
use alloc::vec::Vec;
use frame_support::{storage_alias, traits::OnRuntimeUpgrade};
use frame::{
testing_prelude::storage_alias,
traits::{OnRuntimeUpgrade, WrapperOpaque},
};

#[cfg(feature = "try-runtime")]
use frame_support::ensure;
use frame::deps::frame_support::ensure;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use frame::deps::sp_runtime::TryRuntimeError;

/// The log target.
const TARGET: &str = "runtime::im-online::migration::v1";

/// The original data layout of the im-online pallet (`ReceivedHeartbeats` storage item).
mod v0 {
use super::*;
use frame_support::traits::WrapperOpaque;

#[derive(Encode, Decode, Default)]
pub(super) struct BoundedOpaqueNetworkState {
Expand Down Expand Up @@ -128,15 +130,14 @@ pub fn clear_offchain_storage(validator_set_size: u32) {
key.extend(idx.encode());
key
};
sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear();
StorageValueRef::persistent(&key).clear();
});
}

#[cfg(all(feature = "try-runtime", test))]
mod test {
use super::*;
use crate::mock::{new_test_ext, Runtime as T};
use frame_support::traits::WrapperOpaque;

#[test]
fn migration_works() {
Expand Down
20 changes: 13 additions & 7 deletions substrate/frame/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@

#![cfg(test)]

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, ConstU64},
weights::Weight,
use frame::{
arithmetic::Permill,
deps::{
frame_system, sp_io,
sp_runtime::{self, testing::UintAuthorityId},
},
runtime::{
prelude::{construct_runtime, derive_impl, parameter_types, weights::Weight},
testing_prelude::BuildStorage,
},
traits::{ConstU32, ConstU64, ConvertInto, EstimateNextSessionRotation},
};
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{testing::UintAuthorityId, traits::ConvertInto, BuildStorage, Permill};
use sp_staking::{
offence::{OffenceError, ReportOffence},
SessionIndex,
Expand All @@ -36,7 +42,7 @@ use crate::Config;

type Block = frame_system::mocking::MockBlock<Runtime>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Runtime {
System: frame_system,
Session: pallet_session,
Expand Down Expand Up @@ -150,7 +156,7 @@ parameter_types! {

pub struct TestNextSessionRotation;

impl frame_support::traits::EstimateNextSessionRotation<u64> for TestNextSessionRotation {
impl EstimateNextSessionRotation<u64> for TestNextSessionRotation {
fn average_session_length() -> u64 {
// take the mock result if any and return it
let mock = MockAverageSessionLength::mutate(|p| p.take());
Expand Down
16 changes: 10 additions & 6 deletions substrate/frame/im-online/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

use super::*;
use crate::mock::*;
use frame_support::{assert_noop, dispatch};
use sp_core::offchain::{
testing::{TestOffchainExt, TestTransactionPoolExt},
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
use frame::{
deps::{
frame_support::dispatch,
sp_core::offchain::{
testing::{TestOffchainExt, TestTransactionPoolExt},
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
},
sp_runtime::testing::UintAuthorityId,
},
testing_prelude::*,
};
use sp_runtime::testing::UintAuthorityId;

#[test]
fn test_unresponsiveness_slash_fraction() {
let dummy_offence =
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/im-online/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.