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

Commit

Permalink
Metadata v14 (companion to #3336) (#564)
Browse files Browse the repository at this point in the history
* Remove event pallet::metadata attributes

* Add scale-info deps, TypeInfo derives, update call variants

* Update metadata runtime APIs

* Add missing scale_info dependency, update rococo runtime API

* Add missing scale_info dependency

* Remove pushed diener patches

* Cargo.lock

* Add missing scale-info dependencies

* Fixes

* Statemint runtime fixes

* Call struct variant empty matches

* Add missing scale-info dependency

* Fixes

* scale-info 1.0

* cargo update -p xcm

* update lock

* Update Cargo.lock

* update to latest polkadot

* remove rpc_http_threads

paritytech/substrate#9737

* replace task executor with tokio handler

paritytech/substrate#9737

* fix test compilation?

* Update Cargo.lock

* cargo update

* remove unused

* Update substrate and polkadot

* Update test/client/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 16, 2021
1 parent b5e7376 commit 035a576
Show file tree
Hide file tree
Showing 36 changed files with 576 additions and 409 deletions.
600 changes: 352 additions & 248 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@

use sc_cli;
use sc_service::{
BasePath,
config::{TelemetryEndpoints, PrometheusConfig},
TransactionPoolOptions,
config::{PrometheusConfig, TelemetryEndpoints},
BasePath, TransactionPoolOptions,
};
use std::{
fs,
io::{self, Write},
net::SocketAddr,
};
use structopt::StructOpt;
use std::net::SocketAddr;

/// The `purge-chain` command used to remove the whole chain: the parachain and the relaychain.
#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -66,10 +65,12 @@ impl PurgeChainCmd {
let db_paths = databases
.iter()
.map(|(chain_label, database)| {
database.path().ok_or_else(|| sc_cli::Error::Input(format!(
"Cannot purge custom database implementation of: {}",
chain_label,
)))
database.path().ok_or_else(|| {
sc_cli::Error::Input(format!(
"Cannot purge custom database implementation of: {}",
chain_label,
))
})
})
.collect::<sc_cli::Result<Vec<_>>>()?;

Expand Down Expand Up @@ -152,11 +153,11 @@ impl RunCmd {
pub fn normalize(&self) -> NormalizedRunCmd {
let mut new_base = self.base.clone();

new_base.validator = self.base.validator || self.collator;
new_base.validator = self.base.validator || self.collator;

NormalizedRunCmd {
base: new_base,
parachain_id: self.parachain_id,
NormalizedRunCmd {
base: new_base,
parachain_id: self.parachain_id,
}
}
}
Expand Down Expand Up @@ -205,7 +206,10 @@ impl sc_cli::CliConfiguration for NormalizedRunCmd {
self.base.force_authoring()
}

fn prometheus_config(&self, default_listen_port: u16) -> sc_cli::Result<Option<PrometheusConfig>> {
fn prometheus_config(
&self,
default_listen_port: u16,
) -> sc_cli::Result<Option<PrometheusConfig>> {
self.base.prometheus_config(default_listen_port)
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/aura-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sp-application-crypto = { git = "https://github.com/paritytech/substrate", defau

# Other Dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]}
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }

[dev-dependencies]
Expand All @@ -27,6 +28,7 @@ cumulus-pallet-parachain-system = { path = "../parachain-system" }
default = [ "std" ]
std = [
"codec/std",
"scale-info/std",
"serde",
"frame-support/std",
"sp-runtime/std",
Expand Down
2 changes: 2 additions & 0 deletions pallets/collator-selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ['x86_64-unknown-linux-gnu']
[dependencies]
log = { version = "0.4.0", default-features = false }
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.119", 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" }
Expand Down Expand Up @@ -46,6 +47,7 @@ runtime-benchmarks = [
std = [
'codec/std',
'log/std',
'scale-info/std',
'sp-runtime/std',
'sp-staking/std',
'sp-std/std',
Expand Down
3 changes: 1 addition & 2 deletions pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub mod pallet {
}

/// Basic information about a collation candidate.
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
pub struct CandidateInfo<AccountId, Balance> {
/// Account identifier.
pub who: AccountId,
Expand Down Expand Up @@ -247,7 +247,6 @@ pub mod pallet {
}

#[pallet::event]
#[pallet::metadata(T::AccountId = "AccountId", BalanceOf<T> = "Balance")]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
NewInvulnerables(Vec<T::AccountId>),
Expand Down
2 changes: 2 additions & 0 deletions pallets/dmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
# Other dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ], default-features = false }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }

# Substrate Dependencies
Expand All @@ -32,6 +33,7 @@ default = [ "std" ]
std = [
"codec/std",
"log/std",
"scale-info/std",
"sp-std/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
11 changes: 7 additions & 4 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

use scale_info::TypeInfo;
use sp_std::{prelude::*, convert::TryFrom};
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use cumulus_primitives_core::DmpMessageHandler;
Expand All @@ -30,7 +31,7 @@ use xcm::{VersionedXcm, latest::prelude::*};
use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS};
pub use pallet::*;

#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ConfigData {
/// The maximum amount of weight any individual message may consume. Messages above this weight
/// go into the overweight queue and may only be serviced explicitly by the
Expand All @@ -47,7 +48,7 @@ impl Default for ConfigData {
}

/// Information concerning our message pages.
#[derive(Copy, Clone, Eq, PartialEq, Default, Encode, Decode, RuntimeDebug)]
#[derive(Copy, Clone, Eq, PartialEq, Default, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct PageIndexData {
/// The lowest used page index.
begin_used: PageCounter,
Expand Down Expand Up @@ -166,7 +167,6 @@ pub mod pallet {

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::metadata(T::BlockNumber = "BlockNumber")]
pub enum Event<T: Config> {
/// Downward message is invalid XCM.
/// \[ id \]
Expand Down Expand Up @@ -755,7 +755,10 @@ mod tests {
assert_noop!(DmpQueue::service_overweight(Origin::root(), 0, 9999), Error::<Test>::OverLimit);
assert_eq!(take_trace(), vec![ msg_limit_reached(10000) ]);

let base_weight = super::Call::<Test>::service_overweight(0, 0).get_dispatch_info().weight;
let base_weight = super::Call::<Test>::service_overweight {
index: 0,
weight_limit: 0,
}.get_dispatch_info().weight;
use frame_support::weights::GetDispatchInfo;
let info = DmpQueue::service_overweight(Origin::root(), 0, 20000).unwrap();
let actual_weight = info.actual_weight.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sp-externalities = { git = "https://github.com/paritytech/substrate", default-fe

# Other Dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]}
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
environmental = { version = "1.1.2", default-features = false }
Expand All @@ -55,6 +56,7 @@ default = [ "std" ]
std = [
"serde",
"codec/std",
"scale-info/std",
"frame-support/std",
"pallet-balances/std",
"sp-core/std",
Expand Down
26 changes: 14 additions & 12 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo, DmpMessageHandler,
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, OnValidationData,
OutboundHrmpMessage, ParaId, UpwardMessage, UpwardMessageSender, XcmpMessageHandler,
XcmpMessageSource, PersistedValidationData,
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
XcmpMessageHandler, XcmpMessageSource,
};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use frame_support::{
Expand All @@ -46,7 +46,7 @@ use frame_system::{ensure_none, ensure_root};
use polkadot_parachain::primitives::RelayChainBlockNumber;
use relay_state_snapshot::MessagingStateSnapshot;
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, Hash, BlockNumberProvider},
traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider, Hash},
transaction_validity::{
InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity,
ValidTransaction,
Expand Down Expand Up @@ -393,7 +393,10 @@ pub mod pallet {
}

#[pallet::weight(1_000_000)]
pub fn enact_authorized_upgrade(_: OriginFor<T>, code: Vec<u8>) -> DispatchResultWithPostInfo {
pub fn enact_authorized_upgrade(
_: OriginFor<T>,
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
Self::validate_authorized_upgrade(&code[..])?;
Self::set_code_impl(code)?;
AuthorizedUpgrade::<T>::kill();
Expand All @@ -403,7 +406,6 @@ pub mod pallet {

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::metadata(T::Hash = "Hash")]
pub enum Event<T: Config> {
/// The validation function has been scheduled to apply as of the contained relay chain
/// block number.
Expand Down Expand Up @@ -576,11 +578,11 @@ pub mod pallet {
.flatten()
.expect("validation function params are always injected into inherent data; qed");

Some(Call::set_validation_data(data))
Some(Call::set_validation_data { data })
}

fn is_inherent(call: &Self::Call) -> bool {
matches!(call, Call::set_validation_data(_))
matches!(call, Call::set_validation_data { .. })
}
}

Expand All @@ -599,9 +601,9 @@ pub mod pallet {
#[pallet::validate_unsigned]
impl<T: Config> sp_runtime::traits::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;

fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::enact_authorized_upgrade(ref code) = call {
if let Call::enact_authorized_upgrade { ref code } = call {
if let Ok(hash) = Self::validate_authorized_upgrade(code) {
return Ok(ValidTransaction {
priority: 100,
Expand All @@ -612,7 +614,7 @@ pub mod pallet {
});
}
}
if let Call::set_validation_data(..) = call {
if let Call::set_validation_data { .. } = call {
return Ok(Default::default());
}
Err(InvalidTransaction::Call.into())
Expand Down Expand Up @@ -942,7 +944,7 @@ impl<T: Config> Pallet<T> {

pub struct ParachainSetCode<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> frame_system::SetCode for ParachainSetCode<T> {
impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
fn set_code(code: Vec<u8>) -> DispatchResult {
Pallet::<T>::set_code_impl(code)
}
Expand All @@ -956,7 +958,7 @@ impl<T: Config> frame_system::SetCode for ParachainSetCode<T> {
/// A head for an empty chain is agreed to be a zero hash.
///
/// [hash chain]: https://en.wikipedia.org/wiki/Hash_chain
#[derive(Default, Clone, codec::Encode, codec::Decode)]
#[derive(Default, Clone, codec::Encode, codec::Decode, scale_info::TypeInfo)]
struct MessageQueueChain(relay_chain::Hash);

impl MessageQueueChain {
Expand Down
3 changes: 2 additions & 1 deletion pallets/parachain-system/src/relay_state_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use codec::{Decode, Encode};
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, AbridgedHrmpChannel, ParaId,
};
use scale_info::TypeInfo;
use sp_trie::{MemoryDB, HashDBT, EMPTY_PREFIX};
use sp_runtime::traits::HashFor;
use sp_state_machine::{Backend, TrieBackend};
Expand All @@ -29,7 +30,7 @@ use sp_trie::StorageProof;
/// This data is essential for making sure that the parachain is aware of current resource use on
/// the relay chain and that the candidates produced for this parachain do not exceed any of these
/// limits.
#[derive(Clone, Encode, Decode)]
#[derive(Clone, Encode, Decode, TypeInfo)]
pub struct MessagingStateSnapshot {
/// The current message queue chain head for downward message queue.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
.iter()
.filter_map(|e| e.call().is_sub_type())
.find_map(|c| match c {
crate::Call::set_validation_data(validation_data) => Some(validation_data.clone()),
crate::Call::set_validation_data { data: validation_data } => Some(validation_data.clone()),
_ => None,
})
.expect("Could not find `set_validation_data` inherent");
Expand Down
2 changes: 2 additions & 0 deletions pallets/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand All @@ -22,6 +23,7 @@ cumulus-primitives-core = { path = "../../primitives/core", default-features = f
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"serde",
"cumulus-primitives-core/std",
"sp-std/std",
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use sp_std::{prelude::*, convert::TryFrom};
use cumulus_primitives_core::{ParaId, DmpMessageHandler};
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use codec::{Encode, Decode};
use scale_info::TypeInfo;
use sp_runtime::traits::BadOrigin;
use xcm::{VersionedXcm, latest::{Xcm, Outcome, Parent, ExecuteXcm}};
use frame_support::dispatch::Weight;
Expand Down Expand Up @@ -60,7 +61,6 @@ pub mod pallet {

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::metadata(T::BlockNumber = "BlockNumber")]
pub enum Event<T: Config> {
/// Downward message is invalid XCM.
/// \[ id \]
Expand All @@ -74,7 +74,7 @@ pub mod pallet {
}

/// Origin for the parachains module.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
#[pallet::origin]
pub enum Origin {
Expand Down
2 changes: 2 additions & 0 deletions pallets/xcmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
# Other dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ], default-features = false }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
rand_chacha = { version = "0.3.0", default-features = false }

Expand Down Expand Up @@ -35,6 +36,7 @@ default = [ "std" ]
std = [
"codec/std",
"log/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
Expand Down

0 comments on commit 035a576

Please sign in to comment.