WIP: Update Substrate & Polkadot (#496)

* WIP: Update Substrate

* Update Substrate & Polkadot

* fixes

* more fixes

* few missing origins

* use spawn_essential_handle

* bump polkadot dep

* remove newlines

* fix test

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Sergei Shulepov
2021-06-17 08:37:03 +01:00
committed by GitHub
parent f45c55be3b
commit 1f3458a0e3
20 changed files with 494 additions and 477 deletions
+403 -408
View File
File diff suppressed because it is too large Load Diff
+2 -6
View File
@@ -22,7 +22,7 @@ use polkadot_primitives::v1::{
Block as PBlock, BlockNumber, CandidateCommitments, CandidateDescriptor, CandidateEvent,
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash as PHash, HeadData, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, ParachainHost,
PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode,
PersistedValidationData, SessionIndex, SessionInfo, SigningContext, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex,
};
use polkadot_test_client::{
@@ -473,17 +473,13 @@ sp_api::mock_impl_runtime_apis! {
Vec::new()
}
fn historical_validation_code(_: ParaId, _: BlockNumber) -> Option<ValidationCode> {
None
}
fn inbound_hrmp_channels_contents(
_: ParaId,
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> {
BTreeMap::new()
}
fn validation_code_by_hash(_: PHash) -> Option<ValidationCode> {
fn validation_code_by_hash(_: ValidationCodeHash) -> Option<ValidationCode> {
None
}
}
+1 -5
View File
@@ -248,14 +248,10 @@ struct StartPoVRecovery<'a, Block: BlockT, Client, IQ> {
para_id: ParaId,
client: Arc<Client>,
task_manager: &'a mut TaskManager,
overseer_handler: OverseerHandler,
import_queue: IQ,
_phantom: PhantomData<Block>,
}
impl<'a, Block, Client, IQ> polkadot_service::ExecuteWithClient
for StartPoVRecovery<'a, Block, Client, IQ>
@@ -327,13 +323,13 @@ pub fn build_polkadot_full_node(
true,
None,
telemetry_worker_handle,
polkadot_service::RealOverseerGen,
)?;
Ok(RFullNode {
relay_chain_full_node,
collator_key,
})
}
}
@@ -42,7 +42,7 @@ frame_support::construct_runtime!(
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Aura: pallet_aura::{Pallet, Call, Storage, Config<T>},
Aura: pallet_aura::{Pallet, Storage, Config<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},
Authorship: pallet_authorship::{Pallet, Call, Storage, Inherent},
+3 -3
View File
@@ -373,7 +373,7 @@ pub mod pallet {
}
#[pallet::weight((1_000, DispatchClass::Operational))]
fn sudo_send_upward_message(
pub fn sudo_send_upward_message(
origin: OriginFor<T>,
message: UpwardMessage,
) -> DispatchResult {
@@ -383,7 +383,7 @@ pub mod pallet {
}
#[pallet::weight((1_000_000, DispatchClass::Operational))]
fn authorize_upgrade(origin: OriginFor<T>, code_hash: T::Hash) -> DispatchResult {
pub fn authorize_upgrade(origin: OriginFor<T>, code_hash: T::Hash) -> DispatchResult {
ensure_root(origin)?;
AuthorizedUpgrade::<T>::put(&code_hash);
@@ -393,7 +393,7 @@ pub mod pallet {
}
#[pallet::weight(1_000_000)]
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();
@@ -19,7 +19,7 @@
use frame_support::traits::{ExecuteBlock, ExtrinsicCall, IsSubType, Get};
use sp_runtime::traits::{Block as BlockT, Extrinsic, HashFor, Header as HeaderT, NumberFor};
use sp_io::KillChildStorageResult;
use sp_io::KillStorageResult;
use sp_std::prelude::*;
use polkadot_parachain::primitives::{HeadData, ValidationParams, ValidationResult};
@@ -220,8 +220,14 @@ fn host_storage_root() -> Vec<u8> {
with_externalities(|ext| ext.storage_root())
}
fn host_storage_clear_prefix(prefix: &[u8]) {
with_externalities(|ext| ext.clear_prefix(prefix))
fn host_storage_clear_prefix(prefix: &[u8], limit: Option<u32>) -> KillStorageResult {
with_externalities(|ext| {
let (all_removed, num_removed) = ext.clear_prefix(prefix, limit);
match all_removed {
true => KillStorageResult::AllRemoved(num_removed),
false => KillStorageResult::SomeRemaining(num_removed),
}
})
}
fn host_storage_changes_root(parent_hash: &[u8]) -> Option<Vec<u8>> {
@@ -289,13 +295,13 @@ fn host_default_child_storage_clear(storage_key: &[u8], key: &[u8]) {
fn host_default_child_storage_storage_kill(
storage_key: &[u8],
limit: Option<u32>,
) -> KillChildStorageResult {
) -> KillStorageResult {
let child_info = ChildInfo::new_default(storage_key);
with_externalities(|ext| {
let (all_removed, num_removed) = ext.kill_child_storage(&child_info, limit);
match all_removed {
true => KillChildStorageResult::AllRemoved(num_removed),
false => KillChildStorageResult::SomeRemaining(num_removed),
true => KillStorageResult::AllRemoved(num_removed),
false => KillStorageResult::SomeRemaining(num_removed),
}
})
}
@@ -305,9 +311,15 @@ fn host_default_child_storage_exists(storage_key: &[u8], key: &[u8]) -> bool {
with_externalities(|ext| ext.exists_child_storage(&child_info, key))
}
fn host_default_child_storage_clear_prefix(storage_key: &[u8], prefix: &[u8]) {
fn host_default_child_storage_clear_prefix(storage_key: &[u8], prefix: &[u8], limit: Option<u32>) -> KillStorageResult {
let child_info = ChildInfo::new_default(storage_key);
with_externalities(|ext| ext.clear_child_prefix(&child_info, prefix))
with_externalities(|ext| {
let (all_removed, num_removed) = ext.clear_child_prefix(&child_info, prefix, limit);
match all_removed {
true => KillStorageResult::AllRemoved(num_removed),
false => KillStorageResult::SomeRemaining(num_removed),
}
})
}
fn host_default_child_storage_root(storage_key: &[u8]) -> Vec<u8> {
+22 -21
View File
@@ -72,6 +72,28 @@ pub mod pallet {
/// \[ id, outcome \]
ExecutedDownward([u8; 8], Outcome),
}
/// Origin for the parachains module.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
#[pallet::origin]
pub enum Origin {
/// It comes from the (parent) relay chain.
Relay,
/// It comes from a (sibling) parachain.
SiblingParachain(ParaId),
}
impl From<ParaId> for Origin {
fn from(id: ParaId) -> Origin {
Origin::SiblingParachain(id)
}
}
impl From<u32> for Origin {
fn from(id: u32) -> Origin {
Origin::SiblingParachain(id.into())
}
}
}
/// For an incoming downward message, this just adapts an XCM executor and executes DMP messages
@@ -137,27 +159,6 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
}
}
/// Origin for the parachains module.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Origin {
/// It comes from the (parent) relay chain.
Relay,
/// It comes from a (sibling) parachain.
SiblingParachain(ParaId),
}
impl From<ParaId> for Origin {
fn from(id: ParaId) -> Origin {
Origin::SiblingParachain(id)
}
}
impl From<u32> for Origin {
fn from(id: u32) -> Origin {
Origin::SiblingParachain(id.into())
}
}
/// Ensure that the origin `o` represents a sibling parachain.
/// Returns `Ok` with the parachain ID of the sibling or an `Err` otherwise.
pub fn ensure_sibling_para<OuterOrigin>(o: OuterOrigin) -> Result<ParaId, BadOrigin>
@@ -123,14 +123,14 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn start(origin: OriginFor<T>, para: ParaId, payload: Vec<u8>) -> DispatchResult {
pub fn start(origin: OriginFor<T>, para: ParaId, payload: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
Targets::<T>::mutate(|t| t.push((para, payload)));
Ok(())
}
#[pallet::weight(0)]
fn start_many(origin: OriginFor<T>, para: ParaId, count: u32, payload: Vec<u8>) -> DispatchResult {
pub fn start_many(origin: OriginFor<T>, para: ParaId, count: u32, payload: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
for _ in 0..count {
Targets::<T>::mutate(|t| t.push((para, payload.clone())));
@@ -139,14 +139,14 @@ pub mod pallet {
}
#[pallet::weight(0)]
fn stop(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
pub fn stop(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
ensure_root(origin)?;
Targets::<T>::mutate(|t| if let Some(p) = t.iter().position(|(p, _)| p == &para) { t.swap_remove(p); });
Ok(())
}
#[pallet::weight(0)]
fn stop_all(origin: OriginFor<T>, maybe_para: Option<ParaId>) -> DispatchResult {
pub fn stop_all(origin: OriginFor<T>, maybe_para: Option<ParaId>) -> DispatchResult {
ensure_root(origin)?;
if let Some(para) = maybe_para {
Targets::<T>::mutate(|t| t.retain(|&(x, _)| x != para));
@@ -157,7 +157,7 @@ pub mod pallet {
}
#[pallet::weight(0)]
fn ping(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
pub fn ping(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
// Only accept pings from other chains.
let para = ensure_sibling_para(<T as Config>::Origin::from(origin))?;
@@ -177,7 +177,7 @@ pub mod pallet {
}
#[pallet::weight(0)]
fn pong(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
pub fn pong(origin: OriginFor<T>, seq: u32, payload: Vec<u8>) -> DispatchResult {
// Only accept pings from other chains.
let para = ensure_sibling_para(<T as Config>::Origin::from(origin))?;
@@ -222,6 +222,8 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
@@ -436,10 +438,10 @@ construct_runtime! {
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>} = 20,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
@@ -226,7 +226,7 @@ construct_runtime! {
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>},
ParachainInfo: parachain_info::{Pallet, Storage, Config},
// DMP handler.
+1 -1
View File
@@ -163,7 +163,7 @@ where
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_handle(),
task_manager.spawn_essential_handle(),
client.clone(),
);
@@ -466,6 +466,8 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
@@ -669,7 +671,7 @@ construct_runtime!(
// System support stuff.
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>} = 1,
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage} = 2,
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 2,
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 4,
@@ -53,4 +53,9 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn transfer_all() -> Weight {
(84_170_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
@@ -65,7 +65,7 @@ where
mod tests {
use super::*;
use frame_support::traits::FindAuthor;
use frame_support::{parameter_types, weights::DispatchClass, PalletId};
use frame_support::{parameter_types, PalletId};
use frame_system::{limits, EnsureRoot};
use polkadot_primitives::v1::AccountId;
use sp_core::H256;
@@ -92,14 +92,6 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.for_class(DispatchClass::all(), |weight| {
weight.base_extrinsic = 100;
})
.for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(1024);
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const MaxReserves: u32 = 50;
@@ -119,7 +111,7 @@ mod tests {
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockLength = BlockLength;
type BlockWeights = BlockWeights;
type BlockWeights = ();
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
@@ -226,6 +226,8 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
}
impl pallet_randomness_collective_flip::Config for Runtime {}
parameter_types! {
pub const AssetDeposit: Balance = 100 * DOLLARS; // 100 DOLLARS deposit to create asset
pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT;
@@ -610,7 +612,7 @@ construct_runtime!(
// System support stuff.
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>} = 1,
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage} = 2,
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 2,
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 4,
@@ -53,4 +53,9 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn transfer_all() -> Weight {
(84_170_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
@@ -227,6 +227,8 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
@@ -600,7 +602,7 @@ construct_runtime!(
// System support stuff;
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
ParachainInfo: parachain_info::{Pallet, Storage, Config},
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
@@ -53,4 +53,9 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn transfer_all() -> Weight {
(84_170_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
+3 -1
View File
@@ -233,6 +233,8 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = ();
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_sudo::Config for Runtime {
type Call = Call;
type Event = Event;
@@ -273,7 +275,7 @@ construct_runtime! {
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
}
}
+1 -1
View File
@@ -115,7 +115,7 @@ pub fn new_partial(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_handle(),
task_manager.spawn_essential_handle(),
client.clone(),
);