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

xcm-builder: added logging for xcm filters/helpers/matchers/types (#2408) #7003

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/assets/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ workspace = true
[dependencies]
codec = { features = ["derive"], workspace = true }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
tracing = { workspace = true }

# Substrate
frame-support = { workspace = true }
Expand Down Expand Up @@ -43,14 +43,14 @@ std = [
"codec/std",
"cumulus-primitives-core/std",
"frame-support/std",
"log/std",
"pallet-asset-conversion/std",
"pallet-assets/std",
"pallet-xcm/std",
"parachains-common/std",
"scale-info/std",
"sp-api/std",
"sp-runtime/std",
"tracing/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
Expand Down
26 changes: 24 additions & 2 deletions cumulus/parachains/runtimes/assets/common/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,31 @@ impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Loc
],
);
if seed1 % 2 == 0 {
(with_id.try_into().map_err(|_| "Something went wrong").unwrap(), Target::get())
(
with_id
.try_into()
.map_err(|error| {
tracing::error!(
target: "xcm",
?error,
"Failed to create asset pairs when seed1 is even",
);
"Something went wrong"
})
.unwrap(),
Target::get(),
)
} else {
(Target::get(), with_id.try_into().map_err(|_| "Something went wrong").unwrap())
(
Target::get(),
with_id
.try_into()
.map_err(|error| {
tracing::error!(target: "xcm", ?error, "Failed to create asset pairs");
"Something went wrong"
})
.unwrap(),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<
for_tuples!( #(
match Tuple::contains(location) { o @ true => return o, _ => () }
)* );
log::trace!(target: "xcm::contains", "did not match location: {:?}", &location);
tracing::trace!(target: "xcm::contains", ?location, "did not match location");
false
}
}
Expand All @@ -142,7 +142,10 @@ pub fn convert_balance<T: frame_support::pallet_prelude::Get<Location>, Balance:
) -> Result<Asset, FungiblesAccessError> {
match balance.try_into() {
Ok(balance) => Ok((T::get(), balance).into()),
Err(_) => Err(FungiblesAccessError::AmountToBalanceConversionFailed),
Err(_) => {
tracing::error!(target: "xcm::convert_balance", "Failed to convert balance with location to asset");
Err(FungiblesAccessError::AmountToBalanceConversionFailed)
},
}
}

Expand Down
12 changes: 4 additions & 8 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<IsForeign: ContainsPair<Location, Location>> ContainsPair<Asset, Location>
for IsForeignConcreteAsset<IsForeign>
{
fn contains(asset: &Asset, origin: &Location) -> bool {
log::trace!(target: "xcm::contains", "IsForeignConcreteAsset asset: {:?}, origin: {:?}", asset, origin);
tracing::trace!(target: "xcm::contains", ?asset, ?origin, "IsForeignConcreteAsset");
matches!(asset.id, AssetId(ref id) if IsForeign::contains(id, origin))
}
}
Expand Down Expand Up @@ -86,11 +86,7 @@ impl<
match ensure_is_remote(universal_source.clone(), a.clone()) {
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
Err(e) => {
log::trace!(
target: "xcm::contains",
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
a, universal_source, e
);
tracing::trace!(target: "xcm::contains", ?a, ?universal_source, ?e, "FromNetwork origin is not remote to the universal_source");
false
},
}
Expand Down Expand Up @@ -118,13 +114,13 @@ impl<
let expected_origin = OriginLocation::get();
// ensure `origin` is expected `OriginLocation`
if !expected_origin.eq(&origin) {
log::trace!(
tracing::trace!(
target: "xcm::contains",
"RemoteAssetFromLocation asset: {asset:?}, origin: {origin:?} is not from expected {expected_origin:?}"
);
return false;
} else {
log::trace!(
tracing::trace!(
target: "xcm::contains",
"RemoteAssetFromLocation asset: {asset:?}, origin: {origin:?}",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
pub struct ParentOrParentsPlurality;
impl Contains<Location> for ParentOrParentsPlurality {
fn contains(location: &Location) -> bool {
log::trace!(target: "xcm::contains", "did match location: {:?}", &location);
matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
}
}
Expand Down Expand Up @@ -300,6 +301,7 @@ impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
}

fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
log::info!(target: "xcm::handle_fee", "handle fee: {:?}, with reason: {:?}", &fee, &reason);
FeeHandler::handle_fee(fee, context, reason);
}
}
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ codec = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
pallet-asset-conversion = { workspace = true }
pallet-transaction-payment = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-arithmetic = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-weights = { workspace = true }
tracing = { workspace = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }

Expand Down Expand Up @@ -65,7 +65,6 @@ std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-asset-conversion/std",
"pallet-transaction-payment/std",
"polkadot-parachain-primitives/std",
Expand All @@ -75,6 +74,7 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-weights/std",
"tracing/std",
"xcm-executor/std",
"xcm/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
) -> Result<AssetsInHolding, AssetsInHolding> {
let mut give_iter = give.fungible_assets_iter();
let give_asset = give_iter.next().ok_or_else(|| {
log::trace!(
tracing::trace!(
target: "xcm::SingleAssetExchangeAdapter::exchange_asset",
"No fungible asset was in `give`.",
);
Expand All @@ -73,21 +73,21 @@ where
let want_asset = want.get(0).ok_or_else(|| give.clone())?;
let (give_asset_id, give_amount) =
Matcher::matches_fungibles(&give_asset).map_err(|error| {
log::trace!(
tracing::trace!(
target: "xcm::SingleAssetExchangeAdapter::exchange_asset",
"Could not map XCM asset give {:?} to FRAME asset. Error: {:?}",
give_asset,
error,
?give_asset,
?error,
"Could not map XCM asset give to FRAME asset.",
);
give.clone()
})?;
let (want_asset_id, want_amount) =
Matcher::matches_fungibles(&want_asset).map_err(|error| {
log::trace!(
tracing::trace!(
target: "xcm::SingleAssetExchangeAdapter::exchange_asset",
"Could not map XCM asset want {:?} to FRAME asset. Error: {:?}",
want_asset,
error,
?want_asset,
?error,
"Could not map XCM asset want to FRAME asset. Error"
);
give.clone()
})?;
Expand All @@ -106,10 +106,10 @@ where
Some(want_amount),
)
.map_err(|(credit_in, error)| {
log::error!(
tracing::error!(
target: "xcm::SingleAssetExchangeAdapter::exchange_asset",
"Could not perform the swap, error: {:?}.",
error
?error,
"Could not perform the swap, error"
);
drop(credit_in);
give.clone()
Expand All @@ -127,10 +127,10 @@ where
want_amount,
)
.map_err(|(credit_in, error)| {
log::error!(
tracing::error!(
target: "xcm::SingleAssetExchangeAdapter::exchange_asset",
"Could not perform the swap, error: {:?}.",
error
?error,
"Could not perform the swap with error",
);
drop(credit_in);
give.clone()
Expand Down Expand Up @@ -162,22 +162,22 @@ where
// We first match both XCM assets to the asset ID types `AssetConversion` can handle.
let (give_asset_id, give_amount) = Matcher::matches_fungibles(give_asset)
.map_err(|error| {
log::trace!(
tracing::trace!(
target: "xcm::SingleAssetExchangeAdapter::quote_exchange_price",
"Could not map XCM asset {:?} to FRAME asset. Error: {:?}.",
give_asset,
error,
?give_asset,
?error,
"Could not map XCM asset to FRAME asset."
);
()
})
.ok()?;
let (want_asset_id, want_amount) = Matcher::matches_fungibles(want_asset)
.map_err(|error| {
log::trace!(
tracing::trace!(
target: "xcm::SingleAssetExchangeAdapter::quote_exchange_price",
"Could not map XCM asset {:?} to FRAME asset. Error: {:?}.",
want_asset,
error,
?want_asset,
?error,
"Could not map XCM asset to FRAME asset"
);
()
})
Expand Down
Loading
Loading