Skip to content

Commit

Permalink
Use log crate for runtime logging
Browse files Browse the repository at this point in the history
See paritytech/substrate#8128 for more info.
  • Loading branch information
HCastano committed Mar 5, 2021
1 parent bcfc627 commit ca2b26e
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 74 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions bin/rialto/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
hex-literal = "0.3"
libsecp256k1 = { version = "0.3.4", optional = true, default-features = false, features = ["hmac"] }
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.123", optional = true, features = ["derive"] }

# Bridge dependencies
Expand Down Expand Up @@ -86,6 +87,7 @@ std = [
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"log/std",
"pallet-aura/std",
"pallet-balances/std",
"pallet-bridge-eth-poa/std",
Expand Down
6 changes: 3 additions & 3 deletions bin/rialto/runtime/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl MaybeLockFundsTransaction for EthTransaction {

// we only accept transactions sending funds directly to the pre-configured address
if tx.unsigned.to != Some(LOCK_FUNDS_ADDRESS.into()) {
frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Failed to parse fund locks transaction. Invalid peer recipient: {:?}",
tx.unsigned.to,
Expand All @@ -94,7 +94,7 @@ impl MaybeLockFundsTransaction for EthTransaction {
match tx.unsigned.payload.len() {
32 => recipient_raw.as_fixed_bytes_mut().copy_from_slice(&tx.unsigned.payload),
len => {
frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Failed to parse fund locks transaction. Invalid recipient length: {}",
len,
Expand All @@ -106,7 +106,7 @@ impl MaybeLockFundsTransaction for EthTransaction {
let amount = tx.unsigned.value.low_u128();

if tx.unsigned.value != amount.into() {
frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Failed to parse fund locks transaction. Invalid amount: {}",
tx.unsigned.value,
Expand Down
6 changes: 3 additions & 3 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl bp_currency_exchange::DepositInto for DepositInto {
// - deposited != 0: (should never happen in practice) deposit has been partially completed
match deposited_amount {
_ if deposited_amount == amount => {
frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Deposited {} to {:?}",
amount,
Expand All @@ -299,7 +299,7 @@ impl bp_currency_exchange::DepositInto for DepositInto {
Ok(())
}
_ if deposited_amount == 0 => {
frame_support::debug::error!(
log::error!(
target: "runtime",
"Deposit of {} to {:?} has failed",
amount,
Expand All @@ -309,7 +309,7 @@ impl bp_currency_exchange::DepositInto for DepositInto {
Err(bp_currency_exchange::Error::DepositFailed)
}
_ => {
frame_support::debug::error!(
log::error!(
target: "runtime",
"Deposit of {} to {:?} has partially competed. {} has been deposited",
amount,
Expand Down
2 changes: 2 additions & 0 deletions modules/call-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
log = { version = "0.4.14", default-features = false }

# Bridge dependencies

Expand All @@ -33,6 +34,7 @@ std = [
"bp-runtime/std",
"frame-support/std",
"frame-system/std",
"log/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
22 changes: 11 additions & 11 deletions modules/call-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let message = match message {
Ok(message) => message,
Err(_) => {
frame_support::debug::trace!("Message {:?}/{:?}: rejected before actual dispatch", bridge, id);
log::trace!("Message {:?}/{:?}: rejected before actual dispatch", bridge, id);
Self::deposit_event(RawEvent::MessageRejected(bridge, id));
return;
}
Expand All @@ -212,7 +212,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
// (we want it to be the same, because otherwise we may decode Call improperly)
let expected_version = <T as frame_system::Config>::Version::get().spec_version;
if message.spec_version != expected_version {
frame_support::debug::trace!(
log::trace!(
"Message {:?}/{:?}: spec_version mismatch. Expected {:?}, got {:?}",
bridge,
id,
Expand All @@ -232,7 +232,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let call = match message.call.into() {
Ok(call) => call,
Err(_) => {
frame_support::debug::trace!("Failed to decode Call from message {:?}/{:?}", bridge, id,);
log::trace!("Failed to decode Call from message {:?}/{:?}", bridge, id,);
Self::deposit_event(RawEvent::MessageCallDecodeFailed(bridge, id));
return;
}
Expand All @@ -243,15 +243,15 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
CallOrigin::SourceRoot => {
let hex_id = derive_account_id::<T::SourceChainAccountId>(bridge, SourceAccount::Root);
let target_id = T::AccountIdConverter::convert(hex_id);
frame_support::debug::trace!("Root Account: {:?}", &target_id);
log::trace!("Root Account: {:?}", &target_id);
target_id
}
CallOrigin::TargetAccount(source_account_id, target_public, target_signature) => {
let digest = account_ownership_digest(&call, source_account_id, message.spec_version, bridge);

let target_account = target_public.into_account();
if !target_signature.verify(&digest[..], &target_account) {
frame_support::debug::trace!(
log::trace!(
"Message {:?}/{:?}: origin proof is invalid. Expected account: {:?} from signature: {:?}",
bridge,
id,
Expand All @@ -262,20 +262,20 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
return;
}

frame_support::debug::trace!("Target Account: {:?}", &target_account);
log::trace!("Target Account: {:?}", &target_account);
target_account
}
CallOrigin::SourceAccount(source_account_id) => {
let hex_id = derive_account_id(bridge, SourceAccount::Account(source_account_id));
let target_id = T::AccountIdConverter::convert(hex_id);
frame_support::debug::trace!("Source Account: {:?}", &target_id);
log::trace!("Source Account: {:?}", &target_id);
target_id
}
};

// filter the call
if !T::CallFilter::filter(&call) {
frame_support::debug::trace!(
log::trace!(
"Message {:?}/{:?}: the call ({:?}) is rejected by filter",
bridge,
id,
Expand All @@ -291,7 +291,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let dispatch_info = call.get_dispatch_info();
let expected_weight = dispatch_info.weight;
if message.weight < expected_weight {
frame_support::debug::trace!(
log::trace!(
"Message {:?}/{:?}: passed weight is too low. Expected at least {:?}, got {:?}",
bridge,
id,
Expand All @@ -310,11 +310,11 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
// finally dispatch message
let origin = RawOrigin::Signed(origin_account).into();

frame_support::debug::trace!("Message being dispatched is: {:?}", &call);
log::trace!("Message being dispatched is: {:?}", &call);
let dispatch_result = call.dispatch(origin);
let actual_call_weight = extract_actual_weight(&dispatch_result, &dispatch_info);

frame_support::debug::trace!(
log::trace!(
"Message {:?}/{:?} has been dispatched. Weight: {} of {}. Result: {:?}",
bridge,
id,
Expand Down
2 changes: 2 additions & 0 deletions modules/currency-exchange/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0", optional = true }

# Bridge dependencies
Expand Down Expand Up @@ -36,6 +37,7 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"serde",
"sp-runtime/std",
"sp-std/std",
Expand Down
4 changes: 2 additions & 2 deletions modules/currency-exchange/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ decl_module! {
// reward submitter for providing valid message
T::OnTransactionSubmitted::on_valid_transaction_submitted(submitter);

frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Completed currency exchange: {:?}",
deposit.transfer_id,
Expand All @@ -138,7 +138,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
proof: &<T::PeerBlockchain as InclusionProofVerifier>::TransactionInclusionProof,
) -> bool {
if let Err(err) = prepare_deposit_details::<T, I>(proof) {
frame_support::debug::trace!(
log::trace!(
target: "runtime",
"Can't accept exchange transaction: {:?}",
err,
Expand Down
2 changes: 2 additions & 0 deletions modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"], optional = true }
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0", optional = true }

# Bridge dependencies
Expand Down Expand Up @@ -36,6 +37,7 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"serde",
"sp-io/std",
"sp-runtime/std",
Expand Down
Loading

0 comments on commit ca2b26e

Please sign in to comment.