Skip to content

Commit

Permalink
formatted affected crates
Browse files Browse the repository at this point in the history
  • Loading branch information
x3c41a committed Sep 27, 2024
1 parent 598ae4a commit bf1f2b3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
pub mod genesis;

pub use bridge_hub_westend_runtime::{
self,
xcm_config::XcmConfig as BridgeHubWestendXcmConfig,
self, xcm_config::XcmConfig as BridgeHubWestendXcmConfig,
ExistentialDeposit as BridgeHubWestendExistentialDeposit,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. }
RuntimeCall::Nfts { .. } |
RuntimeCall::Uniques { .. }
)
},
ProxyType::AssetOwner => matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. }
RuntimeCall::Nfts { .. } |
RuntimeCall::Uniques { .. }
)
},
ProxyType::AssetOwner => matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor;
use sp_runtime::traits::{AccountIdConversion, ConvertInto, TryConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribePalletTerminal, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint, MatchedConvertedConcreteId, NetworkExportTableItem, NoChecking, NonFungiblesAdapter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SingleAssetExchangeAdapter, SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, XcmFeeManagerFromComponents};
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily,
DescribePalletTerminal, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter,
FungiblesAdapter, GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete,
LocalMint, MatchedConvertedConcreteId, NetworkExportTableItem, NoChecking, NonFungiblesAdapter,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SingleAssetExchangeAdapter, SovereignPaidRemoteExporter,
SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
WithLatestLocationConverter, WithUniqueTopic, XcmFeeManagerFromComponents,
};
use xcm_executor::XcmExecutor;

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ use sp_runtime::traits::AccountIdConversion;
use sp_std::marker::PhantomData;
use testnet_parachains_constants::westend::snowbridge::EthereumNetwork;
use xcm::latest::prelude::*;
use xcm_builder::{AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribePalletTerminal, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, GlobalConsensusParachainConvertsFor, HandleFee, HashedDescription, IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic};
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily,
DescribePalletTerminal, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter,
GlobalConsensusParachainConvertsFor, HandleFee, HashedDescription, IsConcrete,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{
traits::{FeeManager, FeeReason, FeeReason::Export},
XcmExecutor,
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,8 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn generate_holding_assets(max_assets: u32) -> Assets {
let fungibles_amount: u128 = 100;
let holding_fungibles = max_assets / 2;
let holding_non_fungibles = max_assets - holding_fungibles - 1; // -1 because of adding `Here` asset
// add count of `holding_fungibles`
// add count of `holding_fungibles`
(0..holding_fungibles)
.map(|i| {
Asset {
Expand Down
42 changes: 26 additions & 16 deletions polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ impl<Config: config::Config> XcmExecutor<Config> {
pub fn set_topic(&mut self, v: Option<[u8; 32]>) {
self.context.topic = v;
}
pub fn asset_claimer(&self) -> Option<Location> { self.asset_claimer.clone() }
pub fn asset_claimer(&self) -> Option<Location> {
self.asset_claimer.clone()
}
}

pub struct WeighedMessage<Call>(Weight, Xcm<Call>);
Expand Down Expand Up @@ -369,8 +371,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
} else {
self.context.origin.as_ref().unwrap_or(&self.original_origin)
};
let trap_weight =
Config::AssetTrap::drop_assets(claimer, self.holding, &self.context);
let trap_weight = Config::AssetTrap::drop_assets(claimer, self.holding, &self.context);
weight_used.saturating_accrue(trap_weight);
};

Expand Down Expand Up @@ -534,13 +535,20 @@ impl<Config: config::Config> XcmExecutor<Config> {
} else {
// This condition exists to support `BuyExecution` while the ecosystem
// transitions to `PayFees`.
let assets_taken_from_holding_to_pay_delivery_fees: AssetsInHolding = if self.fees.is_empty() {
// Means `BuyExecution` was used, we'll find the fees in the `holding` register.
self.holding.try_take(asset_to_pay_for_fees.clone().into()).map_err(|_| XcmError::NotHoldingFees)?.into()
} else {
// Means `PayFees` was used, we'll find the fees in the `fees` register.
self.fees.try_take(asset_to_pay_for_fees.clone().into()).map_err(|_| XcmError::NotHoldingFees)?.into()
};
let assets_taken_from_holding_to_pay_delivery_fees: AssetsInHolding =
if self.fees.is_empty() {
// Means `BuyExecution` was used, we'll find the fees in the `holding` register.
self.holding
.try_take(asset_to_pay_for_fees.clone().into())
.map_err(|_| XcmError::NotHoldingFees)?
.into()
} else {
// Means `PayFees` was used, we'll find the fees in the `fees` register.
self.fees
.try_take(asset_to_pay_for_fees.clone().into())
.map_err(|_| XcmError::NotHoldingFees)?
.into()
};
tracing::trace!(target: "xcm::fees", ?assets_taken_from_holding_to_pay_delivery_fees);
let mut iter = assets_taken_from_holding_to_pay_delivery_fees.fungible_assets_iter();
let asset = iter.next().ok_or(XcmError::NotHoldingFees)?;
Expand Down Expand Up @@ -991,24 +999,26 @@ impl<Config: config::Config> XcmExecutor<Config> {
let old_holding = self.holding.clone();
let result = Config::TransactionalProcessor::process(|| {
let maybe_delivery_fee = if self.fees.is_empty() {
// we need to do this take/put cycle to solve wildcards and get exact assets to
// be weighed
// we need to do this take/put cycle to solve wildcards and get exact assets
// to be weighed
let to_weigh = self.holding.saturating_take(assets.clone());
self.holding.subsume_assets(to_weigh.clone());
let to_weigh_reanchored = Self::reanchored(to_weigh, &dest, None);
let mut message_to_weigh =
vec![ReserveAssetDeposited(to_weigh_reanchored), ClearOrigin];
message_to_weigh.extend(xcm.0.clone().into_iter());
let (_, fee) =
validate_send::<Config::XcmSender>(dest.clone(), Xcm(message_to_weigh))?;
let (_, fee) = validate_send::<Config::XcmSender>(
dest.clone(),
Xcm(message_to_weigh),
)?;
let maybe_delivery_fee = fee.get(0).map(|asset_needed_for_fees| {
tracing::trace!(
target: "xcm::DepositReserveAsset",
"Asset provided to pay for fees {:?}, asset required for delivery fees: {:?}",
self.asset_used_for_fees, asset_needed_for_fees,
);
let asset_to_pay_for_fees =
self.calculate_asset_for_delivery_fees(asset_needed_for_fees.clone());
let asset_to_pay_for_fees = self
.calculate_asset_for_delivery_fees(asset_needed_for_fees.clone());
// set aside fee to be charged by XcmSender
let delivery_fee =
self.holding.saturating_take(asset_to_pay_for_fees.into());
Expand Down
192 changes: 96 additions & 96 deletions polkadot/xcm/xcm-executor/src/tests/set_asset_claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,112 +27,112 @@ use crate::XcmExecutor;

#[test]
fn set_asset_claimer() {
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.set_asset_claimer(bob.clone())
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_ok());
assert_eq!(vm.asset_claimer(), Some(bob));
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.set_asset_claimer(bob.clone())
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_ok());
assert_eq!(vm.asset_claimer(), Some(bob));
}

#[test]
fn do_not_set_asset_claimer_none() {
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_ok());
assert_eq!(vm.asset_claimer(), None);
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_ok());
assert_eq!(vm.asset_claimer(), None);
}

#[test]
fn trap_then_set_asset_claimer() {
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.trap(0u64)
.set_asset_claimer(bob)
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_err());
assert_eq!(vm.asset_claimer(), None);
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.trap(0u64)
.set_asset_claimer(bob)
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_err());
assert_eq!(vm.asset_claimer(), None);
}

#[test]
fn set_asset_claimer_then_trap() {
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.set_asset_claimer(bob.clone())
.trap(0u64)
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_err());
assert_eq!(vm.asset_claimer(), Some(bob));
let sender = Location::new(0, [AccountId32 { id: [0; 32], network: None }]);
let bob = Location::new(0, [AccountId32 { id: [2; 32], network: None }]);

// Make sure the user has enough funds to withdraw.
add_asset(sender.clone(), (Here, 100u128));

// Build xcm.
let xcm = Xcm::<TestCall>::builder_unsafe()
// if withdrawing fails we're not missing any corner case.
.withdraw_asset((Here, 100u128))
.clear_origin()
.set_asset_claimer(bob.clone())
.trap(0u64)
.pay_fees((Here, 10u128)) // 10% destined for fees, not more.
.build();

// We create an XCVM instance instead of calling `XcmExecutor::<_>::prepare_and_execute` so we
// can inspect its fields.
let mut vm =
XcmExecutor::<XcmConfig>::new(sender, xcm.using_encoded(sp_io::hashing::blake2_256));
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(xcm.clone()).unwrap().weight_of();

let result = vm.bench_process(xcm);
assert!(result.is_err());
assert_eq!(vm.asset_claimer(), Some(bob));
}

0 comments on commit bf1f2b3

Please sign in to comment.