From 02375f1e9c74e25d57b01c03a6df03ac6d1ada24 Mon Sep 17 00:00:00 2001 From: martoon Date: Sat, 16 Sep 2023 00:41:16 +0300 Subject: [PATCH 1/4] MIR: Add commands to test rollup with debugger Using debugger is a significantly simpler way of testing than actually deploying the rollup, and it also may require much less tooling installed. This commit adds the Makefile targets to quickly debug the kernel. --- contrib/mir/.gitignore | 1 + contrib/mir/Makefile | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/contrib/mir/.gitignore b/contrib/mir/.gitignore index b6a4c5a8eab4..8481b3404b0c 100644 --- a/contrib/mir/.gitignore +++ b/contrib/mir/.gitignore @@ -1,3 +1,4 @@ src/syntax.rs bin/ .tezos-smart-rollup-node/ +debugger-inputs.json diff --git a/contrib/mir/Makefile b/contrib/mir/Makefile index 863598393023..13c55063655c 100644 --- a/contrib/mir/Makefile +++ b/contrib/mir/Makefile @@ -3,7 +3,7 @@ # # SPDX-License-Identifier: MIT -.PHONY: build fill-kernel-chunks prepare-smart-rollup-config originate_rollup clean-rollup-dir clean-build clean +.PHONY: build fill-kernel-chunks prepare-smart-rollup-config originate_rollup debug-kernel-internal debug-kernel-simple debug-kernel-full clean-rollup-dir clean-build clean # Folders BIN_DIR ?= bin @@ -93,4 +93,29 @@ clean-build: rm -rf $(BIN_DIR) rm -rf ./target +# This is a template for inputs file put to debugger. +# Created automatically on call to debugger, you can next update this file +# as needed. +debugger-inputs.json: + echo '[[{"external": "07"}]]' > debugger-inputs.json + # the format is explained here + # https://tezos.gitlab.io/alpha/smart_rollups.html#testing-your-kernel + +debug-kernel-internal: $(BIN_DIR)/$(KERNEL_NAME).wasm debugger-inputs.json + # not always we've generated some kernel pages, so create the folder + # if it is absent, for uniformity + mkdir -p $(BIN_DIR)/wasm_2_0_0 + octez-smart-rollup-wasm-debugger \ + --kernel $(BIN_DIR)/$(KERNEL_NAME).wasm \ + --inputs debugger-inputs.json \ + --preimage-dir $(BIN_DIR)/wasm_2_0_0 + +# This tests the original kernel before any processing. +# Requires less tooling to run, and provides almost the same coverage. +debug-kernel-simple: + $(MAKE) debug-kernel-internal KERNEL_NAME=mir-raw-kernel + +debug-kernel-full: + $(MAKE) debug-kernel-internal KERNEL_NAME=mir-installer-kernel + clean: clean-build clean-rollup-dir -- GitLab From 0a697e9ff1edda5b46cce184e50fd248463576c1 Mon Sep 17 00:00:00 2001 From: martoon Date: Sat, 16 Sep 2023 00:43:21 +0300 Subject: [PATCH 2/4] MIR: Add root-level docs about testing Describe the two ways to test our rollup, elaborate on debugging. --- contrib/mir/README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/contrib/mir/README.md b/contrib/mir/README.md index a21715130d70..c88922285a6e 100644 --- a/contrib/mir/README.md +++ b/contrib/mir/README.md @@ -33,3 +33,44 @@ You can run the included tests by the following command. Some tests print gas consumption information (in addition to testing it), but `cargo test` omits output from successful tests by default. To see it, run `cargo test -- --show-output` + +## Testing rollup manually + +There are two basic ways to poke the rollup. + +### Testing with debugger + +The simpler way to test the rollup is using the debugger. + +See [the official page](https://tezos.gitlab.io/shell/smart_rollup_node.html#testing-your-kernel) for instructions. + +In our case you need: +* Prerequisite: obtain `octez-smart-rollup-wasm-debugger`. + + It can be built from OCaml sources, or you can get a ready static binary from the Releases page of [tezos-packaging](https://github.com/serokell/tezos-packaging) repository. + +* Run `make debugger-inputs.json` and fill your message content into that file. +* Run `make debug-kernel-simple`. +* Interact with the debugger as mentioned in the docs. Observe the printed debug + messages, check the necessary durable storage keys. Usually you just type + + ```sh + step inbox + ``` + + to make the kernel consume the input messages, and then to check out the + result written to the durable storage: + + ```sh + show key /storage + ``` + +The mentioned command tests the very raw kernel as produced by Rust. + +For real deployment some preprocessing is necessary. If you want to account for +it, use `make debug-kernel-full`. This would require some of the tools mentioned +in the [deployment](./docs/testing-with-deployment.md) document. + +### Testing with deployment + +See the [respective document](./docs/testing-with-deployment.md) on this. -- GitLab From c067479494b293eb52637320e938f0dceaa78599 Mon Sep 17 00:00:00 2001 From: martoon Date: Mon, 9 Oct 2023 19:44:05 +0400 Subject: [PATCH 3/4] MIR: Add line feed to debug messages Problem: turned out (and probably that was expected, but still), that `debug_msg!` writes exactly the given text, and multiple calls result in all the messages being printed in one line. Solution: add trailing newline. I'll add a higher level API to this later. --- contrib/mir/src/rollup/demo.rs | 2 +- contrib/mir/src/rollup/kernel.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/mir/src/rollup/demo.rs b/contrib/mir/src/rollup/demo.rs index aced606eda1f..195b0258356a 100644 --- a/contrib/mir/src/rollup/demo.rs +++ b/contrib/mir/src/rollup/demo.rs @@ -58,7 +58,7 @@ pub fn call_fibonacci(host: &mut impl Runtime, param: usize) -> Result<(), Error host.store_write_all(STORAGE_PATH, &new_storage.to_le_bytes()) .map_err(|err| err.to_string())?; - debug_msg!(host, "Computation successful, storage updated"); + debug_msg!(host, "Computation successful, storage updated\n"); Ok(()) } diff --git a/contrib/mir/src/rollup/kernel.rs b/contrib/mir/src/rollup/kernel.rs index 3e42ddefa4cd..ff4a11b488bd 100644 --- a/contrib/mir/src/rollup/kernel.rs +++ b/contrib/mir/src/rollup/kernel.rs @@ -27,7 +27,7 @@ pub type Error = String; /// execution time of one such call. pub fn kernel_entry(host: &mut impl Runtime) { // Ways of observing that kernel has indeed been invoked, helps in testing - debug_msg!(host, "Kernel invoked"); + debug_msg!(host, "Kernel invoked\n"); let _ = host.store_write(&RefPath::assert_from(b"/started"), &[1], 0); let mut first_message_for_invocation = true; @@ -36,14 +36,14 @@ pub fn kernel_entry(host: &mut impl Runtime) { match host.read_input() { Ok(Some(msg)) => { if first_message_for_invocation { - debug_msg!(host, "Handling messages at level {}", msg.level); + debug_msg!(host, "Handling messages at level {}\n", msg.level); first_message_for_invocation = false; } // TODO [#6411]: wrap into catch_unwind let res = process_message(host, &msg); res.unwrap_or_else(|err| { - debug_msg!(host, "Processing message #{} failed: {}", msg.id, err) + debug_msg!(host, "Processing message #{} failed: {}\n", msg.id, err) }) } // The kernel gallery and some experienced devs advise to keep @@ -63,7 +63,7 @@ pub fn process_message(host: &mut impl Runtime, msg: &Message) -> Result<(), Err debug_assert!(rest.is_empty()); match msg { InboxMessage::External(payload) => { - debug_msg!(host, "Message #{msg_id} - external: {payload:#x?}"); + debug_msg!(host, "Message #{msg_id} - external: {payload:#x?}\n"); process_external_message(host, &payload)? } // [optimization] If payload is bytes, it should not be hard @@ -75,7 +75,7 @@ pub fn process_message(host: &mut impl Runtime, msg: &Message) -> Result<(), Err InternalInboxMessage::Transfer(transfer) => { debug_msg!( host, - "Message #{msg_id} - internal transfer to {} with payload: {:#x?}", + "Message #{msg_id} - internal transfer to {} with payload: {:#x?}\n", transfer.destination, &transfer.payload.0 ); -- GitLab From a3fa819af16784dd4ce8d449450af62b5c0730ae Mon Sep 17 00:00:00 2001 From: martoon Date: Thu, 12 Oct 2023 19:40:56 +0400 Subject: [PATCH 4/4] MIR: Drop the check on smart-rollup-installer Problem: that check was in fact static and triggered disregard the used target. Solution: remove it, it's not so important. Slightly clarify the docs on installing that executable to make that better grep-able. --- contrib/mir/Makefile | 6 ------ contrib/mir/docs/testing-with-deployment.md | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/contrib/mir/Makefile b/contrib/mir/Makefile index 13c55063655c..25f958ab6e06 100644 --- a/contrib/mir/Makefile +++ b/contrib/mir/Makefile @@ -35,12 +35,6 @@ $(BIN_DIR)/mir-kernel.wasm: $(BIN_DIR)/mir-raw-kernel.wasm # an installer kernel that would load those chunks on run. # The chunks have to be exposed via our local rollup node. $(BIN_DIR)/mir-installer-kernel.wasm: $(BIN_DIR)/mir-kernel.wasm - ifeq ($(SMART_ROLLUP_INSTALLER),smart-rollup-installer) - ifeq (, $(shell which smart-rollup-installer)) - $(error "No smart-rollup-installer in $$PATH, you can install it with `cargo install`. \ - Make sure cargo binaries folder is in your path") - endif - endif $(SMART_ROLLUP_INSTALLER) get-reveal-installer \ --upgrade-to $(BIN_DIR)/mir-kernel.wasm \ --output $(BIN_DIR)/mir-installer-kernel.wasm \ diff --git a/contrib/mir/docs/testing-with-deployment.md b/contrib/mir/docs/testing-with-deployment.md index 8a72a2ec76ba..e41b6c47cb6d 100644 --- a/contrib/mir/docs/testing-with-deployment.md +++ b/contrib/mir/docs/testing-with-deployment.md @@ -18,7 +18,7 @@ You will need the following programs installed: * `octez-client`; * `octez-smart-rollup-client`; * `octez-smart-rollup-node`. -* `tezos-smart-rollup-installer`: use `cargo install tezos-smart-rollup-installer`. +* `smart-rollup-installer`: use `cargo install tezos-smart-rollup-installer`. Make sure that your data directory of `octez-client` (`~/.octez-client` by default) mentions the testing network you are planning to operate with. -- GitLab