Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to polkadot-stable2412-1 #448

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert more v4 xcm types to v5
  • Loading branch information
dastansam committed Feb 5, 2025
commit c8079aca7683095428fce7e8bcc71fa5b8e9f67f
2 changes: 1 addition & 1 deletion polimec-common/common/src/assets.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;
use variant_count::VariantCount;
use xcm::v4::prelude::{AccountKey20, Ethereum, GeneralIndex, GlobalConsensus, Location, PalletInstance, Parachain};
use xcm::v5::prelude::{AccountKey20, Ethereum, GeneralIndex, GlobalConsensus, Location, PalletInstance, Parachain};
extern crate alloc;
use alloc::{vec, vec::*};

2 changes: 1 addition & 1 deletion polimec-common/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ use sp_runtime::{
FixedPointNumber, RuntimeDebug,
};
use sp_std::prelude::*;
pub use xcm::v4::{opaque::Xcm, Assets, Location, QueryId, SendError, SendResult, SendXcm, XcmHash};
pub use xcm::v5::{opaque::Xcm, Assets, Location, QueryId, SendError, SendResult, SendXcm, XcmHash};

pub mod assets;
pub mod credentials;
30 changes: 23 additions & 7 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ use sp_core::crypto::Ss58Codec;
pub use sp_runtime::BuildStorage;
#[cfg(feature = "runtime-benchmarks")]
use xcm::v5::{Junction::Parachain, Parent, ParentThen};
use xcm::{v4::Location, VersionedAssetId};
use xcm::{v5::Location, VersionedAssetId};

#[cfg(feature = "runtime-benchmarks")]
mod benchmark_helpers;
@@ -158,12 +158,28 @@ pub type SignedExtra = (
pallet_skip_feeless_payment::SkipCheckIfFeeless<Runtime, pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// The TransactionExtension to the basic transaction logic.
///
/// When you change this, you **MUST** modify [`sign`] in `bin/node/testing/src/keyring.rs`!
///
/// [`sign`]: <../../testing/src/keyring.rs.html>
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
pallet_dispenser::extensions::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_skip_feeless_payment::SkipCheckIfFeeless<Runtime, pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;

/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, TxExtension>;

pub type Migrations = migrations::Unreleased;

@@ -900,12 +916,12 @@ impl frame_system::offchain::SigningTypes for Runtime {
type Signature = Signature;
}

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Runtime
impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime
where
RuntimeCall: From<LocalCall>,
RuntimeCall: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = RuntimeCall;
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
@@ -928,7 +944,7 @@ where
// so the actual block number is `n`.
.saturating_sub(1);
let tip = 0;
let extra: SignedExtra = (
let extra: TxExtension = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
4 changes: 2 additions & 2 deletions runtimes/polimec/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ use polimec_common::assets::AcceptedFundingAsset;
use polimec_common_test_utils::DummyXcmSender;
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use xcm::v4::prelude::*;
use xcm::v5::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, CreateMatcher, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
@@ -127,7 +127,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
),
Balance,
xcm::v4::Location,
xcm::v5::Location,
>;

/// `AssetId`/`Balance` converter for `ContributionTokens`.
17 changes: 11 additions & 6 deletions runtimes/shared-configuration/src/fee.rs
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ impl<Runtime, Converter, FeeCreditor, TipCreditor> OnChargeAssetTransaction<Runt
for TxFeeFungiblesAdapter<Converter, FeeCreditor, TipCreditor>
where
Runtime: pallet_asset_tx_payment::Config,
Runtime::Fungibles: Inspect<AccountIdOf<Runtime>, AssetId = xcm::v4::Location>,
Runtime::Fungibles: Inspect<AccountIdOf<Runtime>, AssetId = xcm::v5::Location>,
Converter: ConversionToAssetBalance<BalanceOf<Runtime>, AssetIdOf<Runtime>, AssetBalanceOf<Runtime>>,
FeeCreditor: HandleCredit<Runtime::AccountId, Runtime::Fungibles>,
TipCreditor: HandleCredit<Runtime::AccountId, Runtime::Fungibles>,
@@ -203,15 +203,17 @@ where
) -> Result<(), TransactionValidityError> {
let asset_id: xcm::v4::Location =
asset_id.try_into().map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Payment))?;
let assed_id_v5: xcm::v5::Location =
asset_id.try_into().map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Payment))?;

let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
let converted_fee = Converter::to_asset_balance(fee, asset_id.clone())
let converted_fee = Converter::to_asset_balance(fee, assed_id_v5.clone())
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
.max(min_converted_fee);

// Ensure we can withdraw enough `asset_id` for the swap.
match <Runtime::Fungibles as fungibles::Inspect<Runtime::AccountId>>::can_withdraw(
asset_id.clone(),
assed_id_v5.clone(),
who,
converted_fee,
) {
@@ -240,17 +242,20 @@ where
// fee.
let asset_id: xcm::v4::Location =
asset_id.try_into().map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Payment))?;
let assed_id_v5: xcm::v5::Location =
asset_id.try_into().map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Payment))?;

let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
let converted_fee = Converter::to_asset_balance(fee, asset_id.clone())
let converted_fee = Converter::to_asset_balance(fee, assed_id_v5.clone())
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
.max(min_converted_fee);
let can_withdraw =
<Runtime::Fungibles as Inspect<Runtime::AccountId>>::can_withdraw(asset_id.clone(), who, converted_fee);
<Runtime::Fungibles as Inspect<Runtime::AccountId>>::can_withdraw(assed_id_v5.clone(), who, converted_fee);
if can_withdraw != WithdrawConsequence::Success {
return Err(InvalidTransaction::Payment.into())
}
<Runtime::Fungibles as fungibles::Balanced<Runtime::AccountId>>::withdraw(
asset_id,
assed_id_v5,
who,
converted_fee,
Exact,