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

To polkadot-v0.9.38 #309

Closed
wants to merge 18 commits into from
Closed
865 changes: 461 additions & 404 deletions Cargo.lock

Large diffs are not rendered by default.

449 changes: 131 additions & 318 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ substrate-build-script-utils = { workspace = true }
# crates.io
array-bytes = { workspace = true }
async-trait = { version = "0.1" }
clap = { version = "4.0", features = ["derive"] }
clap = { version = "4.1", features = ["derive"] }
codec = { package = "parity-scale-codec", workspace = true }
futures = { version = "0.3" }
jsonrpsee = { version = "0.16", features = ["server"] }
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public
.public()
}

#[allow(dead_code)]
fn load_config<G, E>(name: &'static str) -> GenericChainSpec<G, E>
where
E: DeserializeOwned,
Expand Down
9 changes: 3 additions & 6 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,11 @@ pub fn run() -> Result<()> {

runner.run_node_until_exit(|config| async move {
let chain_spec = &config.chain_spec;
let hwbench = if !cli.no_hardware_benchmarks {
let hwbench = (!cli.no_hardware_benchmarks).then_some(
config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})
} else {
None
};
})).flatten();

set_default_ss58_version(chain_spec);

Expand All @@ -674,7 +671,7 @@ pub fn run() -> Result<()> {
);
let id = ParaId::from(para_id);
let parachain_account =
AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account_truncating(&id);
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(&id);
let state_version = Cli::native_runtime_version(&config.chain_spec).state_version();
let block: Block =
cumulus_client_cli::generate_genesis_block(&*config.chain_spec, state_version)
Expand Down
10 changes: 10 additions & 0 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ where

if let Some(hwbench) = hwbench {
sc_sysinfo::print_hwbench(&hwbench);
// Here you can check whether the hardware meets your chains' requirements. Putting a link
// in there and swapping out the requirements for your own are probably a good idea. The
// requirements for a para-chain are dictated by its relay-chain.
if !frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench)
&& validator
{
log::warn!(
"⚠️ The hardware does not meet the minimal requirements for role 'Authority'."
);
}

if let Some(ref mut telemetry) = telemetry {
let telemetry_handle = telemetry.handle();
Expand Down
3 changes: 3 additions & 0 deletions pallet/message-transact/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ sp-io = { workspace = true }

[features]
default = ["std"]

runtime-benchmarks = []

std = [
# crates.io
"codec/std",
Expand Down
9 changes: 7 additions & 2 deletions pallet/message-transact/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use pallet_evm::{FeeCalculator, GasWeightMapping};
// substrate
use frame_support::{traits::EnsureOrigin, PalletError, RuntimeDebug};
use sp_core::{H160, U256};
use sp_runtime::traits::BadOrigin;
use sp_std::boxed::Box;

pub use pallet::*;
Expand All @@ -62,15 +63,19 @@ impl<O: Into<Result<LcmpEthOrigin, O>> + From<LcmpEthOrigin>> EnsureOrigin<O>
{
type Success = H160;

fn ensure_origin(o: O) -> Result<Self::Success, BadOrigin> {
Self::try_origin(o).map_err(|_| BadOrigin)
}

fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().map(|o| match o {
LcmpEthOrigin::MessageTransact(id) => id,
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(LcmpEthOrigin::MessageTransact(Default::default()))
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(LcmpEthOrigin::MessageTransact(Default::default())))
}
}

Expand Down
8 changes: 0 additions & 8 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,6 @@ where
fn note_author(author: T::AccountId) {
Self::reward_by_ids(&[(author, 20)])
}

fn note_uncle(uncle_author: T::AccountId, _age: T::BlockNumber) {
if let Some(block_author) = <pallet_authorship::Pallet<T>>::author() {
Self::reward_by_ids(&[(block_author, 2), (uncle_author, 1)])
} else {
log::error!("[pallet::staking] block author not set, this should never happen; qed");
}
}
}

// Play the role of the session manager.
Expand Down
25 changes: 12 additions & 13 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ where
{
fn should_execute<RuntimeCall>(
origin: &MultiLocation,
message: &mut Xcm<RuntimeCall>,
max_weight: XcmWeight,
weight_credit: &mut XcmWeight,
message: &mut [Instruction<RuntimeCall>],
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit)
Expand All @@ -84,12 +84,11 @@ pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<RuntimeCall>(
origin: &MultiLocation,

message: &mut Xcm<RuntimeCall>,
_max_weight: XcmWeight,
_weight_credit: &mut XcmWeight,
message: &mut [Instruction<RuntimeCall>],
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
if message.iter().any(|inst| {
matches!(
inst,
InitiateReserveWithdraw {
Expand All @@ -108,7 +107,7 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
// should not allow this, but we just log it here.
if matches!(origin, MultiLocation { parents: 1, interior: Here })
&& message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
&& message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::warn!(
target: "xcm::barriers",
Expand Down Expand Up @@ -148,7 +147,7 @@ pub struct LocalAssetTrader<
OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,
R: TakeRevenue,
>(
XcmWeight,
Weight,
Currency::Balance,
PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced, R)>,
);
Expand All @@ -162,12 +161,12 @@ impl<
> WeightTrader for LocalAssetTrader<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced, R>
{
fn new() -> Self {
Self(0, Zero::zero(), PhantomData)
Self(Weight::zero(), Zero::zero(), PhantomData)
}

fn buy_weight(&mut self, weight: XcmWeight, payment: Assets) -> Result<Assets, XcmError> {
log::trace!(target: "xcm::weight", "LocalAssetTrader::buy_weight weight: {:?}, payment: {:?}", weight, payment);
let amount = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight));
let amount = WeightToFee::weight_to_fee(&weight);
let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
let required: MultiAsset = (Concrete(AssetId::get()), u128_amount).into();
let unused = payment.checked_sub(required.clone()).map_err(|_| XcmError::TooExpensive)?;
Expand All @@ -180,7 +179,7 @@ impl<
fn refund_weight(&mut self, weight: XcmWeight) -> Option<MultiAsset> {
log::trace!(target: "xcm::weight", "LocalAssetTrader::refund_weight weight: {:?}", weight);
let weight = weight.min(self.0);
let amount = WeightToFee::weight_to_fee(&Weight::from_ref_time(weight));
let amount = WeightToFee::weight_to_fee(&weight);
self.0 -= weight;
self.1 = self.1.saturating_sub(amount);
let amount: u128 = amount.saturated_into();
Expand Down
1 change: 1 addition & 0 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ runtime-benchmarks = [
# darwinia
"darwinia-common-runtime/runtime-benchmarks",
"darwinia-deposit/runtime-benchmarks",
"darwinia-message-transact/runtime-benchmarks",

# darwinia-messages-substrate
"bridge-runtime-common/runtime-benchmarks",
Expand Down
1 change: 0 additions & 1 deletion runtime/crab/src/bridges_message/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl MessageBridge for WithDarwiniaMessageBridge {
const BRIDGED_CHAIN_ID: bp_runtime::ChainId = DARWINIA_CHAIN_ID;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
bridge_runtime_common::pallets::WITH_CRAB_MESSAGES_PALLET_NAME;
const RELAYER_FEE_PERCENT: u32 = 10;
const THIS_CHAIN_ID: bp_runtime::ChainId = CRAB_CHAIN_ID;
}

Expand Down
12 changes: 12 additions & 0 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ sp_api::impl_runtime_apis! {
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
fn query_weight_to_fee(weight: frame_support::weights::Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
Expand All @@ -322,6 +328,12 @@ sp_api::impl_runtime_apis! {
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_call_fee_details(call, len)
}
fn query_weight_to_fee(weight: frame_support::weights::Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}

impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
Expand Down
2 changes: 0 additions & 2 deletions runtime/crab/src/pallets/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ use crate::*;

impl pallet_authorship::Config for Runtime {
type EventHandler = (DarwiniaStaking,);
type FilterUncle = ();
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type UncleGenerations = ConstU32<0>;
}
71 changes: 50 additions & 21 deletions runtime/crab/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

// darwinia
use crate::*;
// polkadot
use xcm::latest::prelude::*;
// substrate
use frame_support::traits::Currency;

Expand All @@ -36,7 +38,7 @@ pub type LocalAssetTransactor = xcm_builder::CurrencyAdapter<
>;

frame_support::parameter_types! {
pub const RelayNetwork: xcm::latest::prelude::NetworkId = xcm::latest::prelude::NetworkId::Kusama;
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
}
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -77,37 +79,42 @@ pub type Barrier = darwinia_common_runtime::xcm_configs::DenyThenTry<
darwinia_common_runtime::xcm_configs::DenyReserveTransferToRelayChain,
(
xcm_builder::TakeWeightCredit,
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
xcm_builder::WithComputedOrigin<
(
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
),
UniversalLocation,
ConstU32<8>,
>,
// Expected responses are OK.
xcm_builder::AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<darwinia_common_runtime::xcm_configs::ParentOrSiblings>,
),
>;

frame_support::parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxInstructions: u32 = 100;
pub AnchoringSelfReserve: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::MultiLocation::new(
pub AnchoringSelfReserve: MultiLocation = MultiLocation::new(
0,
xcm::latest::prelude::X1(xcm::latest::prelude::PalletInstance(<Balances as frame_support::traits::PalletInfoAccess>::index() as u8))
X1(PalletInstance(<Balances as frame_support::traits::PalletInfoAccess>::index() as u8))
);
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub Ancestry: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::Parachain(ParachainInfo::parachain_id().into()).into();
pub UnitWeightCost: u64 = 1_000_000_000;
pub UnitWeightCost: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(1_000_000_000, 64 * 1024);
}

pub struct ToTreasury;
impl xcm_builder::TakeRevenue for ToTreasury {
fn take_revenue(revenue: xcm::latest::prelude::MultiAsset) {
if let xcm::latest::prelude::MultiAsset {
id: xcm::latest::prelude::Concrete(_location),
fun: xcm::latest::prelude::Fungible(amount),
} = revenue
{
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset { id: Concrete(_location), fun: Fungible(amount) } = revenue {
let treasury_account = Treasury::account_id();
let _ = Balances::deposit_creating(&treasury_account, amount);

Expand All @@ -122,17 +129,23 @@ impl xcm_builder::TakeRevenue for ToTreasury {
pub struct XcmExecutorConfig;
impl xcm_executor::Config for XcmExecutorConfig {
type AssetClaims = PolkadotXcm;
type AssetExchanger = ();
type AssetLocker = ();
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type AssetTrap = PolkadotXcm;
type Barrier = Barrier;
type CallDispatcher = RuntimeCall;
type FeeManager = ();
type IsReserve = xcm_builder::NativeAsset;
type IsTeleporter = ();
// Teleporting is disabled.
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MessageExporter = ();
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type PalletInstancesInfo = AllPalletsWithSystem;
type ResponseHandler = PolkadotXcm;
type RuntimeCall = RuntimeCall;
type SafeCallFilter = frame_support::traits::Everything;
type SubscriptionService = PolkadotXcm;
type Trader = xcm_configs::LocalAssetTrader<
frame_support::weights::ConstantMultiplier<
Expand All @@ -145,6 +158,9 @@ impl xcm_executor::Config for XcmExecutorConfig {
DealWithFees<Runtime>,
ToTreasury,
>;
type UniversalAliases = frame_support::traits::Nothing;
// Teleporting is disabled.
type UniversalLocation = UniversalLocation;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmSender = XcmRouter;
}
Expand All @@ -156,21 +172,34 @@ pub type LocalOriginToLocation =
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);

#[cfg(feature = "runtime-benchmarks")]
frame_support::parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type MaxLockers = ConstU32<8>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type WeightInfo = pallet_xcm::TestWeightInfo;
type XcmExecuteFilter = frame_support::traits::Everything;
type XcmExecutor = xcm_executor::XcmExecutor<XcmExecutorConfig>;
type XcmReserveTransferFilter = frame_support::traits::Everything;
Expand Down
2 changes: 1 addition & 1 deletion runtime/crab/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 500;
pub const MAXIMUM_BLOCK_WEIGHT: frame_support::weights::Weight =
frame_support::weights::Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_MILLIS * WEIGHT_MILLISECS_PER_BLOCK,
cumulus_primitives_core::relay_chain::v2::MAX_POV_SIZE as u64,
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

frame_support::parameter_types! {
Expand Down
Loading