-
Notifications
You must be signed in to change notification settings - Fork 8
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 code snippets and move to rust workspace #302
base: master
Are you sure you want to change the base?
Conversation
@UtkarshBhardwaj007 I have migrated the existing code for the current tutorials. I'll wait until the benchmarking PR is merged so I can include that here |
Thanks, this is great. I believe you mean this PR? It is merged now and you should be able to use it. I'll review once you do :) |
...utorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/tests/integration_tests.rs
Show resolved
Hide resolved
.snippets/code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallet-unit-testing/src/lib.rs
Outdated
Show resolved
Hide resolved
frame-system = { version = "38.0.0", default-features = false } | ||
scale-info = { version = "2.11.1", default-features = false } | ||
sp-runtime = { version = "39.0.5", default-features = false } | ||
color-print = { version = "0.3.4" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, if you use the umbrella crate here, you will have a much easier time updating dependencies.
...polkadot-sdk/parachains/zero-to-hero/add-pallets-to-runtime/pallets/custom-pallet/src/lib.rs
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,193 @@ | |||
use crate::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double checking: are all of these files actually needed?
It seems like this step of the tutorial is about benchmarking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to compile the runtime without modifying the template src code we need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a LOT of code being pulled here, sometimes multiple copies of the same. We need to double check if this is the right pattern.
I mean, why do we need code related to XCM config, a full working runtime and so on here?
Let's establish a framework around how we should do this task that is sane, minimal but still achieves to goal.
Imagine you have the old school doc in front of you, with a hardcoded code in the markdown file.
The question you should be asking is this:
- What is the "smallest working rust project" that I can add, that can contain this snippet and make sure it is correct?
And only create that.
The only bottleneck/exception to this is that you might want to reference snippets of code in the original parachain template that this tutorial is based on, in which case we can embed the correct version of this template that we are relying on as a git submodule
to this repo. This will actually improve our flow, as it will be super clear: "this toturial is based on the parachain template commit XXX", and every time there is a new parachain template release, we can also update it here.
@0xLucca @nhussein11 Adding the points that we discussed here for your review @kianenigma @albertov19 :
@0xLucca Feel free to add to this in case I missed something :) |
Everything makes sense IMO. I'll let Kian comment a bit more on the Substrate/Rust technical side of things.
If templates are within our control, we should add licenses to it. If they are external (OpenZeppelin for example,) they inherit the license of the code being imported. |
I'll work today on leaving just one crate and adjusting all the .md files to use that. Regarding licenses, there are some files that we pull from the parachain template that do not have licenses (example), some are licensed as unlicensed (example) and others as Apache 2.0 (example). For now, I'll just add the MIT-0 license to the files we created from scratch |
@kianenigma @UtkarshBhardwaj007 This is ready to review. I've moved all the code to a single crate and updated the md files |
.snippets/code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/template/Cargo.toml
Outdated
Show resolved
Hide resolved
tutorials/polkadot-sdk/parachains/zero-to-hero/add-pallets-to-runtime.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com>
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/Cargo.toml:24:30' | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/Cargo.toml:35:35' | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/Cargo.toml:22:28' | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] | |
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/Cargo.toml:30:30' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not hardcode things as much as possible. I know we have to do some workarounds with mkdocs
to make this work but I think it is better than hardcoding things in the .md
files.
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/Cargo.toml::14' | ||
|
||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/Cargo.toml:22:28' | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] | |
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/Cargo.toml:30:30' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/src/lib.rs:203:203' | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:20:23' | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:36:47' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:57:57' | |
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:218:218' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing one closing {
. The extra tab
before the first line is to ensure consistent formatting as mkdocs
doesn't take care of that when we use code snippets.
@@ -0,0 +1,305 @@ | |||
// This is free and unencumbered software released into the public domain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xLucca can you please do the exercise I proposed in #302 (review)?
What snippets of code do you want to add to the tutorial's markdown format? What is the smallest running code that can represent that?
I don't get why don't build a that is
- frame system
- pallet utility
- custom pallet
- the macros related to benchmarking
and that's it. Why should this simple tutorial have all of this runtime apis, xcm configs, weights files and so on?
Or anything else that you actually want to show?
These codes are all fairly independent of any template, and work on any of them.
If you have a good reason that any of this code actually depends on the full runtime, please tell me, but I am pretty sure there is none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to ask one more time to reevaluate the approach here and not copy paste the template here
https://github.com/polkadot-developers/polkadot-docs/pull/302/files#r1917045718
@@ -118,7 +119,8 @@ In this step, you will configure two essential components that are critical for | |||
Add the following `Config` trait definition to your pallet: | |||
|
|||
```rust | |||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/src/lib.rs:33:42' | |||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:45:53' | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is at various places. Could you please update this everywhere just for consistency.
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:179:186' | ||
#[pallet::weight(0)] | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs:188:188' | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing {
```rust | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/build-custom-pallet/src/lib.rs::203' | ||
--8<-- 'code/tutorials/polkadot-sdk/parachains/zero-to-hero/pallets/custom-pallet/src/lib.rs::23' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes the license. I don't think we need to show the license in the tutorials.
This PR reorganizes the code snippets in the zero-to-hero tutorial to be part of the Rustr workspace