Unverified Commit 27b8d778 authored by Alexander Theißen's avatar Alexander Theißen Committed by GitHub
Browse files

Flip the `DEBUG_ENABLED` conditional (#878)

* Force the `DEBUG_ENABLED = enabled` code to be executed when RPC is used

* Fix clippy

* Flip the conditional
parent a2e549ea
Pipeline #150121 passed with stages
in 34 minutes and 47 seconds
......@@ -661,18 +661,26 @@ pub fn random(subject: &[u8], output: &mut &mut [u8]) {
/// This depends on the `seal_debug_message` interface which requires the
/// `"pallet-contracts/unstable-interface"` feature to be enabled in the target runtime.
pub fn debug_message(message: &str) {
static mut DEBUG_ENABLED: bool = true;
static mut DEBUG_ENABLED: bool = false;
static mut FIRST_RUN: bool = true;
// SAFETY: safe because executing in a single threaded context
if unsafe { DEBUG_ENABLED } {
// We need those two variables in order to make sure that the assignment is performed
// in the "logging enabled" case. This is because during RPC execution logging might
// be enabled while it is disabled during the actual execution as part of a transaction.
// The gas estimation takes place during RPC execution. We want to overestimate instead
// of underestimate gas usage. Otherwise using this estimate could lead to a out of gas error.
if unsafe { DEBUG_ENABLED || FIRST_RUN } {
let bytes = message.as_bytes();
let ret_code = unsafe {
sys::seal_debug_message(Ptr32::from_slice(bytes), bytes.len() as u32)
};
if let Err(Error::LoggingDisabled) = ret_code.into() {
if !matches!(ret_code.into(), Err(Error::LoggingDisabled)) {
// SAFETY: safe because executing in a single threaded context
unsafe { DEBUG_ENABLED = false }
unsafe { DEBUG_ENABLED = true }
}
// SAFETY: safe because executing in a single threaded context
unsafe { FIRST_RUN = false }
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment