contracts Add LOG_TARGET constant (#14002)

* contracts Add LOG_TARGET constant

* Update frame/contracts/src/lib.rs

Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>

---------

Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
This commit is contained in:
PG Herveou
2023-04-25 13:46:20 +02:00
committed by GitHub
parent bcf7601169
commit c11cb1b274
5 changed files with 21 additions and 14 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ use crate::{
gas::GasMeter,
storage::{self, DepositAccount, WriteOutcome},
BalanceOf, CodeHash, Config, ContractInfo, ContractInfoOf, DebugBufferVec, Determinism, Error,
Event, Nonce, Pallet as Contracts, Schedule, System,
Event, Nonce, Pallet as Contracts, Schedule, System, LOG_TARGET,
};
use frame_support::{
crypto::ecdsa::ECDSAExt,
@@ -1002,7 +1002,7 @@ where
} else {
if let Some((msg, false)) = self.debug_message.as_ref().map(|m| (m, m.is_empty())) {
log::debug!(
target: "runtime::contracts",
target: LOG_TARGET,
"Execution finished with debug buffer: {}",
core::str::from_utf8(msg).unwrap_or("<Invalid UTF8>"),
);
@@ -1331,7 +1331,7 @@ where
.try_extend(&mut msg.bytes())
.map_err(|_| {
log::debug!(
target: "runtime::contracts",
target: LOG_TARGET,
"Debug buffer (of {} bytes) exhausted!",
DebugBufferVec::<T>::bound(),
)
+7
View File
@@ -163,6 +163,13 @@ type OldWeight = u64;
/// that this value makes sense for a memory location or length.
const SENTINEL: u32 = u32::MAX;
/// The target that is used for the log output emitted by this crate.
///
/// Hence you can use this target to selectively increase the log level for this crate.
///
/// Example: `RUST_LOG=runtime::contracts=debug my_code --dev`
const LOG_TARGET: &str = "runtime::contracts";
#[frame_support::pallet]
pub mod pallet {
use super::*;
@@ -19,7 +19,7 @@
use crate::{
storage::{ContractInfo, DepositAccount},
BalanceOf, Config, Error, Inspect, Pallet, System,
BalanceOf, Config, Error, Inspect, Pallet, System, LOG_TARGET,
};
use codec::Encode;
use frame_support::{
@@ -502,7 +502,7 @@ impl<T: Config> Ext<T> for ReservingExt {
);
if let Err(err) = result {
log::error!(
target: "runtime::contracts",
target: LOG_TARGET,
"Failed to transfer storage deposit {:?} from origin {:?} to deposit account {:?}: {:?}",
amount, origin, deposit_account, err,
);
@@ -531,7 +531,7 @@ impl<T: Config> Ext<T> for ReservingExt {
);
if matches!(result, Err(_)) {
log::error!(
target: "runtime::contracts",
target: LOG_TARGET,
"Failed to refund storage deposit {:?} from deposit account {:?} to origin {:?}: {:?}",
amount, deposit_account, origin, result,
);
+3 -3
View File
@@ -43,7 +43,7 @@ use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
gas::GasMeter,
AccountIdOf, BalanceOf, CodeHash, CodeVec, Config, Error, OwnerInfoOf, RelaxedCodeVec,
Schedule,
Schedule, LOG_TARGET,
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::dispatch::{DispatchError, DispatchResult};
@@ -326,7 +326,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
},
)
.map_err(|msg| {
log::debug!(target: "runtime::contracts", "failed to instantiate code: {}", msg);
log::debug!(target: LOG_TARGET, "failed to instantiate code: {}", msg);
Error::<T>::CodeRejected
})?;
store.data_mut().set_memory(memory);
@@ -335,7 +335,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
.get_export(&store, function.identifier())
.and_then(|export| export.into_func())
.ok_or_else(|| {
log::error!(target: "runtime::contracts", "failed to find entry point");
log::error!(target: LOG_TARGET, "failed to find entry point");
Error::<T>::CodeRejected
})?;
@@ -25,7 +25,7 @@ use crate::{
wasm::{
runtime::AllowDeprecatedInterface, Determinism, Environment, OwnerInfo, PrefabWasmModule,
},
AccountIdOf, CodeVec, Config, Error, Schedule,
AccountIdOf, CodeVec, Config, Error, Schedule, LOG_TARGET,
};
use codec::{Encode, MaxEncodedLen};
use sp_runtime::{traits::Hash, DispatchError};
@@ -379,7 +379,7 @@ where
})
.validate_all(original_code)
.map_err(|err| {
log::debug!(target: "runtime::contracts", "{}", err);
log::debug!(target: LOG_TARGET, "{}", err);
(Error::<T>::CodeRejected.into(), "validation of new code failed")
})?;
@@ -403,7 +403,7 @@ where
Ok((code, memory_limits))
})()
.map_err(|msg: &str| {
log::debug!(target: "runtime::contracts", "new code rejected: {}", msg);
log::debug!(target: LOG_TARGET, "new code rejected: {}", msg);
(Error::<T>::CodeRejected.into(), msg)
})?;
@@ -426,7 +426,7 @@ where
},
)
.map_err(|err| {
log::debug!(target: "runtime::contracts", "{}", err);
log::debug!(target: LOG_TARGET, "{}", err);
(Error::<T>::CodeRejected.into(), "new code rejected after instrumentation")
})?;
}
@@ -518,7 +518,7 @@ where
InstrumentReason::Reinstrument,
)
.map_err(|(err, msg)| {
log::error!(target: "runtime::contracts", "CodeRejected during reinstrument: {}", msg);
log::error!(target: LOG_TARGET, "CodeRejected during reinstrument: {}", msg);
err
})
.map(|(code, _)| code)