Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion for #10403: Remove Default for AccountId #842

Merged
merged 14 commits into from
Dec 14, 2021
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,19 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
sp_tracing::try_init_simple();
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let invulnerables = vec![1, 2];
let keys = invulnerables

let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)];
let keys = balances
.iter()
.map(|i| (*i, *i, MockSessionKeys { aura: UintAuthorityId(*i) }))
.map(|&(i, _)| (i, i, MockSessionKeys { aura: UintAuthorityId(i) }))
Comment on lines +228 to +232
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a logic change. Before the keys only included [1, 2], and now has 1 through 5.

Is there a reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - other keys were used in tests as validators, but they won't show up in the validator list unless they have a session key defined (this is the change).

They always should have had a session key defined, but we got away without it previously because we used a very lazy and not very correct .unwrap_or_default() when retrieving the validators' session keys.

.collect::<Vec<_>>();

let balances = pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)],
};
let collator_selection = collator_selection::GenesisConfig::<Test> {
desired_candidates: 2,
candidacy_bond: 10,
invulnerables,
};
let session = pallet_session::GenesisConfig::<Test> { keys };
balances.assimilate_storage(&mut t).unwrap();
pallet_balances::GenesisConfig::<Test> { balances }.assimilate_storage(&mut t).unwrap();
// collator selection must be initialized before session.
collator_selection.assimilate_storage(&mut t).unwrap();
session.assimilate_storage(&mut t).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions pallets/session-benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
parity-scale-codec = { version = "2.3.1", default-features = false }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
Expand All @@ -28,6 +29,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
]
std = [
"parity-scale-codec/std",
"sp-std/std",
"sp-runtime/std",
"frame-system/std",
Expand Down
5 changes: 3 additions & 2 deletions pallets/session-benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ use sp_std::{prelude::*, vec};
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use pallet_session::*;
use parity_scale_codec::Decode;
pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
pub trait Config: pallet_session::Config {}

benchmarks! {
set_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::default();
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(caller), keys, proof)

purge_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::default();
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
let _t = pallet_session::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof);
}: _(RawOrigin::Signed(caller))
Expand Down
1 change: 1 addition & 0 deletions parachain-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ impl_runtime_apis! {

list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);

Expand Down
7 changes: 4 additions & 3 deletions polkadot-parachains/parachains-common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ where
From<polkadot_primitives::v1::AccountId> + Into<polkadot_primitives::v1::AccountId>,
{
fn handle_credit(credit: CreditOf<AccountIdOf<R>, pallet_assets::Pallet<R>>) {
let author = pallet_authorship::Pallet::<R>::author();
// In case of error: Will drop the result triggering the `OnDrop` of the imbalance.
let _ = pallet_assets::Pallet::<R>::resolve(&author, credit);
if let Some(author) = pallet_authorship::Pallet::<R>::author() {
// In case of error: Will drop the result triggering the `OnDrop` of the imbalance.
let _ = pallet_assets::Pallet::<R>::resolve(&author, credit);
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion polkadot-parachains/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use codec::{Decode, Encode};
use frame_support::unsigned::TransactionValidityError;
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_runtime::{
create_runtime_str, generic,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -254,6 +255,15 @@ impl sp_runtime::traits::SignedExtension for DisallowSigned {
) -> sp_std::result::Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
Ok(())
}
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(self.validate(who, call, info, len).map(|_| ())?)
}
fn validate(
&self,
_who: &Self::AccountId,
Expand Down
6 changes: 3 additions & 3 deletions polkadot-parachains/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn testnet_genesis(
balances: rococo_parachain_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
sudo: rococo_parachain_runtime::SudoConfig { key: root_key },
sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) },
parachain_info: rococo_parachain_runtime::ParachainInfoConfig { parachain_id: id },
aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities },
aura_ext: Default::default(),
Expand Down Expand Up @@ -210,7 +210,7 @@ fn seedling_testnet_genesis(
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
sudo: seedling_runtime::SudoConfig { key: root_key },
sudo: seedling_runtime::SudoConfig { key: Some(root_key) },
parachain_info: seedling_runtime::ParachainInfoConfig { parachain_id },
parachain_system: Default::default(),
}
Expand Down Expand Up @@ -725,7 +725,7 @@ fn westmint_genesis(
balances: westmint_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, WESTMINT_ED * 4096)).collect(),
},
sudo: westmint_runtime::SudoConfig { key: root_key },
sudo: westmint_runtime::SudoConfig { key: Some(root_key) },
parachain_info: westmint_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: westmint_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
Expand Down
2 changes: 1 addition & 1 deletion test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn testnet_genesis(
balances: cumulus_test_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
sudo: cumulus_test_runtime::SudoConfig { key: root_key },
sudo: cumulus_test_runtime::SudoConfig { key: Some(root_key) },
transaction_payment: Default::default(),
}
}