Part 2: Optimizing the kernel
To originate the kernel on Tezos, it must fit within the maximum size for a layer 1 operation (32KB). In these steps, you reduce the size of the kernel:
-
From the
hello-world-kerneldirectory, run this command to print the current size of the kernel:du -h target/wasm32-unknown-unknown/debug/hello_world_kernel.wasmBecause you ran it in debug mode, the size of the compiled kernel and its dependencies may be 18MB or more, which is too large to originate.
-
Run this command to create a release build of the kernel:
cargo build --release --target wasm32-unknown-unknownThis command creates a release build of the kernel in the
target/wasm32-unknown-unknown/release/directory. -
Check the size of the release build of the kernel:
du -h target/wasm32-unknown-unknown/release/hello_world_kernel.wasmThe release build is significantly smaller, but still too large.
-
Run the
wasm-stripcommand to reduce the size of the kernel:wasm-strip target/wasm32-unknown-unknown/release/hello_world_kernel.wasmThis command removes WebAssembly code that is not necessary to run Smart Rollups.
-
Run the
ducommand again to see the new size of the kernel:du -h target/wasm32-unknown-unknown/release/hello_world_kernel.wasmThe size of the kernel is smaller now.
To get the kernel running with an even smaller size, you can use the installer kernel, which includes only enough information to install your original kernel. To do this, your kernel is split up and stored in separate files called preimages. When the installer kernel runs, it requests these files and reconstructs the original kernel.
-
Run this command to install the installer kernel tool:
cargo install tezos-smart-rollup-installer -
Run this command to create an installer kernel:
smart-rollup-installer get-reveal-installer \
--upgrade-to target/wasm32-unknown-unknown/release/hello_world_kernel.wasm \
--output hello_world_kernel_installer.wasm --preimages-dir preimages/This command creates the following files:
hello_world_kernel_installer.wasm: The installer kernelpreimages/: A directory that contains the preimages that allow nodes to restore the original kernel code
When a node runs the installer kernel, it retrieves the preimages through the reveal data channel, a channel that Smart Rollups use to request data from outside of layer 1. For more information about the reveal data channel, see Reveal data channel.
-
Verify the size of the installer kernel by running this command:
du -h hello_world_kernel_installer.wasmNow the kernel is small enough to originate on layer 1.
-
As you did in the previous section, from the root of the Octez repository, run the installer kernel in debug mode by running this command, changing
<REPO_PATH>to the path to thehello-world-kerneldirectory:dune exec src/bin_wasm_debugger/main_wasm_debugger.exe -- \
--kernel <REPO_PATH>/hello_world_kernel_installer.wasm \
--preimage-dir <REPO_PATH>/preimages \
--inputs <REPO_PATH>/empty_input.jsonNote that this command uses the installer kernel and provides the location of the preimages in the
--preimage-dirargument.Then you can use the
step inboxcommand to simulate receiving the inbox from layer 1, as you did in the previous section. You can see the hello world kernel messages in the log, which shows that the upgrade from the installer kernel to the full kernel was successful. -
Press Ctrl + C to end the debugging session.
-
From the
hello-world-kerneldirectory, create a hexadecimal version of the installer kernel by running this command outside of the Docker container:smart-rollup-installer get-reveal-installer \
--upgrade-to target/wasm32-unknown-unknown/release/hello_world_kernel.wasm \
--output hello_world_kernel_installer.hex --preimages-dir preimages/
In the next section, set up a sandbox environment to deploy this kernel. Continue to Part 3: Deploying (originating) to a sandbox.