# DAL tutorial cheatsheet
## Prerequisite
### Network
DAL is currently active on:
- Dailynet ([doc](https://teztnets.xyz/dailynet-about)): reset everyday
- Weeklynet ([doc](https://teztnets.xyz/weeklynet-about)): reset every wednesday
### Account
Provide an account with money. On the documentation page for each network above, there is a faucet you can use. For example, the one of this week for weeklynet is [here](https://faucet.weeklynet-2023-12-06.teztnets.xyz/).
To be able to commit on a rollup, at least 10k tez are needed. So requiring 20ktez should be more than enough to run a rollup with DAL for a week.
### Choose the kernel
:::info
Feel free to address suggestions for modifying the current echo kernel into something better for the tutorial.
:::
At the moment, kernels for smart-rollups are written with a Rust SDK. Hence you must have installed the rust toolchain locally. We have a paragraph in the [documentation](https://tezos.gitlab.io/introduction/howtoget.html?highlight=rust#install-rust) that explains how.
To compile the DAL echo kernel into WASM, you need to compile the SDK and the kernel code.
From your local clone of `tezos/tezos`, you can run the following commands:
- `make build-kernels-dev-deps`: This allows to fetch the dependencies used to compile the Rust kernel SDK
- `make -f kernels.mk dal_echo_kernel.wasm`: This allows to compile the echo kernel
- `make -f kernels.mk kernel_sdk`: As a side-effects, this enables to compile the `smart-rollup installer`. This binary is a bootstrap process that allows to load the kernel code onto the rollup node and boot from it (this is a similar process as the floppy disks that Windows was using a long time ago).
:::warning
The smart-rollup installer reuses the DAC logic. However, we plan in the future to provide a similar UX using the DAL logic instead to provide a full end-to-end decentralised toolchain. Because by using DAC, the code of the kernel is never pushed onto the L1.
:::
### Running an `octez-node`
Nothing too complicated. You can follow the instruction from the network page of dailynet/weeklynet as provided above.
:::info
If there are public nodes on weeklynet, we could also try to use public nodes instead, everything should work as expected.
:::
Mind to:
- Set your git repository on the same commit as the one provided by the network page. For weeklynet of this week it is: `36959547`
- open your RPC server via the option `--rpc-addr`
Optionnaly:
- If you run multiple `octez-node` on the same machine, you may have to change the port used by the p2p protocol of the octez-node. This can be done via `--net-addr` option. Feel free to read the documentation for more details
- If you want to use a specific directory instead of the default one, use the `--data-dir` option. By doing so, do note you will have to use this option for all the other commands involving the `octez-node`.
### Running an `octez-dal-node`
To run an octez-dal-node, you need to specify a profile. The profile allows to set the topics of the P2P that will "select" the messages we are interested in. For example a slot producer for slot index 0 only wants to see messages related to the slot index 0 and not 1. Similarly an attester only wants the topics he is interested in.
Read the DAL node manual with `octez-dal-node run --help` to get more info about the topic available.
```bash!
./octez-dal-node run
--producer-profiles 0
--endpoint <rpc-endpoint-octez-node>
```
allows to run a DAL node that will track the topics for slot index 0.
## Originate rollup
At this stage, the only missing piece before injecting data is to run a rollup using the DAL echo kernel.
This can be done via the smart-rollup kernel installer:
```bash
./smart-rollup-installer get-reveal-installer
--upgrade-to dal_echo_kernel.wasm \
--output output.hex \
--preimages-dir wasm_2_0_0
```
This command will generate a smart-rollup kernel that does two things:
- Import piece by piece the code of the DAL echo kernel into the memory
- When done, exec on the DAL echo kernel
Remark:
- `output.hex` is the hexadecimal representation of the installer kernel
- `wasm_2_0_0` is the kind of the PVM and also the folder that will contain the DAL echo kernel split into smaller chunks.
```
./octez-client --endpoint <node-endpoint> \
--base-dir <your wallet>
originate smart rollup echo \
from <account> \
of kind wasm_2_0_0 \
of type unit \
with kernel `cat output.hex` \
--burn-cap 2 \
--force
```
Notes:
- No need to provide `--base-dir` if you used the default one
- the endpoint is the `octez-node` endpoint.
- `acount` is the acount that will originate the operation
- `output.tex` is the file generated by the previous command
At this stage, the rollup is originated onto the L1, and the code of the kernel is in the repository `wasm_2_0_0`. Next step is to run a smart rollup node that will run the installer kernel, import the chunks of the DAL echo kernel and exec from it.
### Running the rollup node
If you don't want to use the default directory of the rollup node, one must be created:
```
mkdir <my-awesome-rollup-node-directory>
```
Then you need to import the chunks of the DAL echo kernel in the `wasm_2_0_0` directory into the rollup node directory.
If you created an ad-hoc one, the command is:
```
cp -rf wasm_2_0_0 <my_awesome-directory>/wasm_2_0_0
```
if you used the default one then
```
cp -rf wasm_2_0_0 ./tezos-sc-rollup-node/wasm_2_0_0
```
Now you can run the rollup-node:
```bash!
./octez-smart-rollup-node --better-errors \
--base-dir <wallet> \
--endpoint <octez-node-endpoint> \
run operator for echo \
with operators <account> \
--data-dir <data-dir> \
--log-kernel-debug \
--dal-node <octez-dal-node-endpoint>
```
Remarks:
- data-dir is optional if you used a different one
- `--dal-node` allows to specify the DAL node to fetch the data that will be imported by the kernel later on.
## Import data
To import data for the DAL echo kernel, you need to make a `slot` (of a fixed-length). The length is of size `slot-size` which is a parametric constant from the economic protocol.
The value `slot-size` can be obtained via an RPC `./octez-client rpc get /chains/main/blocks/head/context/constants`.
To generate those data, one can use a script:
```bash
acc=123456789000
echo '"' > data.txt
echo $acc >> data.txt
for i in `seq 1 65530`; do printf "00"; done >> data.txt
echo '"' >> data.txt
```
This script generates data of size 65536, but it needs to be adapted if the `slot-size` is different.
We have no DAL client yet, so we use `curl` to make HTTP request to the DAL node.
### Step a: Generate a commitment
```bash!
curl -s -X POST http://localhost:30001/commitments \
-H 'Content-Type: application/json' --data "@data.txt"
```
We make a POST request to post the data we generated previously.
```bash!
curl -s -X PUT \
http://localhost:30001/commitments/<slot_header>/shards \
-H 'Content-Type: application/json' \
--data '{"with_proof": true}'
```
We generate the shards that will be propagated onto the DAL P2P network. Please replace `<slot_header>` by the result of the previous RPC.
```bash!
curl -s -X GET \
http://localhost:30001/commitments/<slot_header>/proof
```
We generate the proof of the commitment (proving the size of the slot does not exceed `slot-size`).
Finally, we can inject the commitment:
```bash
./octez-client --endpoint <octez-node> \
--base-dir <wallet> \
--wait 0 publish dal commitment \
<slot_header \
from publisher for slot 0 with proof \
<proof>
```
Where `<proof>` is the result of the previous RPC. When the `octez-client` returns the commitment has been included into the L1. Now we just have to wait for the DAL to work. We can use Explorus for that: https://beta.explorus.io/dal (select weeklynet).
We can check the content via:
```bash!
./octez-smart-rollup-client-alpha rpc get \
'/global/block/head/durable/wasm_2_0_0/value?key=/output/slot-0' | less
```
Change the `slot-0` into the corresponding slot index you have used.