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-session and pallet-session-benchmarking to use umbrella crate #7323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 3 additions & 12 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-session = { optional = true, workspace = true }
sp-storage = { optional = true, workspace = true }
sp-transaction-pool = { optional = true, workspace = true }
sp-version = { optional = true, workspace = true }
sp-staking = { optional = true, workspace = true }

frame-executive = { optional = true, workspace = true }
frame-system-rpc-runtime-api = { optional = true, workspace = true }
Expand Down Expand Up @@ -111,6 +112,7 @@ std = [
"sp-storage/std",
"sp-transaction-pool?/std",
"sp-version?/std",
"sp-staking/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
18 changes: 3 additions & 15 deletions substrate/frame/session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["runtime"] }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
pallet-timestamp = { workspace = true }
scale-info = { features = ["derive", "serde"], workspace = true }
sp-core = { features = ["serde"], workspace = true }
sp-io = { workspace = true }
sp-runtime = { features = ["serde"], workspace = true }
sp-session = { workspace = true }
sp-staking = { features = ["serde"], workspace = true }
sp-state-machine = { workspace = true }
sp-trie = { optional = true, workspace = true }

Expand All @@ -36,22 +31,15 @@ default = ["historical", "std"]
historical = ["sp-trie"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-timestamp/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
"sp-state-machine/std",
"sp-trie/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
22 changes: 6 additions & 16 deletions substrate/frame/session/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true }
frame-benchmarking = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["runtime"] }
# frame-benchmarking = { workspace = true }
pallet-session = { workspace = true }
pallet-staking = { workspace = true }
rand = { features = ["std_rng"], workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }

[dev-dependencies]
Expand All @@ -33,34 +31,26 @@ pallet-balances = { workspace = true, default-features = true }
pallet-staking-reward-curve = { workspace = true, default-features = true }
pallet-timestamp = { workspace = true, default-features = true }
scale-info = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"frame-benchmarking/std",
# "frame-benchmarking/std",
"frame/std",
"frame-election-provider-support/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-session/std",
"pallet-staking/std",
"pallet-timestamp/std",
"rand/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-session/std",
]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
# "frame-benchmarking/runtime-benchmarks",
"frame/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
5 changes: 1 addition & 4 deletions substrate/frame/session/benchmarking/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
// This is separated into its own crate due to cyclic dependency issues.

use alloc::{vec, vec::Vec};
use sp_runtime::traits::{One, StaticLookup, TrailingZeroInput};

use codec::Decode;
use frame_benchmarking::v2::*;
use frame_support::traits::{Get, KeyOwnerProofSystem, OnInitialize};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use frame::benchmarking::prelude::{RawOrigin, *};
use pallet_session::{historical::Pallet as Historical, Pallet as Session, *};
use pallet_staking::{
benchmarking::create_validator_with_nominators, testing_utils::create_validators,
Expand Down
22 changes: 9 additions & 13 deletions substrate/frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ use frame_election_provider_support::{
bounds::{ElectionBounds, ElectionBoundsBuilder},
onchain, SequentialPhragmen,
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, ConstU64},
};
use sp_runtime::{traits::IdentityLookup, BuildStorage, KeyTypeId};
use frame::testing_prelude::*;

type AccountId = u64;
type Nonce = u32;
type Balance = u64;

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

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -72,7 +68,7 @@ impl pallet_session::historical::Config for Test {
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
}

sp_runtime::impl_opaque_keys! {
impl_opaque_keys! {
pub struct SessionKeys {
pub foo: sp_runtime::testing::UintAuthorityId,
}
Expand All @@ -83,9 +79,9 @@ impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
// corresponds to the opaque key id above
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[KeyTypeId([100u8, 117u8, 109u8, 121u8])];

fn on_genesis_session<Ks: sp_runtime::traits::OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
fn on_genesis_session<Ks: OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}

fn on_new_session<Ks: sp_runtime::traits::OpaqueKeys>(
fn on_new_session<Ks: OpaqueKeys>(
_: bool,
_: &[(AccountId, Ks)],
_: &[(AccountId, Ks)],
Expand Down Expand Up @@ -117,7 +113,7 @@ pallet_staking_reward_curve::build! {
);
}
parameter_types! {
pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
pub static ElectionsBounds: ElectionBounds = ElectionBoundsBuilder::default().build();
}

Expand Down Expand Up @@ -149,7 +145,7 @@ impl pallet_staking::Config for Test {

impl crate::Config for Test {}

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState {
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
sp_io::TestExternalities::new(t)
TestState::new(t)
}
25 changes: 7 additions & 18 deletions substrate/frame/session/src/historical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,22 @@ mod shared;
use alloc::vec::Vec;
use codec::{Decode, Encode};
use core::fmt::Debug;
use sp_runtime::{
traits::{Convert, OpaqueKeys},
KeyTypeId,
};

use sp_session::{MembershipProof, ValidatorCount};
use sp_staking::SessionIndex;
use sp_trie::{
trie_types::{TrieDBBuilder, TrieDBMutBuilderV0},
LayoutV0, MemoryDB, Recorder, StorageProof, Trie, TrieMut, TrieRecorder,
};

use frame_support::{
print,
traits::{KeyOwnerProofSystem, ValidatorSet, ValidatorSetWithIdentification},
Parameter, LOG_TARGET,
};

use frame::testing_prelude::*;
use crate::{self as pallet_session, Pallet as Session};

pub use pallet::*;
use sp_trie::{accessed_nodes_tracker::AccessedNodesTracker, recorder_ext::RecorderExt};

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

/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Expand Down Expand Up @@ -136,7 +126,7 @@ impl<T: Config> ValidatorSet<T::AccountId> for Pallet<T> {
type ValidatorId = T::ValidatorId;
type ValidatorIdOf = T::ValidatorIdOf;

fn session_index() -> sp_staking::SessionIndex {
fn session_index() -> SessionIndex {
super::Pallet::<T>::current_index()
}

Expand Down Expand Up @@ -377,14 +367,13 @@ pub(crate) mod tests {
};
use alloc::vec;

use sp_runtime::{key_types::DUMMY, testing::UintAuthorityId, BuildStorage};
use sp_state_machine::BasicExternalities;

use frame_support::traits::{KeyOwnerProofSystem, OnInitialize};
use frame::traits::{KeyOwnerProofSystem, OnInitialize};

type Historical = Pallet<Test>;

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
pub(crate) fn new_test_ext() -> TestState {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let keys: Vec<_> = NextValidators::get()
.iter()
Expand All @@ -399,7 +388,7 @@ pub(crate) mod tests {
pallet_session::GenesisConfig::<Test> { keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
sp_io::TestExternalities::new(t)
TestState::new(t)
}

#[test]
Expand Down
17 changes: 5 additions & 12 deletions substrate/frame/session/src/historical/offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
//! and the off-chain indexing API.

use alloc::vec::Vec;
use sp_runtime::{
offchain::storage::{MutateStorageError, StorageRetrievalError, StorageValueRef},
KeyTypeId,
};

use sp_session::MembershipProof;

use super::{shared, Config, IdentificationTuple, ProvingTrie};
Expand Down Expand Up @@ -143,18 +140,14 @@ mod tests {
};

use codec::Encode;
use sp_core::{
crypto::key_types::DUMMY,
offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt, StorageKind},
};
use sp_runtime::{testing::UintAuthorityId, BuildStorage};

use sp_state_machine::BasicExternalities;

use frame_support::traits::{KeyOwnerProofSystem, OnInitialize};
use frame::traits::{KeyOwnerProofSystem, OnInitialize};

type Historical = Pallet<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.expect("Failed to create test externalities.");
Expand All @@ -175,7 +168,7 @@ mod tests {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
let mut ext = TestState::new(t);

let (offchain, offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db());

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/session/src/historical/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use alloc::vec::Vec;
use codec::Encode;
use sp_runtime::traits::Convert;
use frame::testing_prelude::*;

use super::{shared, Config as HistoricalConfig};
use crate::{Config as SessionConfig, Pallet as SessionModule, SessionIndex};
Expand All @@ -46,7 +46,7 @@ pub fn store_session_validator_set_to_offchain<T: HistoricalConfig + SessionConf

encoded_validator_list.using_encoded(|encoded_validator_list| {
let derived_key = shared::derive_key(shared::PREFIX, session_index);
sp_io::offchain_index::set(derived_key.as_slice(), encoded_validator_list);
frame::deps::sp_io::offchain_index::set(derived_key.as_slice(), encoded_validator_list);
});
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/session/src/historical/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use alloc::{borrow::ToOwned, vec::Vec};
use codec::Encode;
use sp_staking::SessionIndex;
use frame::testing_prelude::*;

pub(super) const PREFIX: &[u8] = b"session_historical";
pub(super) const LAST_PRUNE: &[u8] = b"session_historical_last_prune";
Expand Down
Loading
Loading