From 998d190ea06a8d539a8c4a8527905cf8758abe4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= <alex.theissen@me.com> Date: Sun, 21 Mar 2021 14:49:44 +0100 Subject: [PATCH] Use the log crate to output contract generated messages. (#8403) --- substrate/frame/contracts/README.md | 15 +++++++++++++++ substrate/frame/contracts/src/wasm/runtime.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/substrate/frame/contracts/README.md b/substrate/frame/contracts/README.md index 1cb384e14c5..6c987165990 100644 --- a/substrate/frame/contracts/README.md +++ b/substrate/frame/contracts/README.md @@ -57,4 +57,19 @@ will make things a lot easier. One such language is [`ink`](https://github.com/p which is an [`eDSL`](https://wiki.haskell.org/Embedded_domain_specific_language) that enables writing WebAssembly based smart contracts in the Rust programming language. +## Debugging + +Contracts can emit messages to the node console when run on a development chain through the +`seal_println` API. This is exposed in ink! via +[`ink_env::debug_println()`](https://docs.rs/ink_env/latest/ink_env/fn.debug_println.html). + +In order to see these messages the log level for the `runtime::contracts` target needs to be raised +to at least the `info` level which is the default. However, those messages are easy to overlook +because of the noise generated by block production. A good starting point for contract debugging +could be: + +```bash +cargo run --release -- --dev --tmp -lerror,runtime::contracts +``` + License: Apache-2.0 diff --git a/substrate/frame/contracts/src/wasm/runtime.rs b/substrate/frame/contracts/src/wasm/runtime.rs index 2ceac1c5160..8e3c2244f1e 100644 --- a/substrate/frame/contracts/src/wasm/runtime.rs +++ b/substrate/frame/contracts/src/wasm/runtime.rs @@ -1366,7 +1366,7 @@ define_env!(Env, <E: Ext>, seal_println(ctx, str_ptr: u32, str_len: u32) => { let data = ctx.read_sandbox_memory(str_ptr, str_len)?; if let Ok(utf8) = core::str::from_utf8(&data) { - sp_runtime::print(utf8); + log::info!(target: "runtime::contracts", "seal_println: {}", utf8); } Ok(()) }, -- GitLab