Skip to content

Commit 934c091

Browse files
ayevbeosaAyevbeosa Iyamubkchracatangiuraymondkfcheung
authored
xcm-builder: added logging for xcm filters/helpers/matchers/types (paritytech#2408) (paritytech#7003)
# Description Added logs in pallet-xcm to help in debugging, fixes paritytech#2408, and in continuation of paritytech#4982 # Checklist - [x] https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/ - [x] https://github.com/paritytech/polkadot-sdk/tree/master/cumulus/parachains/runtimes/assets/common/src - [x] runtime-defined XCM filters/converters (just [one example](https://github.com/paritytech/polkadot-sdk/blob/183b55aae21e97ef39192e5a358287e2b6b7043c/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs#L284)) Polkadot Address: 1Gz5aLtEu2n4jsfA6XwtZnuaRymJrDDw4kEGdNHTdxrpzrc --------- Co-authored-by: Ayevbeosa Iyamu <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]> Co-authored-by: Raymond Cheung <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e915cad commit 934c091

27 files changed

+478
-341
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/runtimes/assets/common/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ workspace = true
1414
[dependencies]
1515
codec = { features = ["derive"], workspace = true }
1616
impl-trait-for-tuples = { workspace = true }
17-
log = { workspace = true }
1817
scale-info = { features = ["derive"], workspace = true }
18+
tracing = { workspace = true }
1919

2020
# Substrate
2121
frame-support = { workspace = true }
@@ -43,14 +43,14 @@ std = [
4343
"codec/std",
4444
"cumulus-primitives-core/std",
4545
"frame-support/std",
46-
"log/std",
4746
"pallet-asset-conversion/std",
4847
"pallet-assets/std",
4948
"pallet-xcm/std",
5049
"parachains-common/std",
5150
"scale-info/std",
5251
"sp-api/std",
5352
"sp-runtime/std",
53+
"tracing/std",
5454
"xcm-builder/std",
5555
"xcm-executor/std",
5656
"xcm/std",

cumulus/parachains/runtimes/assets/common/src/benchmarks.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use core::marker::PhantomData;
16+
use core::{fmt::Debug, marker::PhantomData};
1717
use cumulus_primitives_core::ParaId;
1818
use sp_runtime::traits::Get;
1919
use xcm::latest::prelude::*;
@@ -22,8 +22,10 @@ use xcm::latest::prelude::*;
2222
pub struct AssetPairFactory<Target, SelfParaId, PalletId, L = Location>(
2323
PhantomData<(Target, SelfParaId, PalletId, L)>,
2424
);
25-
impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Location>>
25+
impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Location> + Debug>
2626
pallet_asset_conversion::BenchmarkHelper<L> for AssetPairFactory<Target, SelfParaId, PalletId, L>
27+
where
28+
<L as TryFrom<Location>>::Error: Debug,
2729
{
2830
fn create_pair(seed1: u32, seed2: u32) -> (L, L) {
2931
let with_id = Location::new(
@@ -35,9 +37,31 @@ impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Loc
3537
],
3638
);
3739
if seed1 % 2 == 0 {
38-
(with_id.try_into().map_err(|_| "Something went wrong").unwrap(), Target::get())
40+
(
41+
with_id
42+
.try_into()
43+
.map_err(|error| {
44+
tracing::error!(
45+
target: "xcm",
46+
?error,
47+
"Failed to create asset pairs when seed1 is even",
48+
);
49+
"Something went wrong"
50+
})
51+
.unwrap(),
52+
Target::get(),
53+
)
3954
} else {
40-
(Target::get(), with_id.try_into().map_err(|_| "Something went wrong").unwrap())
55+
(
56+
Target::get(),
57+
with_id
58+
.try_into()
59+
.map_err(|error| {
60+
tracing::error!(target: "xcm", ?error, "Failed to create asset pairs");
61+
"Something went wrong"
62+
})
63+
.unwrap(),
64+
)
4165
}
4266
}
4367
}

cumulus/parachains/runtimes/assets/common/src/foreign_creators.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
use core::fmt::Debug;
1617
use frame_support::traits::{
1718
ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, OriginTrait,
1819
};
@@ -29,8 +30,8 @@ impl<
2930
IsForeign: ContainsPair<L, L>,
3031
AccountOf: ConvertLocation<AccountId>,
3132
AccountId: Clone,
32-
RuntimeOrigin: From<XcmOrigin> + OriginTrait + Clone,
33-
L: TryFrom<Location> + TryInto<Location> + Clone,
33+
RuntimeOrigin: From<XcmOrigin> + OriginTrait + Clone + Debug,
34+
L: TryFrom<Location> + TryInto<Location> + Clone + Debug,
3435
> EnsureOriginWithArg<RuntimeOrigin, L> for ForeignCreators<IsForeign, AccountOf, AccountId, L>
3536
where
3637
RuntimeOrigin::PalletsOrigin:
@@ -42,8 +43,10 @@ where
4243
origin: RuntimeOrigin,
4344
asset_location: &L,
4445
) -> core::result::Result<Self::Success, RuntimeOrigin> {
46+
tracing::trace!(target: "xcm::try_origin", ?origin, ?asset_location, "ForeignCreators");
4547
let origin_location = EnsureXcm::<Everything, L>::try_origin(origin.clone())?;
4648
if !IsForeign::contains(asset_location, &origin_location) {
49+
tracing::trace!(target: "xcm::try_origin", ?asset_location, ?origin_location, "ForeignCreators: no match");
4750
return Err(origin)
4851
}
4952
let latest_location: Location =

cumulus/parachains/runtimes/assets/common/src/fungible_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<
117117
for_tuples!( #(
118118
match Tuple::contains(location) { o @ true => return o, _ => () }
119119
)* );
120-
log::trace!(target: "xcm::contains", "did not match location: {:?}", &location);
120+
tracing::trace!(target: "xcm::contains", ?location, "MatchesLocation: no match");
121121
false
122122
}
123123
}

cumulus/parachains/runtimes/assets/common/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod matching;
2424
pub mod runtime_api;
2525

2626
extern crate alloc;
27+
extern crate core;
2728

2829
use crate::matching::{LocalLocationPattern, ParentLocation};
2930
use alloc::vec::Vec;

cumulus/parachains/runtimes/assets/common/src/matching.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
use core::fmt::Debug;
1617
use cumulus_primitives_core::ParaId;
1718
use frame_support::{
1819
pallet_prelude::Get,
@@ -33,8 +34,9 @@ impl<IsForeign: ContainsPair<Location, Location>> ContainsPair<Asset, Location>
3334
for IsForeignConcreteAsset<IsForeign>
3435
{
3536
fn contains(asset: &Asset, origin: &Location) -> bool {
36-
log::trace!(target: "xcm::contains", "IsForeignConcreteAsset asset: {:?}, origin: {:?}", asset, origin);
37-
matches!(asset.id, AssetId(ref id) if IsForeign::contains(id, origin))
37+
let result = matches!(asset.id, AssetId(ref id) if IsForeign::contains(id, origin));
38+
tracing::trace!(target: "xcm::contains", ?asset, ?origin, ?result, "IsForeignConcreteAsset");
39+
result
3840
}
3941
}
4042

@@ -43,10 +45,11 @@ impl<IsForeign: ContainsPair<Location, Location>> ContainsPair<Asset, Location>
4345
pub struct FromSiblingParachain<SelfParaId, L = Location>(
4446
core::marker::PhantomData<(SelfParaId, L)>,
4547
);
46-
impl<SelfParaId: Get<ParaId>, L: TryFrom<Location> + TryInto<Location> + Clone> ContainsPair<L, L>
47-
for FromSiblingParachain<SelfParaId, L>
48+
impl<SelfParaId: Get<ParaId>, L: TryFrom<Location> + TryInto<Location> + Clone + Debug>
49+
ContainsPair<L, L> for FromSiblingParachain<SelfParaId, L>
4850
{
4951
fn contains(a: &L, b: &L) -> bool {
52+
tracing::trace!(target: "xcm:contains", ?a, ?b, "FromSiblingParachain");
5053
// We convert locations to latest
5154
let a = match ((*a).clone().try_into(), (*b).clone().try_into()) {
5255
(Ok(a), Ok(b)) if a.starts_with(&b) => a, // `a` needs to be from `b` at least
@@ -70,10 +73,11 @@ pub struct FromNetwork<UniversalLocation, ExpectedNetworkId, L = Location>(
7073
impl<
7174
UniversalLocation: Get<InteriorLocation>,
7275
ExpectedNetworkId: Get<NetworkId>,
73-
L: TryFrom<Location> + TryInto<Location> + Clone,
76+
L: TryFrom<Location> + TryInto<Location> + Clone + Debug,
7477
> ContainsPair<L, L> for FromNetwork<UniversalLocation, ExpectedNetworkId, L>
7578
{
7679
fn contains(a: &L, b: &L) -> bool {
80+
tracing::trace!(target: "xcm:contains", ?a, ?b, "FromNetwork");
7781
// We convert locations to latest
7882
let a = match ((*a).clone().try_into(), (*b).clone().try_into()) {
7983
(Ok(a), Ok(b)) if a.starts_with(&b) => a, // `a` needs to be from `b` at least
@@ -86,11 +90,7 @@ impl<
8690
match ensure_is_remote(universal_source.clone(), a.clone()) {
8791
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
8892
Err(e) => {
89-
log::trace!(
90-
target: "xcm::contains",
91-
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
92-
a, universal_source, e
93-
);
93+
tracing::debug!(target: "xcm::contains", origin = ?a, ?universal_source, error = ?e, "FromNetwork origin is not remote to the universal_source");
9494
false
9595
},
9696
}
@@ -118,15 +118,20 @@ impl<
118118
let expected_origin = OriginLocation::get();
119119
// ensure `origin` is expected `OriginLocation`
120120
if !expected_origin.eq(&origin) {
121-
log::trace!(
121+
tracing::trace!(
122122
target: "xcm::contains",
123-
"RemoteAssetFromLocation asset: {asset:?}, origin: {origin:?} is not from expected {expected_origin:?}"
123+
?asset,
124+
?origin,
125+
?expected_origin,
126+
"RemoteAssetFromLocation: Asset is not from expected origin"
124127
);
125128
return false;
126129
} else {
127-
log::trace!(
130+
tracing::trace!(
128131
target: "xcm::contains",
129-
"RemoteAssetFromLocation asset: {asset:?}, origin: {origin:?}",
132+
?asset,
133+
?origin,
134+
"RemoteAssetFromLocation",
130135
);
131136
}
132137

@@ -138,6 +143,7 @@ impl<AssetsAllowedNetworks: Contains<Location>, OriginLocation: Get<Location>>
138143
ContainsPair<Asset, Location> for RemoteAssetFromLocation<AssetsAllowedNetworks, OriginLocation>
139144
{
140145
fn contains(asset: &Asset, origin: &Location) -> bool {
146+
tracing::trace!(target: "xcm:contains", ?asset, ?origin, "RemoteAssetFromLocation");
141147
<Self as ContainsPair<Location, Location>>::contains(&asset.id.0, origin)
142148
}
143149
}

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features =
1717
[dependencies]
1818
codec = { features = ["derive"], workspace = true }
1919
hex-literal = { workspace = true, default-features = true }
20-
log = { workspace = true }
2120
scale-info = { features = ["derive"], workspace = true }
2221
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
2322
serde_json = { features = ["alloc"], workspace = true }
23+
tracing = { workspace = true }
2424

2525
# Substrate
2626
frame-benchmarking = { optional = true, workspace = true }
@@ -162,7 +162,6 @@ std = [
162162
"frame-system-rpc-runtime-api/std",
163163
"frame-system/std",
164164
"frame-try-runtime?/std",
165-
"log/std",
166165
"pallet-aura/std",
167166
"pallet-authorship/std",
168167
"pallet-balances/std",
@@ -215,6 +214,7 @@ std = [
215214
"sp-version/std",
216215
"substrate-wasm-builder",
217216
"testnet-parachains-constants/std",
217+
"tracing/std",
218218
"westend-runtime-constants/std",
219219
"xcm-builder/std",
220220
"xcm-executor/std",

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,11 @@ impl_runtime_apis! {
813813
Ok(WeightToFee::weight_to_fee(&weight))
814814
},
815815
Ok(asset_id) => {
816-
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
816+
tracing::trace!(target: "xcm::xcm_runtime_apis", ?asset_id, "query_weight_to_asset_fee - unhandled asset_id!");
817817
Err(XcmPaymentApiError::AssetNotFound)
818818
},
819819
Err(_) => {
820-
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
820+
tracing::trace!(target: "xcm::xcm_runtime_apis", ?asset, "query_weight_to_asset_fee - failed to convert asset!");
821821
Err(XcmPaymentApiError::VersionedConversionFailed)
822822
}
823823
}
@@ -1163,12 +1163,15 @@ impl_runtime_apis! {
11631163
alloc::boxed::Box::new(bridge_to_rococo_config::BridgeHubRococoLocation::get()),
11641164
XCM_VERSION,
11651165
).map_err(|e| {
1166-
log::error!(
1167-
"Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
1168-
RuntimeOrigin::root(),
1169-
bridge_to_rococo_config::BridgeHubRococoLocation::get(),
1170-
XCM_VERSION,
1171-
e
1166+
let origin = RuntimeOrigin::root();
1167+
let bridge = bridge_to_rococo_config::BridgeHubRococoLocation::get();
1168+
tracing::error!(
1169+
target: "xcm::export_message_origin_and_destination",
1170+
?origin,
1171+
?bridge,
1172+
?XCM_VERSION,
1173+
?e,
1174+
"Failed to dispatch `force_xcm_version`",
11721175
);
11731176
BenchmarkError::Stop("XcmVersion was not stored!")
11741177
})?;
@@ -1198,11 +1201,12 @@ impl_runtime_apis! {
11981201
bp_messages::LegacyLaneId([1, 2, 3, 4]),
11991202
true,
12001203
).map_err(|e| {
1201-
log::error!(
1202-
"Failed to `XcmOverBridgeHubRococo::open_bridge`({:?}, {:?})`, error: {:?}",
1203-
sibling_parachain_location,
1204-
bridge_destination_universal_location,
1205-
e
1204+
tracing::error!(
1205+
target: "xcm::export_message_origin_and_destination",
1206+
?sibling_parachain_location,
1207+
?bridge_destination_universal_location,
1208+
?e,
1209+
"Failed to `XcmOverBridgeHubRococo::open_bridge`",
12061210
);
12071211
BenchmarkError::Stop("Bridge was not opened!")
12081212
})?;

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ pub type XcmOriginToTransactDispatchOrigin = (
123123
pub struct ParentOrParentsPlurality;
124124
impl Contains<Location> for ParentOrParentsPlurality {
125125
fn contains(location: &Location) -> bool {
126-
matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
126+
let result = matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]));
127+
tracing::trace!(target: "xcm::contains", ?location, ?result, "ParentOrParentsPlurality matches");
128+
result
127129
}
128130
}
129131

@@ -300,6 +302,7 @@ impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
300302
}
301303

302304
fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
305+
tracing::trace!(target: "xcm::handle_fee", ?fee, ?context, ?reason, "FeeManager handle_fee");
303306
FeeHandler::handle_fee(fee, context, reason);
304307
}
305308
}

0 commit comments

Comments
 (0)