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

Add XCM Tracing #3353

Merged
8 commits merged into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bridges/modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Pallet<T, I> {
let expected_version = <T as frame_system::Config>::Version::get().spec_version;
if message.spec_version != expected_version {
log::trace!(
target: "runtime::bridge-dispatch",
apopiak marked this conversation as resolved.
Show resolved Hide resolved
"Message {:?}/{:?}: spec_version mismatch. Expected {:?}, got {:?}",
bridge,
id,
Expand Down
1 change: 1 addition & 0 deletions xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2018"
impl-trait-for-tuples = "0.2.0"
parity-scale-codec = { version = "2.0.0", default-features = false, features = [ "derive" ] }
derivative = {version = "2.2.0", default-features = false, features = [ "use_core" ] }
log = { version = "0.4.14", default-features = false }

[features]
default = ["std"]
Expand Down
1 change: 1 addition & 0 deletions xcm/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
log = { version = "0.4.14", default-features = false }

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down
1 change: 1 addition & 0 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub mod pallet {
MultiLocation::Null => message,
who => Xcm::<()>::RelayedFrom { who, message: Box::new(message) },
};
log::trace!(target: "xcm::send_xcm", "dest: {:?}, message: {:?}", &dest, &message);
T::XcmRouter::send_xcm(dest, message)
}

Expand Down
5 changes: 5 additions & 0 deletions xcm/src/v0/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pub trait ExecuteXcm<Call> {
/// a basic hard-limit and the implementation may place further restrictions or requirements on weight and
/// other aspects.
fn execute_xcm(origin: MultiLocation, message: Xcm<Call>, weight_limit: Weight) -> Outcome {
log::debug!(
target: "xcm::execute_xcm",
"origin: {:?}, message: {:?}, weight_limit: {:?}",
&origin, &message, weight_limit,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log I feel unsure about
Feels useful to be able to just add -lxcm=debug and get some measure of logging, but also adds this to (most) every implementation automatically. Also doesn't capture direct calls to execute_xcm_in_credit (which e.g. teleport_assets does).

Self::execute_xcm_in_credit(origin, message, weight_limit, 0)
}

Expand Down
18 changes: 17 additions & 1 deletion xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> {
weight_limit: Weight,
mut weight_credit: Weight,
) -> Outcome {
log::trace!(
target: "xcm::execute_xcm_in_credit",
"origin: {:?}, message: {:?}, weight_limit: {:?}, weight_credit: {:?}",
&origin, &message, weight_limit, weight_credit,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
// TODO: #2841 #HARDENXCM We should identify recursive bombs here and bail.
let mut message = Xcm::<Config::Call>::from(message);
let shallow_weight = match Config::Weigher::shallow(&mut message) {
Expand All @@ -67,6 +72,7 @@ impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> {
let mut trader = Config::Trader::new();
let result = Self::do_execute_xcm(origin, true, message, &mut weight_credit, Some(shallow_weight), &mut trader);
drop(trader);
log::trace!(target: "xcm::execute_xcm", "result: {:?}", &result);
match result {
Ok(surplus) => Outcome::Complete(maximum_weight.saturating_sub(surplus)),
// TODO: #2841 #REALWEIGHT We can do better than returning `maximum_weight` here, and we should otherwise
Expand Down Expand Up @@ -94,6 +100,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
maybe_shallow_weight: Option<Weight>,
trader: &mut Config::Trader,
) -> Result<Weight, XcmError> {
log::trace!(
target: "xcm::do_execute_xcm",
"origin: {:?}, top_level: {:?}, message: {:?}, weight_credit: {:?}, maybe_shallow_weight: {:?}",
&origin, top_level, &message, weight_credit, maybe_shallow_weight,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
// This is the weight of everything that cannot be paid for. This basically means all computation
// except any XCM which is behind an Order::BuyExecution.
let shallow_weight = maybe_shallow_weight
Expand Down Expand Up @@ -165,7 +176,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
}
Some((Assets::from(assets), effects))
}
(origin, Xcm::Transact { origin_type, require_weight_at_most, mut call }) => {
(origin, Xcm::Transact { origin_type, require_weight_at_most, mut call }) => {
// We assume that the Relay-chain is allowed to use transact on this parachain.

// TODO: #2841 #TRANSACTFILTER allow the trait to issue filters for the relay-chain
Expand Down Expand Up @@ -225,6 +236,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
effect: Order<Config::Call>,
trader: &mut Config::Trader,
) -> Result<Weight, XcmError> {
log::trace!(
target: "xcm::execute_effects",
"origin: {:?}, holding: {:?}, effect: {:?}",
origin, holding, &effect,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
let mut total_surplus = 0;
match effect {
Order::DepositAsset { assets, dest } => {
Expand Down
5 changes: 5 additions & 0 deletions xcm/xcm-executor/src/traits/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ impl<O> ConvertOrigin<O> for Tuple {
r => return r
};
)* );
log::trace!(
target: "xcm::convert_origin",
"could not convert: origin: {:?}, kind: {:?}",
&origin, &kind
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(origin)
}
}
Expand Down
5 changes: 5 additions & 0 deletions xcm/xcm-executor/src/traits/filter_asset_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ impl FilterAssetLocation for Tuple {
for_tuples!( #(
if Tuple::filter_asset_location(what, origin) { return true }
)* );
log::trace!(
target: "xcm::filter_asset_location",
"got filtered: what: {:?}, origin: {:?}",
&what, &origin,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
false
}
}
1 change: 1 addition & 0 deletions xcm/xcm-executor/src/traits/matches_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl<Balance> MatchesFungible<Balance> for Tuple {
for_tuples!( #(
match Tuple::matches_fungible(a) { o @ Some(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_fungible", "did not match fungible asset: {:?}", &a);
None
}
}
1 change: 1 addition & 0 deletions xcm/xcm-executor/src/traits/matches_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl<
for_tuples!( #(
match Tuple::matches_fungibles(a) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_fungibles", "did not match fungibles asset: {:?}", &a);
Err(Error::AssetNotFound)
}
}
5 changes: 5 additions & 0 deletions xcm/xcm-executor/src/traits/should_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ impl ShouldExecute for Tuple {
_ => (),
}
)* );
log::trace!(
target: "xcm::should_execute",
"did not pass barrier: origin: {:?}, top_level: {:?}, message: {:?}, shallow_weight: {:?}, weight_credit: {:?}",
&origin, top_level, &message, shallow_weight, weight_credit
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(())
}
}
25 changes: 25 additions & 0 deletions xcm/xcm-executor/src/traits/transact_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,59 @@ impl TransactAsset for Tuple {
r => return r,
}
)* );
log::trace!(
target: "xcm::TransactAsset::can_check_in",
"asset not found: what: {:?}, origin: {:?}",
&what, &origin,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(XcmError::AssetNotFound)
}

fn check_in(origin: &MultiLocation, what: &MultiAsset) {
for_tuples!( #(
Tuple::check_in(origin, what);
)* );
}

fn check_out(dest: &MultiLocation, what: &MultiAsset) {
for_tuples!( #(
Tuple::check_out(dest, what);
)* );
}

fn deposit_asset(what: &MultiAsset, who: &MultiLocation) -> XcmResult {
for_tuples!( #(
match Tuple::deposit_asset(what, who) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(
target: "xcm::TransactAsset::deposit_asset",
"did not deposit asset: what: {:?}, who: {:?}",
&what, &who,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(XcmError::Unimplemented)
}

fn withdraw_asset(what: &MultiAsset, who: &MultiLocation) -> Result<Assets, XcmError> {
for_tuples!( #(
match Tuple::withdraw_asset(what, who) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(
target: "xcm::TransactAsset::withdraw_asset",
"did not withdraw asset: what: {:?}, who: {:?}",
&what, &who,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(XcmError::Unimplemented)
}

fn transfer_asset(what: &MultiAsset, from: &MultiLocation, to: &MultiLocation) -> Result<Assets, XcmError> {
for_tuples!( #(
match Tuple::transfer_asset(what, from, to) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(
target: "xcm::TransactAsset::transfer_asset",
"did not transfer asset: what: {:?}, from: {:?}, to: {:?}",
&what, &from, &to,
apopiak marked this conversation as resolved.
Show resolved Hide resolved
);
Err(XcmError::Unimplemented)
}
}