Skip to main content

Part 1: Running the kernel in debug mode

To set up the application for the tutorial, you must configure Rust to build the kernel. Then you can run the kernel in debug mode to see how it works.

Before you begin, make sure that you have installed the prerequisites in Deploy a Smart Rollup.

Downloading and building the kernel

Follow these steps to get the kernel code and build it:

  1. Clone the repository with the kernel code and go into its directory:

    git clone https://gitlab.com/trili/hello-world-kernel.git
    cd hello-world-kernel/
  2. Configure Rust to build WebAssembly applications:

    1. Verify that you have Rust version 1.73.0 or later installed by running rustc --version.

    2. If you have a version of Rust later than 1.73.0, use the rustup override command to use version 1.73.0:

      rustup override set 1.73.0
    3. Add WASM as a compilation target for Rust by running this command:

      rustup target add wasm32-unknown-unknown
  3. Build the kernel by running this command:

    cargo build --target wasm32-unknown-unknown

    If the kernel builds correctly, the terminal shows a message that looks like "Finished dev [unoptimized + debuginfo] target(s) in 15s." The compiled kernel files are in the target/wasm32-unknown-unknown/debug folder. In particular, the compiled kernel itself is in the hello_world_kernel.wasm file.

Now the kernel is compiled into a single file that nodes can run.

Debugging the kernel

Octez provides an executable named octez-smart-rollup-wasm-debugger that runs Smart Rollups in debug mode to make it easier to test and observe them. Later, you will deploy the rollup to the sandbox, but running it in debug mode first verifies that it built correctly.

This executable is not provided in Octez releases or Docker containers, so you must set up the Octez source code and run it from there.

  1. Install the opam package manager as described in its documentation: https://opam.ocaml.org/doc/Install.html.

  2. Install the Dune build system:

    opam install dune
  3. In a directory outside the hello-world-kernel directory, clone the Octez repository by running this command:

    git clone https://gitlab.com/tezos/tezos.git
  4. Go into the tezos directory:

    cd tezos
  5. Run these commands to install the necessary dependencies:

    opam init --bare
    eval $(opam env)
  6. From the tezos directory, run this command to start the Smart Rollup in debug mode and pass an empty message inbox to it, changing <REPO_PATH> to the path to the hello-world-kernel directory:

    dune exec src/bin_wasm_debugger/main_wasm_debugger.exe -- \
    --kernel <REPO_PATH>/target/wasm32-unknown-unknown/debug/hello_world_kernel.wasm \
    --inputs <REPO_PATH>/empty_input.json

    The command prompt changes to show that you are in debugging mode, which steps through commands. If you see an error, make sure that the kernel built properly and that the paths in the command are correct.

  7. At the debugging prompt, run this command to send the message inbox to the kernel:

    step inbox

    The response shows the logging information for the kernel, including these parts:

    • The message "Hello, kernel" from the hello_kernel function
    • The message "Got message: Internal(StartOfLevel)," which represents the start of the message inbox
    • The message "Got message: Internal(InfoPerLevel(InfoPerLevel ...," which provides the hash and timestamp of the previous block
    • The message "Got message: Internal(EndOfLevel)," which represents the end of the message inbox
  8. Press Ctrl + C to end debugging mode.

Now you know that the kernel works. In the next section, you optimize the kernel to be small enough to be deployed. Continue to Part 2: Optimizing the kernel.