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

Commit

Permalink
WIP: Update Substrate & Polkadot (#496)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
pepyakin and shawntabrizi authored Jun 17, 2021
1 parent 7d6f46b commit fe21865
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 477 deletions.
811 changes: 403 additions & 408 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions client/network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 1 addition & 5 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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,
})

}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
6 changes: 3 additions & 3 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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();
Expand Down
28 changes: 20 additions & 8 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>> {
Expand Down Expand Up @@ -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),
}
})
}
Expand All @@ -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> {
Expand Down
43 changes: 22 additions & 21 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down
12 changes: 6 additions & 6 deletions polkadot-parachains/pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand All @@ -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));
Expand All @@ -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))?;

Expand All @@ -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))?;

Expand Down
6 changes: 4 additions & 2 deletions polkadot-parachains/rococo-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/shell-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);

Expand Down
4 changes: 3 additions & 1 deletion polkadot-parachains/statemine-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
12 changes: 2 additions & 10 deletions polkadot-parachains/statemint-common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion polkadot-parachains/statemint-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Loading

0 comments on commit fe21865

Please sign in to comment.