Skip to content

Commit

Permalink
Deploying the kernel and running the node
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymcmackin committed Oct 6, 2023
1 parent 6a0657e commit 5347231
Showing 1 changed file with 64 additions and 148 deletions.
212 changes: 64 additions & 148 deletions src/pages/tutorials/smart-rollups/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,186 +450,97 @@ In particular, the size of the kernel needs to be smaller than the manager opera
Now the kernel is small enough to be deployed on layer 1.
In fact, when it is deployed, it will be even smaller than the result of this command because the command is checking the hexadecimal representation and the deployed kernel will be in binary.

## Part 5: Deploying (originating) the kernel

Smart rollup kernels are originated to Tezos in a way similar to smart contracts.
Instead of running the `octez-client originate contract`, you run the `octez-client originate smart rollup` command.

1. In the second terminal window, in the Docker container, in the `hello-world-kernel` folder, run this command to deploy the installer kernel to the Tezos sandbox:

```bash
octez-client originate smart rollup "test_smart_rollup" from "bootstrap1" of kind wasm_2_0_0 of type bytes with kernel file:hello_world_kernel_installer.hex --burn-cap 3
```

Like the command to originate a smart contract, this command uses the `--burn-cap` argument to allow the transaction to take fees from the account.
Also like deploying a smart contract, the response in the terminal shows information about the transaction and the address of the originated smart rollup, which starts with `sr1`.

### 4.3. The Installer Kernel

Instead of using a kernel file for origination in the aforementioned format, an alternative approach is to utilize the **installer** version of the kernel. This **installer kernel** can be **upgraded** to the original version if provided with additional information in the form of **preimages**, which can be provided to the rollup node later on as part of its **reveal data channel**.

There are two ways to communicate with smart rollups:

1. **global inbox** -- allows Layer 1 to transmit information to all rollups. This unique inbox contains two kinds of messages: **external messages** are pushed through a Layer 1 manager operation, while **internal messages** are pushed by Layer 1 smart contracts or the protocol itself (e.g. `StartOfLevel`, `InfoPerLevel`, `EndOfLevel`).
2. **reveal data channel** -- allows the rollup to retrieve data (e.g. **preimages**) coming from data sources external to Layer 1.

The main benefit of the installer kernel is that it is small enough to be used in origination regardless of the kernel that it will be upgraded to.

There is an [installer kernel origination topic](https://tezos.stackexchange.com/questions/4784/how-to-originating-a-smart-rollup-with-an-installer-kernel/5794#5794) for this; please consult it for further clarifications. To generate the **installer kernel**, the `smart-rollup-installer` tool is required:

`outside docker session - hello-world-kernel`

```bash!
cargo install tezos-smart-rollup-installer
```

To create the installer kernel from the initial kernel:

`outside docker session - hello-world-kernel`

```bash!
smart-rollup-installer get-reveal-installer --upgrade-to target/wasm32-unknown-unknown/debug/hello_world_kernel.wasm --output hello_world_kernel_installer.hex --preimages-dir preimages/
```

This command creates the following:

- `hello_world_kernel_installer.hex` -- the hexadecimal representation of the installer kernel to be used in the origination.
- `preimages/` -- a directory containing the preimages necessary for upgrading from the installer kernel to the original kernel. These preimages are transmitted to the rollup node that runs the installer kernel with the help of the [**reveal data channel**](https://tezos.gitlab.io/alpha/smart_rollups.html#reveal-data-channel).

Notice the reduced dimensions of the installer kernel:

`outside docker session - hello-world-kernel`

```bash!
du -h hello_world_kernel_installer.hex
# 36.0K hello_world_kernel_installer.hex
```

Because of the size of this installer kernel, you are now ready for deployment.

Note that this shows the size of the `hex` encoded file, which is larger than the actual binary size of the kernel that we originate.

## 5. Deploying the Kernel

### 5.1. Sandboxed Mode

Our goal now is to create a testing environment for originating our rollup with the created kernel. In the `hello-world-kernel` repository, we offer the `sandbox-node.sh` file, which does the following:

- configures the `Octez` node to operate in [**sandbox mode**](https://tezos.gitlab.io/user/sandbox.html).
- activates the `alpha` protocol by using an `activator` account.
- creates five test (bootstrapping) accounts used for manual [**baking**](https://opentezos.com/baking/cli-baker/).
- creates a loop of continuous baking.

Run the file with:

`docker session 1`

```bash!
./sandbox_node.sh
```

Ignore the "Unable to connect to the node" error, as it only comes once because the `octez-client` command was used while the node was not yet bootstrapped. The result should be a permanent loop containing:

`docker session 1`

```bash!
# Injected block at minimal timestamp
```

Leave that process running. Open a new `Docker` session, which works in the same container named `octez-container`:

`outside docker session - hello-world-kernel`

```bash!
docker exec -it octez-container /bin/sh
```

It is very important to remember to open a new terminal session and run the command above whenever we mention a "new `Docker` session" or when you see that the `docker session` counter has increased.

To check that the network has the correctly configured protocol:

`docker session 2`

```bash!
octez-client rpc get /chains/main/blocks/head/metadata | grep protocol
# "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK",
# "next_protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
```

You are now ready for the Smart Rollup origination process.

### 5.2. Smart Rollup Origination
If you need to open a new terminal window within the Docker container, run the command `docker exec -it octez-container /bin/sh`.

To originate a smart rollup using the `hello_world_kernel_installer` created above:
## Part 6: Running the smart rollup node

`docker session 2`
Now that the smart rollup kernel is set up on level 1, anyone can run a smart rollup node based on that kernel.
Smart rollup nodes are similar to baking nodes, but they run the smart rollup code instead of baking Tezos blocks.
In these steps, you start a smart rollup node, but note that anyone can run a node based on your kernel, including people who want to verify the rollup's behavior.
```bash!
octez-client originate smart rollup "test_smart_rollup" from "bootstrap1" of kind wasm_2_0_0 of type bytes with kernel file:hello-world-kernel/hello_world_kernel_installer.hex --burn-cap 3
```
1. Copy the contents of the preimages folder to a folder that the rollup node can access by running these commands:
```bash!
# > Node is bootstrapped.
# ...
# Smart rollup sr1B8HjmEaQ1sawZtnPU3YNEkYZavkv54M4z memorized as "test_smart_rollup"
```
```bash
mkdir -p ~/.tezos-rollup-node/wasm_2_0_0
In the command above, the `--burn-cap` option specifies the amount of ꜩ you are willing to "burn" (lose) to allocate storage in the global context of the blockchain for each rollup.
cp preimages/* ~/.tezos-rollup-node/wasm_2_0_0/
```
To run a rollup node for the rollup using the installer kernel, you need to copy the contents of the preimages directory to `${ROLLUP_NODE_DIR}/wasm_2_0_0/`. You can set `$ROLLUP_NODE_DIR` to `~/.tezos-rollup-node`, for instance:
1. In the second terminal window, in the Docker container, start the rollup node:
`docker session 2`
```bash
octez-smart-rollup-node-alpha run operator for "test_smart_rollup" with operators "bootstrap2" --data-dir ~/.tezos-rollup-node/ --log-kernel-debug --log-kernel-debug-file hello_kernel.debug
```
```bash!
mkdir -p ~/.tezos-rollup-node/wasm_2_0_0
Now the node is running and writing to the log file `hello_kernel.debug`.
Leave this command running in the terminal window just like you left the first terminal window running the Tezos sandbox.
cp hello-world-kernel/preimages/* ~/.tezos-rollup-node/wasm_2_0_0/
```
1. Open a third terminal window and enter the Docker container again:
You should now be able to **run** your rollup node:
```bash
docker exec -it octez-container /bin/sh
```
`docker session 2`
1. In the container, go to the `hello_world_kernel` folder.
```bash!
octez-smart-rollup-node-alpha run operator for "test_smart_rollup" with operators "bootstrap2" --data-dir ~/.tezos-rollup-node/ --log-kernel-debug --log-kernel-debug-file hello_kernel.debug
```
1. Print the contents of the log file:
Leave this running as well, and open another `Docker` session, as already explained, with the `octez-container`.

Each time a block is baked, a new "Hello, kernel!" message should appear in the `hello_kernel.debug` file:
```bash
tail -f hello_kernel.debug
```
`docker session 3`
Now, each time a block is baked, the smart rollup node prints the contents of the messages in the smart rollup inbox, as in this example:
```bash!
tail -f hello_kernel.debug
# Hello, kernel!
# Got message: Internal(StartOfLevel)
# Got message: Internal(InfoPerLevel(InfoPerLevel { predecessor_timestamp: 2023-06-07T15:31:09Z, predecessor: BlockHash("BLQucC2rFyNhoeW4tuh1zS1g6H6ukzs2DQDUYArWNALGr6g2Jdq") }))
# Got message: Internal(EndOfLevel)
# ... (repeats)
```
```
# Hello, kernel!
# Got message: Internal(StartOfLevel)
# Got message: Internal(InfoPerLevel(InfoPerLevel { predecessor_timestamp: 2023-06-07T15:31:09Z, predecessor: BlockHash("BLQucC2rFyNhoeW4tuh1zS1g6H6ukzs2DQDUYArWNALGr6g2Jdq") }))
# Got message: Internal(EndOfLevel)
```
Finally, you have successfully deployed a very basic yet functional smart rollup.
1. Stop the command by pressing Ctrl + C.
### 5.3. Sending an Inbox Message to the Smart Rollup
1. Run this command to watch for external messages to the rollup:
We now want to send an external message into the rollup inbox, which should be read by our kernel and sent as a debug message. First, we will wait for it to appear using:
```bash
tail -f hello_kernel.debug | grep External
```
`docker session 3`
No output appears at first because the rollup has not received any messages aside from the internal messages that indicate the beginning and end of the inbox.
```bash!
tail -f hello_kernel.debug | grep External
```
Leave this command running.
Open yet another `Docker` session and send an external message into the rollup inbox. You can use the `Octez` client:
1. Open a fourth terminal window, enter the Docker container with the command `docker exec -it octez-container /bin/sh`, and go to the `hello_world_kernel` folder.
`docker session 4`
1. In this fourth terminal window, run this command to simulate adding a message to the smart rollup inbox:
```bash!
octez-client send smart rollup message '[ "test" ]' from "bootstrap3"
```
```bash
octez-client send smart rollup message '[ "test" ]' from "bootstrap3"
```
Once you send the Smart Rollup message, you will notice that in the debug trace, you get:
1. Go back to the third terminal window.
`docker session 3`
This window shows the message that you sent in the fourth window, which it received in binary format, with the numbers representing the letters in "test."
```bash!
Got message: External([116, 101, 115, 116])
```
```
Got message: External([116, 101, 115, 116])
```
`116, 101, 115, 116` represent the bytes of "test".
Now you can send messages to this rollup via Tezos level 1.
### 5.4. Test Networks
Expand Down Expand Up @@ -659,3 +570,8 @@ The workflow should be similar to the one presented for the sandbox mode:
7. [Tezos Testnets](https://teztnets.xyz/)
8. [Origination of the Installer Kernel](https://tezos.stackexchange.com/questions/4784/how-to-originating-a-smart-rollup-with-an-installer-kernel/5794#5794)
9. [Docker Documentation](https://docs.docker.com/get-started/)
## Next steps
Feel free to explore additional examples from the dedicated [kernel gallery](https://gitlab.com/tezos/kernel-gallery/-/tree/main/) or create your own!

0 comments on commit 5347231

Please sign in to comment.