Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement seal_debug_message #792

Merged
merged 31 commits into from
Jun 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2e6ba6c
Implement `seal_debug_message`
ascjones May 14, 2021
fa0fd9e
Update docs
ascjones May 14, 2021
8e896b3
Fmt
ascjones May 14, 2021
8738b80
Fix debug_print macro
ascjones May 19, 2021
13e485e
review: use newline char
ascjones May 19, 2021
2301179
Fix example
ascjones May 19, 2021
5e091c1
Revert to newline string
ascjones May 20, 2021
2279a6f
Fmt
ascjones May 20, 2021
636afc3
Merge branch 'master' into aj-debug-message
ascjones May 20, 2021
9b7b687
Single call to debug_print for debug_println!
ascjones May 20, 2021
c2b656c
Add missing ReturnCode, still need to handle it
ascjones May 20, 2021
4fa9f1e
Inline debug_println!
ascjones May 20, 2021
be0c00d
If logging is disabled then subsequent calls will be a no-op
ascjones May 20, 2021
62f6b10
Fmt
ascjones May 20, 2021
43aba01
Fix missing error match in experimental off-chain
ascjones May 20, 2021
b978d76
Add safety comment to debug_message
ascjones May 20, 2021
35fcf72
Only re-export ink_prelude::format, and explain
ascjones May 20, 2021
d96dea0
Satisfy clippy
ascjones May 20, 2021
efa66bb
Encapsulate DEBUG_ENABLED global in module
ascjones May 21, 2021
3c1b5a1
Move seal_denug_message to unstable module
ascjones May 21, 2021
682ec0f
Update unstable and safety comments
ascjones May 21, 2021
db05bd9
Add more comments about the required features to be enabled on the no…
ascjones May 24, 2021
c641950
Add `ink-debug` feature, make debug messages a noop if not enabled
ascjones May 24, 2021
89c3536
Fmt
ascjones May 24, 2021
1fa7246
Noop macro formatting
ascjones May 24, 2021
dba097b
Enable debug printing for std
ascjones May 24, 2021
0de9b94
Comment formatting
ascjones May 24, 2021
5762406
Encapsulate static variable inside the function
ascjones May 25, 2021
47ef2f1
Merge branch 'master' into aj-debug-message
ascjones May 27, 2021
0524daa
Fmt
ascjones May 27, 2021
61d0280
Remove debug_assert!(true) for disabled macros
ascjones May 27, 2021
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
52 changes: 31 additions & 21 deletions crates/env/src/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use crate::ReturnFlags;
use core::marker::PhantomData;
use ink_primitives::Key;

pub use self::debug::debug_message;

macro_rules! define_error_codes {
(
$(
Expand Down Expand Up @@ -607,28 +609,36 @@ pub fn random(subject: &[u8], output: &mut &mut [u8]) {
extract_from_slice(output, output_len as usize);
}

/// If debug message recording is disabled in the contracts pallet, this will be set to false
/// after an initial call in order to prevent the cost of further calls which will have no effect.
static mut DEBUG_ENABLED: bool = true;
mod debug {
use super::*;

/// Call `seal_debug_message` with the supplied UTF-8 encoded message.
///
/// If debug message recording is disabled in the contracts pallet, the first call to will return
/// a LoggingDisabled error, and further calls will be a no-op to avoid the cost of calling into
/// the supervisor.
///
/// # Safety
///
/// Accesses to the static `DEBUG_ENABLED` are safe because we are executing in a single-threaded
/// environment.
pub fn debug_message(message: &str) {
if unsafe { DEBUG_ENABLED } {
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() {
unsafe { DEBUG_ENABLED = false }
/// If debug message recording is disabled in the contracts pallet, this will be set to false
/// after an initial call in order to prevent the cost of further calls which will have no effect.
static mut DEBUG_ENABLED: bool = true;

/// Call `seal_debug_message` with the supplied UTF-8 encoded message.
///
/// If debug message recording is disabled in the contracts pallet, the first call to will return
/// a LoggingDisabled error, and further calls will be a no-op to avoid the cost of calling into
/// the supervisor.
///
/// # Note
///
/// This depends on the currently dsiabled
ascjones marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Safety
///
/// Accesses to the static `DEBUG_ENABLED` are safe because we are executing in a single-threaded
/// environment.
ascjones marked this conversation as resolved.
Show resolved Hide resolved
pub fn debug_message(message: &str) {
if unsafe { DEBUG_ENABLED } {
ascjones marked this conversation as resolved.
Show resolved Hide resolved
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() {
unsafe { DEBUG_ENABLED = false }
}
}
}
}
Expand Down