Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and improve smart rollup tutorial #118

Merged
merged 62 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c70262e
This should be the last tutorial because of the complexity
timothymcmackin Oct 5, 2023
59236e4
Title
timothymcmackin Oct 5, 2023
70e6c63
Intro
timothymcmackin Oct 5, 2023
1ac78f7
What is a smart rollup?
timothymcmackin Oct 5, 2023
0891661
prereqs
timothymcmackin Oct 5, 2023
112fd94
What is a smart rollup v2
timothymcmackin Oct 6, 2023
539cb1b
Applications that communicate with other blockchains
timothymcmackin Oct 6, 2023
5aacfc5
Enable embedded HTML in markdown
timothymcmackin Oct 6, 2023
ec9f3ea
Diagram
timothymcmackin Oct 6, 2023
b942440
Need to communicate
timothymcmackin Oct 6, 2023
dc6d15f
Tutorial application
timothymcmackin Oct 6, 2023
e74ea9e
Tweaks
timothymcmackin Oct 6, 2023
d054789
Setup and build
timothymcmackin Oct 6, 2023
781691f
Sandbox
timothymcmackin Oct 6, 2023
07185dc
build troubleshooting
timothymcmackin Oct 6, 2023
79fed44
Debug mode and optimizing the kernel
timothymcmackin Oct 6, 2023
aa0a55b
tweaks
timothymcmackin Oct 6, 2023
3153944
Deploying the kernel and running the node
timothymcmackin Oct 6, 2023
f371526
Notes on next steps
timothymcmackin Oct 6, 2023
2b09d88
references and next steps
timothymcmackin Oct 9, 2023
3121630
comments
timothymcmackin Oct 9, 2023
4bb6b83
list numbering
timothymcmackin Oct 9, 2023
08510d3
not getting into this yet
timothymcmackin Oct 9, 2023
5f1b2d0
tweaks
timothymcmackin Oct 9, 2023
0e33475
To open a new one
timothymcmackin Oct 9, 2023
b206696
origination clarifications from Emma
timothymcmackin Oct 9, 2023
3b55fc5
You originate the rollup, not the kernel
timothymcmackin Oct 9, 2023
43c41b9
update references
timothymcmackin Oct 9, 2023
f57d8c6
reorder intro sections
timothymcmackin Oct 11, 2023
36c698d
clarify main function
timothymcmackin Oct 11, 2023
b62dc43
tweaks
timothymcmackin Oct 11, 2023
a5117fc
The tutorial doesn't provide enough info for the user to do this; com…
timothymcmackin Oct 11, 2023
3248740
cleaning up comments and todos
timothymcmackin Oct 11, 2023
27e4668
Separate into sections
timothymcmackin Oct 12, 2023
96200f1
run `$CC --version`
timothymcmackin Oct 24, 2023
d4ddcaa
grep for wasm32 directly
timothymcmackin Oct 24, 2023
4f0931c
This shouldn't be needed anymore
timothymcmackin Oct 17, 2023
ca72efb
Use new version of Rust if this PR is accepted: https://gitlab.com/tr…
timothymcmackin Oct 17, 2023
b25c283
How the installer kernel works
timothymcmackin Oct 24, 2023
4087c61
Converted to binary
timothymcmackin Oct 24, 2023
a73daf7
Split lines
timothymcmackin Oct 24, 2023
88dc0ea
Remove reference to smart contract tutorial
timothymcmackin Oct 24, 2023
95e19e2
Line breaks for better appearance
timothymcmackin Oct 24, 2023
933450e
To originate the kernel on Tezos, it must fit within the maximum size…
timothymcmackin Oct 24, 2023
8358bca
Release build of kernel
timothymcmackin Oct 24, 2023
fcdd812
Optimize the release kernel
timothymcmackin Oct 24, 2023
f4d24cd
Parallel with smart contracts and link to tutorial
timothymcmackin Oct 24, 2023
e6eaa21
Debug the installer kernel
timothymcmackin Oct 24, 2023
2a902a3
Create wasm first to debug, then generate hex to originate
timothymcmackin Oct 25, 2023
692abe1
this is a wasm file
timothymcmackin Oct 25, 2023
bab62a2
line breaks
timothymcmackin Oct 25, 2023
2d7a614
Don't start the sandbox until you need it
timothymcmackin Oct 25, 2023
ca631c0
To get the kernel running...
timothymcmackin Oct 25, 2023
8c852b2
Split up this topic to stress the interaction
timothymcmackin Oct 25, 2023
eb04a17
which provides the hash and timestamp of the previous block
timothymcmackin Oct 26, 2023
eb6c4c5
to request data from outside of layer 1.
timothymcmackin Oct 26, 2023
70416da
Shows that the upgrade was successful
timothymcmackin Oct 26, 2023
62d8a70
hex-encoded
timothymcmackin Oct 26, 2023
c24be8b
reduce the size of
timothymcmackin Oct 26, 2023
7bb4e3e
the maximum size for a layer 1 operation (32KB)
timothymcmackin Oct 26, 2023
a0310d5
Use rustc for rust version instead of cargo
timothymcmackin Oct 26, 2023
2f73983
Make sure that Docker desktop is running.
timothymcmackin Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions markdoc/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import CalendlyEmbed from '@/components/CalendlyEmbed';
// Import the built-in Next.js tags
import { comment } from '@markdoc/next.js/tags'

// Custom tag to allow embedding HTML elements
const UnescapedHtml = ({ htmlWrapperTag = 'div', children }) => {
const html =
typeof children === 'string'
? children
: typeof children.props.children === 'string'
? children.props.children
: children.props.children.join('')

const CustomTag = htmlWrapperTag
return <CustomTag dangerouslySetInnerHTML={{ __html: html }} />
}

const tags = {
callout: {
attributes: {
Expand Down Expand Up @@ -82,6 +95,13 @@ const tags = {
calendlyEmbed: {
render: CalendlyEmbed,
},
html: {
render: UnescapedHtml,
attributes: {
htmlWrapperTag: { type: String },
children: { type: String },
},
},
// tabs: {
// render: Tabs,
// attributes: {},
Expand Down
34 changes: 30 additions & 4 deletions src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ const tutorialNavigation = [
},
],
},
{
title: 'Deploy your own smart rollup',
href: '/tutorials/smart-rollups',
},
{
title: 'Create an NFT',
href: '/tutorials/create-an-nft',
Expand Down Expand Up @@ -347,6 +343,36 @@ const tutorialNavigation = [
},
],
},
{
title: 'Deploy a smart rollup',
href: '/tutorials/smart-rollups',
children: [
{
title: "Introduction",
href: '/tutorials/smart-rollups',
},
{
title: "Part 1: Setting up the application",
href: '/tutorials/smart-rollups/set-up',
},
{
title: "Part 2: Running the kernel in debug mode",
href: '/tutorials/smart-rollups/debug',
},
{
title: "Part 3: Optimizing the kernel",
href: '/tutorials/smart-rollups/optimize',
},
{
title: "Part 4: Deploying (originating) the rollup",
href: '/tutorials/smart-rollups/deploy',
},
{
title: "Part 5: Running and interacting with the rollup node",
href: '/tutorials/smart-rollups/run',
},
],
},
],
},
]
Expand Down
38 changes: 38 additions & 0 deletions src/pages/tutorials/smart-rollups/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
id: debug
title: "Part 2: Running the kernel in debug mode"
lastUpdated: 25th October 2023
---

Octez provides a command 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.

1. In the terminal window inside the Docker container, go to the `hello_world_kernel` folder.

1. Run this command to start the rollup and pass an empty message inbox to it:

```bash
octez-smart-rollup-wasm-debugger \
--kernel target/wasm32-unknown-unknown/debug/hello_world_kernel.wasm \
--inputs empty_input.json
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an error appeared when I try this command:
/bin/sh: step: not found
~/hello-world-kernel $ octez-smart-rollup-wasm-debugger \

--kernel target/wasm32-unknown-unknown/debug/hello_world_kernel.wasm
--inputs empty_input.json
Error
Wrong value for command line option --kernel.
target/wasm32-unknown-unknown/debug/hello_world_kernel.wasm is not a valid file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that error when the .wasm file is not found. Are you sure you are in the hello_world_kernel folder and the path to the wasm file is correct?


The command prompt changes again to show that you are in debugging mode, which steps through commands.

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

```bash
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

1. Press Ctrl + C to end debugging mode.

Now you know that the kernel works.
In the next section, you optimize the kernel to be deployed to the sandbox.
66 changes: 66 additions & 0 deletions src/pages/tutorials/smart-rollups/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
id: deploy
title: "Part 4: Deploying (originating) the rollup"
lastUpdated: 25th October 2023
---

Smart rollups are originated in a way similar to smart contracts.
Instead of running the `octez-client originate contract` command, you run the `octez-client originate smart rollup` command.
This command creates an address for the rollup and stores a small amount of data about it on layer 1.

1. In the Docker container, in the `hello-world-kernel` folder, run this command to start the sandbox:

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

This command starts a Tezos testing environment, including a baking node running in sandbox mode and a group of test accounts.
The console shows repeated messages that show that the node is baking blocks.
For more information about sandbox mode, see [sandbox mode](https://tezos.gitlab.io/user/sandbox.html).

If you see an error that says "Unable to connect to the node," you can ignore it because it happens only once while the node is starting.

1. Leave that terminal instance running for the rest of the tutorial.

1. Open a new terminal window.

1. In the new terminal window, enter the Docker container by running this command:

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

Now the second terminal window is running inside the container just like the first one.

1. In the second terminal window, run this command to verify that the sandbox is running with the correct protocol:

```bash
octez-client rpc get /chains/main/blocks/head/metadata | grep protocol
```

The response shows the protocol that the sandbox is running, as in this example:

```
{ "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK",
"next_protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK",
```

If you don't see a message that looks like this one, check for errors in the first terminal window.

Now the sandbox is running in the Docker container and you can use it to test the rollup.

1. 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
```

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

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`.

Now layer 1 is aware of the rollup and nodes can run the rollup kernel.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is really short. You could potentially originate a very simple contract here, and call the rollup entrypoint? (To prove that Layer 1 really does know about it?). Maybe it would overcomplicate it though.

Alternatively, if we used the debugger on the installer in the previous previous section, you could use it again here for the proper origination?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is a bit longer now because it includes starting the sandbox.

For calling the rollup from a smart contract, thank you for helping me work out how to do that. I'll get this PR pushed through and add that to the tutorial in the future.

Loading