Skip to content

Commit

Permalink
upgrade to 1.1.0 (#6)
Browse files Browse the repository at this point in the history
* upgrade to 1.0.0

* remove non-needed import

* FMT

* warnings clippy

* fmt

* make it compile

* fix tests

* Upgrade to 1.1.0

* fix zero

* Fix build errors with runtime-benchmarks feature enabled

* fmt

---------

Co-authored-by: Cem Eliguzel <cem@moonsonglabs.com>
  • Loading branch information
girazoki and Cem Eliguzel authored Sep 21, 2023
1 parent 4b0317c commit 4304fdb
Show file tree
Hide file tree
Showing 35 changed files with 2,382 additions and 1,602 deletions.
3,196 changes: 2,019 additions & 1,177 deletions Cargo.lock

Large diffs are not rendered by default.

259 changes: 130 additions & 129 deletions Cargo.toml

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions client/consensus/nimbus-consensus/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ where
{
async fn verify(
&mut self,
mut block_params: BlockImportParams<Block, ()>,
) -> Result<BlockImportParams<Block, ()>, String> {
mut block_params: BlockImportParams<Block>,
) -> Result<BlockImportParams<Block>, String> {
// Skip checks that include execution, if being told so or when importing only state.
//
// This is done for example when gap syncing and it is expected that the block after the gap
Expand Down Expand Up @@ -201,10 +201,9 @@ pub fn import_queue<Client, Block: BlockT, I, CIDP>(
spawner: &impl sp_core::traits::SpawnEssentialNamed,
registry: Option<&substrate_prometheus_endpoint::Registry>,
parachain: bool,
) -> ClientResult<BasicQueue<Block, I::Transaction>>
) -> ClientResult<BasicQueue<Block>>
where
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
I::Transaction: Send,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
Expand Down Expand Up @@ -255,7 +254,6 @@ where
I: BlockImport<Block> + Send,
{
type Error = I::Error;
type Transaction = I::Transaction;

async fn check_block(
&mut self,
Expand All @@ -266,7 +264,7 @@ where

async fn import_block(
&mut self,
mut block_import_params: sc_consensus::BlockImportParams<Block, Self::Transaction>,
mut block_import_params: sc_consensus::BlockImportParams<Block>,
) -> Result<sc_consensus::ImportResult, Self::Error> {
// If we are in the parachain context, best block is determined by the relay chain
// except during initial sync
Expand Down
1 change: 0 additions & 1 deletion client/consensus/nimbus-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ where
PF: Environment<B> + Send + Sync + 'static,
PF::Proposer: Proposer<
B,
Transaction = BI::Transaction,
ProofRecording = EnableProofRecording,
Proof = <EnableProofRecording as ProofRecording>::Proof,
>,
Expand Down
5 changes: 2 additions & 3 deletions client/consensus/nimbus-consensus/src/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use nimbus_primitives::{
};
use sc_consensus::BlockImportParams;
use sc_consensus_manual_seal::{ConsensusDataProvider, Error};
use sp_api::{BlockT, HeaderT, ProvideRuntimeApi, TransactionFor};
use sp_api::{BlockT, HeaderT, ProvideRuntimeApi};
use sp_application_crypto::ByteArray;
use sp_core::sr25519;
use sp_inherents::InherentData;
Expand Down Expand Up @@ -52,7 +52,6 @@ where
DP: DigestsProvider<NimbusId, <B as BlockT>::Hash> + Send + Sync,
P: Send + Sync,
{
type Transaction = TransactionFor<C, B>;
type Proof = P;

fn create_digest(&self, parent: &B::Header, inherents: &InherentData) -> Result<Digest, Error> {
Expand Down Expand Up @@ -98,7 +97,7 @@ where
fn append_block_import(
&self,
_parent: &B::Header,
params: &mut BlockImportParams<B, Self::Transaction>,
params: &mut BlockImportParams<B>,
_inherents: &InherentData,
_proof: Self::Proof,
) -> Result<(), Error> {
Expand Down
2 changes: 1 addition & 1 deletion pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
// Now extract the author from the digest
let digest = <frame_system::Pallet<T>>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
Expand Down
19 changes: 7 additions & 12 deletions pallets/author-inherent/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ use frame_support::weights::RuntimeDbWeight;
use frame_system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

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

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
AuthorInherent: pallet_testing::{Pallet, Call, Storage},
}
);
Expand All @@ -55,13 +51,12 @@ impl frame_system::Config for Test {
type DbWeight = TestDbWeight;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Block = Block;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -107,8 +102,8 @@ impl pallet_testing::Config for Test {

/// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default()
.build_storage::<Test>()
frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap()
.into()
}
5 changes: 3 additions & 2 deletions pallets/author-mapping/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ mod tests {
use crate::mock::Runtime;
use frame_support::assert_ok;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
10 changes: 2 additions & 8 deletions pallets/author-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,15 @@ pub mod pallet {
StorageMap<_, Blake2_128Concat, T::AccountId, NimbusId, OptionQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
/// Genesis config for author mapping pallet
pub struct GenesisConfig<T: Config> {
/// The associations that should exist at chain genesis
pub mappings: Vec<(NimbusId, T::AccountId)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { mappings: vec![] }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
for (nimbus_id, account_id) in &self.mappings {
if let Err(e) = Pallet::<T>::enact_registration(
Expand Down
28 changes: 9 additions & 19 deletions pallets/author-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

//! A minimal runtime including the author-mapping pallet
use crate as pallet_author_mapping;
use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, GenesisBuild},
weights::Weight,
};
use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
use nimbus_primitives::NimbusId;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
Expand All @@ -30,7 +26,7 @@ use sp_core::{ByteArray, H256};
use sp_io;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Perbill, RuntimeDebug,
BuildStorage, Perbill, RuntimeDebug,
};

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -58,19 +54,14 @@ impl Into<NimbusId> for TestAuthor {

pub type AccountId = u64;
pub type Balance = u128;
pub type BlockNumber = u32;

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

// Configure a mock runtime to test the pallet.
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Runtime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
AuthorMapping: pallet_author_mapping::{Pallet, Call, Storage, Config<T>, Event<T>},
}
Expand All @@ -86,14 +77,13 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = Everything;
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = BlockNumber;
type Nonce = u64;
type Block = Block;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -121,7 +111,7 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
Expand Down Expand Up @@ -168,8 +158,8 @@ impl ExtBuilder {
}

pub(crate) fn build(self) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.expect("Frame system builds valid default genesis config");

pallet_balances::GenesisConfig::<Runtime> {
Expand Down
5 changes: 3 additions & 2 deletions pallets/author-slot-filter/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ benchmarks! {
mod tests {
use crate::tests::Test;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
12 changes: 7 additions & 5 deletions pallets/author-slot-filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod pallet {
/// The overarching event type
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Deterministic on-chain pseudo-randomness used to do the filtering
type RandomnessSource: Randomness<H256, Self::BlockNumber>;
type RandomnessSource: Randomness<H256, BlockNumberFor<Self>>;
//TODO introduce a new trait for exhaustive sets and use it here.
// Oh actually, we can use the same trait. First we call the inner one
// to determine whether this particular author is eligible there. then we
Expand Down Expand Up @@ -203,21 +203,23 @@ pub mod pallet {
}

#[pallet::genesis_config]
pub struct GenesisConfig {
pub struct GenesisConfig<T: Config> {
pub eligible_count: EligibilityValue,
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
eligible_count: EligibilityValue::default(),
_config: Default::default(),
}
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
EligibleCount::<T>::put(self.eligible_count.clone());
}
Expand Down
22 changes: 8 additions & 14 deletions pallets/author-slot-filter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,22 @@

use crate as pallet_testing;
use frame_support::parameter_types;
use frame_support::sp_io;
use frame_support::traits::ConstU32;
use frame_support::weights::RuntimeDbWeight;
use frame_support_test::TestRandomness;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

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

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
AuthorSlotFilter: pallet_testing::{Pallet, Call, Storage, Event},
System: frame_system,
AuthorSlotFilter: pallet_testing,
}
);

Expand All @@ -56,13 +51,12 @@ impl frame_system::Config for Test {
type DbWeight = TestDbWeight;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Block = Block;
type Hash = H256;
type Nonce = u64;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand All @@ -85,8 +79,8 @@ impl pallet_testing::Config for Test {

/// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default()
.build_storage::<Test>()
frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap()
.into()
}
4 changes: 1 addition & 3 deletions pallets/author-slot-filter/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use scale_info::TypeInfo;
use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Clone, Debug, TypeInfo, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Debug, Default, TypeInfo, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonZeroU32(u32);

impl core::ops::Deref for NonZeroU32 {
Expand Down Expand Up @@ -58,7 +58,6 @@ impl NonZeroU32 {
}
}

#[cfg(feature = "std")]
impl Serialize for NonZeroU32 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -68,7 +67,6 @@ impl Serialize for NonZeroU32 {
}
}

#[cfg(feature = "std")]
impl<'de> Deserialize<'de> for NonZeroU32 {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
Loading

0 comments on commit 4304fdb

Please sign in to comment.