From 98e22bc173aaddee8549b5e040abea27c9f708e6 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 13 Aug 2023 22:23:37 -0700 Subject: [PATCH 1/3] polkish mod 5 prior to content publish --- .../img/5-Substrate/dev-4-1-comms-format.svg | 2 +- .../5-Substrate/dev-4-1-substrate-meta.svg | 2 +- .../dev-trie-backend-16-with-size.svg | 1 + ...ides.md => 1-Intro-to-Substrate_Slides.md} | 9 +- ...ides.md => 2-WASM-Meta-Protocol-Slides.md} | 2 - ...lides.md => 3-Merklized-Storage_Slides.md} | 20 +- ...Slides.md => 4-Transaction-Pool_Slides.md} | 0 ...{4.x-SCALE_Slides.md => 9-SCALE_Slides.md} | 0 ...> 9-Substrate-FRAME-Tips-Tricks-Slides.md} | 10 +- ...s.md => 9-Substrate-In-The-Code_Slides.md} | 5 +- ....md => 9-Substrate-Interactions_Slides.md} | 26 - .../5-Substrate/99-DEP-JSON-RPC_slides.md | 149 ---- .../99-DEP-PJS-api-crash-course_slides.md | 245 ------ ...9-DEP-Substrate-Folder-Structure_slides.md | 303 ------- .../99-DEP-Substrate_CLI_Slides.md | 747 ------------------ 15 files changed, 30 insertions(+), 1491 deletions(-) create mode 100644 assets/img/5-Substrate/dev-trie-backend-16-with-size.svg rename syllabus/5-Substrate/{1.0-Intro-to-Substrate_Slides.md => 1-Intro-to-Substrate_Slides.md} (99%) rename syllabus/5-Substrate/{2.WASM-Meta-Protocol-Slides.md => 2-WASM-Meta-Protocol-Slides.md} (99%) rename syllabus/5-Substrate/{3.Merklized-Storage_Slides.md => 3-Merklized-Storage_Slides.md} (97%) rename syllabus/5-Substrate/{4.X-Transaction-Pool_Slides.md => 4-Transaction-Pool_Slides.md} (100%) rename syllabus/5-Substrate/{4.x-SCALE_Slides.md => 9-SCALE_Slides.md} (100%) rename syllabus/5-Substrate/{4.x-Substrate-FRAME-Tips-Tricks-Slides.md => 9-Substrate-FRAME-Tips-Tricks-Slides.md} (99%) rename syllabus/5-Substrate/{1.1-Substrate-In-The-Code_Slides.md => 9-Substrate-In-The-Code_Slides.md} (95%) rename syllabus/5-Substrate/{4.Substrate-Interactions_Slides.md => 9-Substrate-Interactions_Slides.md} (90%) delete mode 100644 syllabus/5-Substrate/99-DEP-JSON-RPC_slides.md delete mode 100644 syllabus/5-Substrate/99-DEP-PJS-api-crash-course_slides.md delete mode 100644 syllabus/5-Substrate/99-DEP-Substrate-Folder-Structure_slides.md delete mode 100644 syllabus/5-Substrate/99-DEP-Substrate_CLI_Slides.md diff --git a/assets/img/5-Substrate/dev-4-1-comms-format.svg b/assets/img/5-Substrate/dev-4-1-comms-format.svg index 67e765a91..b1729fb61 100644 --- a/assets/img/5-Substrate/dev-4-1-comms-format.svg +++ b/assets/img/5-Substrate/dev-4-1-comms-format.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/assets/img/5-Substrate/dev-4-1-substrate-meta.svg b/assets/img/5-Substrate/dev-4-1-substrate-meta.svg index ed52b4f5a..b4c2d8305 100644 --- a/assets/img/5-Substrate/dev-4-1-substrate-meta.svg +++ b/assets/img/5-Substrate/dev-4-1-substrate-meta.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/assets/img/5-Substrate/dev-trie-backend-16-with-size.svg b/assets/img/5-Substrate/dev-trie-backend-16-with-size.svg new file mode 100644 index 000000000..9ea3bc14a --- /dev/null +++ b/assets/img/5-Substrate/dev-trie-backend-16-with-size.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/syllabus/5-Substrate/1.0-Intro-to-Substrate_Slides.md b/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md similarity index 99% rename from syllabus/5-Substrate/1.0-Intro-to-Substrate_Slides.md rename to syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md index b25e53998..a29e3bf1f 100644 --- a/syllabus/5-Substrate/1.0-Intro-to-Substrate_Slides.md +++ b/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md @@ -348,6 +348,11 @@ _The way to make a protocol truly upgradeable is to design a meta-protocol that +Note: + +In this figure, the meta-protocol, the substrate client, is not forklessly upgrade-able. It can only +be upgraded with a fork. The WASM protocol, though, can be upgraded forklessly. + ---v ### ๐Ÿฆ Governance + Upgradeability @@ -996,11 +1001,9 @@ exception](https://www.gnu.org/software/classpath/license.html). - Currently, the Wasm binary spec v1 is used, read more about the new version here: https://webassembly.github.io/spec/core/binary/index.html -### Post Lecture Notes +### Post Lecture Feedback - a takeaway after each section, more clear path (shawn). -- people confuse that the client is not upgradeable AT ALL. Mention more that it is, just with forks. -- Make the arrow bidirectional in communication paths. --- diff --git a/syllabus/5-Substrate/2.WASM-Meta-Protocol-Slides.md b/syllabus/5-Substrate/2-WASM-Meta-Protocol-Slides.md similarity index 99% rename from syllabus/5-Substrate/2.WASM-Meta-Protocol-Slides.md rename to syllabus/5-Substrate/2-WASM-Meta-Protocol-Slides.md index cb9411af2..3c56240c8 100644 --- a/syllabus/5-Substrate/2.WASM-Meta-Protocol-Slides.md +++ b/syllabus/5-Substrate/2-WASM-Meta-Protocol-Slides.md @@ -1414,8 +1414,6 @@ SomeExternalities.execute_with(|| { ### Post Lecture Notes -- Resource management (block length, weight) is dictated by the runtime. - --- ## Appendix diff --git a/syllabus/5-Substrate/3.Merklized-Storage_Slides.md b/syllabus/5-Substrate/3-Merklized-Storage_Slides.md similarity index 97% rename from syllabus/5-Substrate/3.Merklized-Storage_Slides.md rename to syllabus/5-Substrate/3-Merklized-Storage_Slides.md index 754b456a0..3dadf521f 100644 --- a/syllabus/5-Substrate/3.Merklized-Storage_Slides.md +++ b/syllabus/5-Substrate/3-Merklized-Storage_Slides.md @@ -424,6 +424,16 @@ size and the cost of reading/writing/encoding/decoding all these nodes. ### Base 2, Base 16, Base-26? + + +Note: + +Here's a different way to represent it; the nodes are bigger on the base-16 trie. + +---v + +### Base 2, Base 16, Base-26? + - base-2: Small proofs, more nodes. - base-8: Bigger proofs, less nodes. @@ -614,8 +624,6 @@ with_storage_layer(|| { Notes: - implement with zero-copy. So, the size of values is not so important, it is more about the number. -- TODO: This `with_storage_layer` is currently in FRAME, but it could technically be in primitives, - as there is nothing frame specific about it. ---v @@ -847,7 +855,9 @@ Notes: about what a state transition is. The runtime is the state transition function. Recall the formula of that, and then you will know why this is not allowed. -## Post Lecture +### Post Lecture Feedback + +Double check the narrative and example of the `BIG_STUFF` node. An example/exercise of some sort +would be great, where students call a bunch of `sp_io` functions, visualize the trie, and invoke +proof recorder, and see which pars of the trie is exactly part of the proof. -From Shawn: my narrative of big_stuff still seems incorrect; 100% double check it before going any -further. diff --git a/syllabus/5-Substrate/4.X-Transaction-Pool_Slides.md b/syllabus/5-Substrate/4-Transaction-Pool_Slides.md similarity index 100% rename from syllabus/5-Substrate/4.X-Transaction-Pool_Slides.md rename to syllabus/5-Substrate/4-Transaction-Pool_Slides.md diff --git a/syllabus/5-Substrate/4.x-SCALE_Slides.md b/syllabus/5-Substrate/9-SCALE_Slides.md similarity index 100% rename from syllabus/5-Substrate/4.x-SCALE_Slides.md rename to syllabus/5-Substrate/9-SCALE_Slides.md diff --git a/syllabus/5-Substrate/4.x-Substrate-FRAME-Tips-Tricks-Slides.md b/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md similarity index 99% rename from syllabus/5-Substrate/4.x-Substrate-FRAME-Tips-Tricks-Slides.md rename to syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md index 2d0a5cb94..81416dd64 100644 --- a/syllabus/5-Substrate/4.x-Substrate-FRAME-Tips-Tricks-Slides.md +++ b/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md @@ -185,8 +185,6 @@ note: imagine that you have a crate that has some additional features that are not always needed. You put that behind a feature flag called `additional-features`. -TODO: feature flags should be part of the rust entrance exam. - ---v ### Cargo Features: Substrate Wasm Crates @@ -843,8 +841,6 @@ Notes: often times, in examples above, you have to use this syntax: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name -TODO: we should explicitly add this to the exam as well. - --- ## Implementing Traits For Tuples @@ -1157,7 +1153,5 @@ Notes: - Update on defensive ops: https://github.com/paritytech/substrate/pull/12967 - Next time, talk about making a storage struct be ``. - Cargo format - -TODO: - -- SignedExtension should technically be part of the substrate module. Integrate it in the assignment, perhaps. +- SignedExtension should technically be part of the substrate module. Integrate it in the + assignment, perhaps. diff --git a/syllabus/5-Substrate/1.1-Substrate-In-The-Code_Slides.md b/syllabus/5-Substrate/9-Substrate-In-The-Code_Slides.md similarity index 95% rename from syllabus/5-Substrate/1.1-Substrate-In-The-Code_Slides.md rename to syllabus/5-Substrate/9-Substrate-In-The-Code_Slides.md index 78be068aa..044a55a93 100644 --- a/syllabus/5-Substrate/1.1-Substrate-In-The-Code_Slides.md +++ b/syllabus/5-Substrate/9-Substrate-In-The-Code_Slides.md @@ -191,4 +191,7 @@ Simply search the trait in the rust-docs, and find the implementors! -Notes: +Note: + +One important concept that is important to substrate-based chains, but is somewhat missing here is +`chain-spec`. Make sure to read up about it in the substrate docs. diff --git a/syllabus/5-Substrate/4.Substrate-Interactions_Slides.md b/syllabus/5-Substrate/9-Substrate-Interactions_Slides.md similarity index 90% rename from syllabus/5-Substrate/4.Substrate-Interactions_Slides.md rename to syllabus/5-Substrate/9-Substrate-Interactions_Slides.md index 398d2d902..4cfcf8ad7 100644 --- a/syllabus/5-Substrate/4.Substrate-Interactions_Slides.md +++ b/syllabus/5-Substrate/9-Substrate-Interactions_Slides.md @@ -72,8 +72,6 @@ almost all external communication happens over JSPN-RPC, so let's take a closer Notes: -TODO: @NukeManDan a proper solution for list with fragments would be good, see: https://github.com/hakimel/reveal.js/issues/1848 - recall: https://paritytech.github.io/substrate/master/sc_rpc_api/index.html @@ -251,19 +249,6 @@ https://polkadot.js.org/docs/substrate/rpc#getstoragekey-storagekey-at-blockhash await api.rpc.state.getStorageSize("0x3A636F6465"), ``` -light client: - -TODO: needs fixing - -```ts -import { ScProvider } from "@polkadot/rpc-provider/substrate-connect"; -import * as Sc from "@substrate/connect"; - -const lightProvider = new ScProvider(Sc, Sc.WellKnownChain.polkadot); -await lightProvider.connect(); -const lightApi = await ApiPromise.create({ lightProvider }); -``` - A few random other things: ```ts @@ -294,14 +279,3 @@ Notes: - see "Client Libraries" here: https://project-awesome.org/substrate-developer-hub/awesome-substrate - https://paritytech.github.io/json-rpc-interface-spec/introduction.html - Full subxt guide: https://docs.rs/subxt/latest/subxt/book/index.html - -TODO: further assignment idea: - -- build a custom chain spec, then run it - -- Use `curl` and such to interact. -- Connect PJS apps. -- Write a few simple lines of TS to interact. -- Write a few lines of Rust with SubXT to interact. - -Tricky, as we would be using a FRAME based runtime in order to get some metadata out of it. diff --git a/syllabus/5-Substrate/99-DEP-JSON-RPC_slides.md b/syllabus/5-Substrate/99-DEP-JSON-RPC_slides.md deleted file mode 100644 index 25ddad43d..000000000 --- a/syllabus/5-Substrate/99-DEP-JSON-RPC_slides.md +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: (Deprecated)JSON-RPC Protocol -description: Substrate Overview for Web3 engineers -duration: 45 minutes ---- - -# JSON-RPC Protocol - -### _..and its usage in Substrate._ - ---- - -### The Need For a Common Language - - - ---- - -## JSON-RPC - -> JSON-RPC is a remote procedure call protocol encoded in JSON. It is similar to the XML-RPC protocol, defining only a few data types and commands. - ----v - -### JSON-RPC - -- Nowadays, mostly version 2 is used. -- Request - -```json -{ "jsonrpc": "2.0", "method": "subtract", "params": { "minuend": 42, "subtrahend": 23 }, "id": 3 } -``` - -- Response, if `id` is provided - -```json -{ "jsonrpc": "2.0", "result": 19, "id": 3 } -``` - ----v - -### JSON-RPC - -- Entirely transport agnostic. Deliver the packet to the server, and it will reply. -- Substrate based chains expose both `ws` and `http` (or `wss` and `https`, if desired). - -> with `--ws-port` and `--rpc-port`, 9944 and 9934 respectively. - -Notes: - -```sh -# Kusama endpoint -echo '{ "jsonrpc":"2.0", "id":1, "method":"system_chain" }' | websocat -B 99999999 ws://34.79.74.54:9924 -``` - ----v - -### JSON-RPC - -- JSON-RPC methods are conventionally written as `scope_method` - - - e.g. `rpc_methods`, `state_call` - -- `author`: for submitting stuff to the chain. -- `chain`: for retrieving information about the _blockchain_ data. -- `state`: for retrieving information about the _state_ data. -- `system`: information about the chain, not to be confused with `frame-system`. -- `rpc`: information about the RPC endpoints. - ----v - -### JSON-RPC - -- The full list of substrate RPC can be seen here: https://polkadot.js.org/docs/substrate/rpc/ - ----v - -### JSON-RPC - -- Let's look at a few examples: - -- `system_name`, `system_chain`, `system_chainType`, `system_health`, `system_version`, `system_nodeRoles`, `rpc_methods`, `state_getRuntimeVersion`, `state_getMetadata` - -```sh -# Polkadot public endpoint -echo '{"jsonrpc":"2.0", "id":1, "method":"system_chain" }' | websocat -B 99999999 wss://rpc.polkadot.io | jq -``` - ----v - -### JSON-RPC - -- The whole point of JSON-RPC is to abstract away programming languages and allow a client and server to talk to each other. -- That being said, the following are the noteworthy "libraries" examples that you can use: - - `polkadot.js API`: low and high level library in JS/TS - - `JSONRPSee` (low level Rust library) - - `subxt` (high level Rust library) - - https://polkadot.js.org/apps/#/rpc - ----v - -### JSON-RPC: Activity - -- Prepare `websocat` (and optionally `jq` to pretty display JSON outputs) as your tool of - choice. - -1. Find the genesis hash of the given chain via RPC. -1. Find the first 4 bytes of the code of the given chain. -1. Find the first 4 bytes of the code of the given chain at block 1 million. -1. The block number is stored under `twox(System) ++ twox(Number)`. Find it! - -Notes: - -```sh -# Kusama -echo '{"jsonrpc":"2.0", "id":72, "method":"chain_getBlockHash", "params": ["0x0"] }' | websocat -B 99999999 ws://34.79.74.54:9944 | jq -echo '{"jsonrpc":"2.0", "id":72, "method":"chain_getBlock", "params": ["0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"] }' | websocat -B 99999999 ws://34.79.74.54:9944 | jq - -echo '{"jsonrpc":"2.0", "id":72, "method":"state_getStorage", "params": ["0x3a636f6465"] }' | websocat -B 99999999 ws://34.79.74.54:9944 | head -c 100 - -System: 0x26aa394eea5630e07c48ae0c9558cef7 -Number: 0x02a5c1b19ab7a04f536c519aca4983ac -Key: 0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac -``` - ----v - -### JSON-RPC: Code Activity - -- Try and find all the RPC endpoints in the Rust code! -- The runtime can expose custom RPCs as well, try and find them! -- You have 15 minutes! - ---- - -## Additional Resources! ๐Ÿ˜‹ - -> Check speaker notes (click "s" ๐Ÿ˜‰) - -Notes: - -- see "Client Libraries" here: https://project-awesome.org/substrate-developer-hub/awesome-substrate -- https://paritytech.github.io/json-rpc-interface-spec/introduction.html - -TODO: - -subxt, especially usage of light clients. - -safe and unsafe RPCs diff --git a/syllabus/5-Substrate/99-DEP-PJS-api-crash-course_slides.md b/syllabus/5-Substrate/99-DEP-PJS-api-crash-course_slides.md deleted file mode 100644 index a2ae2f71f..000000000 --- a/syllabus/5-Substrate/99-DEP-PJS-api-crash-course_slides.md +++ /dev/null @@ -1,245 +0,0 @@ ---- -title: (Deprecated)Polkadot JS API Crash Course -description: Polkadot JS API Crash Course for Web3 engineers -duration: 1 hour ---- - -# Polkadot JS API Crash Course - ----v - -## Context - -- De facto library to work with all FRAME-based substrate runtimes. - - - ----v - -## Overview - -> https://github.com/kianenigma/polkadot-js-api-ts-template/ - ----v - -### Overview - -- `api.registry` -- `api.rpc` -- `@polkadot/keyring`. -- `@polkadot/utils`. - ----v - -### Overview - -Almost everything else basically builds on top of `api.rpc`. - -- `api.tx` -- `api.query` -- `api.consts` -- `api.derive` - ---- - -## `api` - -Notes: - -```ts -import { ApiPromise, WsProvider } from "@polkadot/api"; -const provider = new WsProvider("wss://rpc.polkadot.io"); -const api = await ApiPromise.create({ provider }); - -api.stats; -api.isConnected; -api.runtimeVersion; -``` - ---- - -## `api.registry` - -Notes: - -```ts -api.registry.chainDecimals; -api.registry.chainTokens; -api.registry.chainSS58; - -api.registry.metadata; -api.registry.metadata.pallets.map(p => p.toHuman()); - -api.registry.createType(); -``` - ---- - -## `api.rpc` - -- Can call into all RPC endpoints of the chain. - All endpoints are divided based on on scope and method, such as `scope_method`, e.g. `system_chain`. - -Notes: - -```ts -api.rpc.chain.getBlock() - -api.rpc.system.health() -await api.rpc.system.version() - -await api.rpc.state.getRuntimeVersion() -await api.rpc.state.getPairs("0x") - -await api.rpc.state.getKeysPaged("0x", 100) -await api.rpc.state.getStorage() -https://polkadot.js.org/docs/substrate/rpc#getstoragekey-storagekey-at-blockhash-storagedata -await api.rpc.state.getStorageSize("0x3A636F6465"), -``` - ---- - -## `Keyring` - -Notes: - -```ts -import KeyringPair from "@polkadot/keyring"; -import { Keyring } from "@polkadot/api"; -const kr = new Keyring({ type: "sr25519", ss58Format: 42 }); -const account = kr.addFromUri("evil danger film ship lamp gorilla wear job despair garbage dial repair"); - -let sig = account.sign(new Uint8Array([1, 2, 3])); -account.verify(new Uint8Array([1, 2, 3]), sig, account.publicKey); -``` - ---- - -## `api.tx` - -Notes: - -```ts -let call = api.tx.balances.transfer("5FUDdxaaZfye6ogJgqHh3Usqd6WN6q8aApFH4XNjU9iDvC49", 1000000000000); -call.toHuman(); -const signed = call.sign(account); -call.toHuman(); - -signed.send(); -signed.send(); - -await call1.signAndSend(account, ({ events = [], status, dispatchError }) => { - console.log(status.toHuman()); -}); - -call - .paymentInfo(account)(await api.rpc.payment.queryInfo(call.toHex())) - .toHuman(); -``` - - - ---- - -## Types - -- `createType`A powerful tool to keep in mind. -- everything is `Codec` by default, and has `toHuman`, `toU8a`, `toHex`, `toString` and **`.eq`**. - -Notes: - -```ts -import * as BN from "bn.js"; -api.createType("Balance", new Uint8Array([1, 2, 3, 4])); -``` - ---- - -## Crypto Utils - -Notes: - -```ts -import { blake2AsHex, xxHashAsHex, checkAddress } from "@polkadot/util-crypto"; -blake2AsHex("Foo"); -xxHashAsHex("Foo"); -``` - ---- - -## `api.query` - -- `api.query.[module_name].[storage_name]()` -- `api.query.[module_name].[map_name](key)` -- `api.query.[module_name].[map_name].entries()` -- `api.query.[module_name].[double_map_name](key1, key2)` - -Notes: - -```ts -await api.query.system - .number()(await api.query.system.lastRuntimeUpgrade()) - .toHuman()(await api.query.council.members()) - .toHuman(); -``` - -```ts -// let's see what else a storage item has -api.query.council.proposalOf; -api.query.council.proposalOf - .keyPrefix()(await api.query.council.proposalOf.entries()) - .forEach(([key, value]) => console.log(`${key} // ${value}`))(await api.query.council.proposalOf.entries()) - .forEach(([key, value]) => console.log(`${key} // ${key.args[0]} // ${key.slice(-32)} // ${value}`)); -await api.query.council - .proposalOf("0x678debcc07e2300db98fa74979c8e75ebd0075bee8f58bf7c1ca4bda724449f8")( - await api.query.council.proposalOf.keys() - ) - .map(x => x.toString()); -``` - ---- - -## `api.consts` - -- `api.consts.[config_name]()` - -Notes: - -```ts -api.consts.system.version.toHuman(); -api.consts.system.blockWeights.toHuman(); -api.consts.system.blockLength.toHuman(); -``` - ---- - -## `api.derive` - -Helpers that combine multiple calls and queries into one. -Entirely optional to use. - -Notes: - -```ts -await api.derive.accounts.hasIdentity("15S7YtETM31QxYYqubAwRJKRSM4v4Ua6WGFYnx1VuFBnWqdG"); -const unsub = await api.derive.chain - .subscribeNewHeads(h => { - console.log(h.author); - unsub(); - })(await api.rpc.chain.getBlockHash(100)) - .toHuman()(await api.rpc.chain.getBlock("0xedf9246b378fe4aa1c29d21c64b0bf9880553690ce6cd956c18c03310e49fa5f")) - .toHuman(); -api.derive.chain.getBlockByNumber(1000); - -api.derive.chain.bestNumberFinalized(); -``` - ---- - -## Exercise: Using Polkadot JS API - -- Find the some interesting blocks in Polkadot/Kusama: - - The largest block - - The block that consumed the most weight. - - Last remark that Shawn made onchain??? ๐Ÿค” -- Bonus: use [subxt](https://github.com/emostov/substrate-subxt/). diff --git a/syllabus/5-Substrate/99-DEP-Substrate-Folder-Structure_slides.md b/syllabus/5-Substrate/99-DEP-Substrate-Folder-Structure_slides.md deleted file mode 100644 index 799789a78..000000000 --- a/syllabus/5-Substrate/99-DEP-Substrate-Folder-Structure_slides.md +++ /dev/null @@ -1,303 +0,0 @@ ---- -title: (Deprecated)Substrate Folder Structure -description: -duration: 30m lecture + 60m node-template activity + 60m wasm-crate activity ---- - -# Substrate Folder Structure - ---- - -## Substrate Folder Structure - -- How to look at substrate from **_within_**. - - Mostly relevant when wanting to work on substrate itself. -- How to look at substrate from **_without_**. - - Mostly relevant when wanting to build on top of substrate. - ---- - -## Substrate Internally - -Substrate is roughly composed of 3 parts: - -- Client: `./client`: `sc-*` -- FRAME: `./frame`: `frame-*`, `pallet-*` -- Primitives: `./primitives`: `sp-*` - -Primitives is the glue between the other two. - ----v - -### Substrate Internally: `./client` - -- database -- consensus - - finality - - block-builder -- networking -- import-queue / tx-queue / mempool - ----v - -### Substrate Internally: `./primitives` - -- crypto primitives -- runtime-api/host-functions -- ... - ----v - -### Substrate Internally: `./frame` - -- modules that compose the runtime. - - balances/currency (bitcoin) - - Wasm/Solidity smart contracts (Ethereum) - - transaction-payment - - staking - - identity - - proxy / (onchain) multisig - - ... - ----v - -### Workshop - -- Go search for some crates based on these prefixes in https://paritytech.github.io/substrate/. -- Look into the codebase as well. - ----v - -### Substrate Internally - -- So what's the point in all of this? ๐Ÿคจ - -- When looking for the code related to a given topic, this information should help you find it. -
-- Networking? only on `sc-*` -- Database/Storage? Probably in `sc-*` and `sp-*` - ---- - -## Substrate Externally - -- How substrate is seen once used by a developer. -- Substrate can be used as a set of _libraries_ in a binary package. - ----v - -### Substrate Externally - - - ----v - -### Substrate Externally - -- Remember this? This is the node-template or FRAME layer: - - - -Notes: - -A bit of code to build the CI, etc. -A bit of code to build the runtime, with maybe some custom modules. - -And the rest is... MAGIC - ----v - -### Substrate Externally: Examples - -- `bin/kitchensink-node`. -- `bin/node-template`. -- low and behold, the entire `polkadot` repo. -- Tomorrow, you will receive a template for your activity, which is a substrate node without FRAME. - ---- - -## Activity: Exploring Substrate Node Template - -- This is your de-facto "substrate starter pack". - Clone it, and try and find all the main components of it,
based on the material you have learned so far. - -
- -- Which set of functions the runtime is exposing (remember the thing called "**Runtime API**"? ๐Ÿ˜‰)? -- Which modules from `frame` are used in the runtime? -- What is the version of the runtime? spec-name/version (you have not learned about this). -- Which RPC endpoints does this node have? -- Which consensus algorithm(s) is it using? -- You have 15 minutes! - -Notes: - -I can rephrase this exercise as: reading-alien-code challenge. You have not been taught most of -these. - -In the runtime the answer is the top level amalgamator file. In the cli side, look for a -`service.rs` file. - ---- - -## Activity: Compiling Rust to Wasm - -- Let's make a simple rust crate that compiles to Wasm! - ----v - -### Activity: Compiling Rust to Wasm - -- A target triple consists of three strings separated by a hyphen, with a possible fourth string at the end preceded by a hyphen. -- The first is the **architecture**, the second is the **"vendor"**, the third is the **OS type**, and the optional fourth is environment type. - -* `wasm32-unknown-emscripten`: Legacy, provides some kind of `std`-like environment -* `wasm32-unknown-unknown` โœ“ WebAssembly: Can compile anywhere, can run anywhere, no `std` -* `wasm32-wasi` โœ“ WebAssembly with WASI - ----v - -### Rust -> Wasm Details - -```rust -#[no_mangle] // don't re-name symbols while linking -pub extern "C" fn add_one() { // use C-style ABI - ... -} -``` - -and if a library: - -``` -[lib] -crate-type = ["cdylib"] -``` - ----v - -### Activity: Compiling Rust to Wasm - -- you can use `wasmtime-cli` to execute, and `wasm-gc` to trim your Wasm files. -- For each step, try both `wasm32-unknown-unknown` and `wasm32-wasi`. - ----v - -### Activity: Compiling Rust to Wasm - -- First, write a Wasm function that multiplies a number by 2. -- Then, write a Wasm function that prints 42. -- Then, write a Wasm function that prints or returns the current time. -- Then, write a Wasm function that writes the result of the multiplication into a file called `output`. -- Finally, write a Wasm function that multiplies two `f32` numbers. -- Then, really finally, make a Wasm function that divides a number by 0. - -> For this last one, you might want to transform your `wasm-library` crate into a `wasm` "bin" crate. - ---- - -## Extra Activity: Wasm Execution - -- Substrate supports two types of Wasm execution. -- Find the right crate in substrate repo to find the executors, then look them up online. -- Argue which type of executor should be used for runtimes, and which for smart contracts. -- You have less than 30 minutes! - -Notes: - -We want students to discover `wasmi` and Wasmtime, and research their differences. - -So the key difference here is that the compilation of the code is unsafe because you can attack an -optimizing compiler. -You can input some code for compilation that just takes forever to compile -(compiler bombs). -There is no difference on safety in the actual execution apart from interpreters -being more simple and hence less likely to have bugs. - -So compilation can be safe. -But only if you can do it in linear time. -And that prevents most optimizations which makes the produced code slow. -And it is questionable and surely depend on the contract in question whether the compilation time can be recuperated if you need to compile it every time it is run. -When we have fuel metering we could port the code generation of Wasmtime to the runtime and cache the produced native code on-chain. -Cause with fuel metering we are immune against compiler bombs. - -Then we could have near native speed for contracts. - -Of course we could port the code generation of a linear time compiler to the runtime and have the same without fuel metering. -However, there is none except Wasmer. -And they were acquired by NEAR. -It was always a shady project but now I don't want to rely on it at all. -Everything except Wasmtime is a huge liability. - ---- - -## Additional Resources! ๐Ÿ˜‹ - -> Check speaker notes (click "s" ๐Ÿ˜‰) - -Notes: - -- More on Rust target spec: - - - https://rust-lang.github.io/rfcs/0131-target-specification.html - -- Lin Clark's awesome talks on WASI (not super relevant to our work though): - - - https://www.youtube.com/watch?v=fh9WXPu0hw8 - - https://www.youtube.com/watch?v=HktWin_LPf4 - -- `wasm-unknown` vs `wasm-wasi`: - - - https://users.rust-lang.org/t/wasm32-unknown-unknown-vs-wasm32-wasi/78325/5 - -- `extern "C"`: - - - https://doc.rust-lang.org/std/keyword.extern.html - - https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code - -- Chapter 11 of this book is a great read: https://nostarch.com/rust-rustaceans - -## Activity Hints (Post Lecture) - -``` -rustup target add wasm32-wasi -rustup target add wasm32-unknown-unknown - -cargo init --lib -apply stuff (`cdylib`, `#[no_mangle]`) - -cargo build --target wasm32-unknown-unknown --release -``` - -Install `wasmtime-cli`, maybe `cargo install wasmtime-cli`? Figure it out based on the `wasmtime-cli` -docs! - -``` -wasmtime ./target/wasm32-unknown-unknown/release/wasm-crate.wasm --invoke ... -``` - -DON'T USE `bindgen`! That's for compiling wasm to browser! - -A rust `lib` crate can be executed via `wasmtime`, a rust `bin` crate can be executed itself with -`cargo run`, but there are caveats. USE LIB CRATE for now. - -If you want to play with the de-compiled WAM file: - -``` -wasm-gc target/wasm32-unknown-unknown/release/wasm_crate.wasm out.wasm -wasm2wat out.wasm | grep export -``` - -Even with `wasi`, in order to create a file you need permission. - -Note that functions like `std::time::now()` and such are available in `wam32-unknown-unknown`, but -simply panic. The point is that you probably won't get a compile error, but it won't work either. - -the point of `f32` is to show that you we can use float, but float are un-deterministic, so YOU -SHOULD NOT USE THEM IN YOUR RUNTIME. - -Try and use `Vec<_>` or other types that are dynamically allocated. Recall that `wasm32-unknown-unknown` does not have an allocator! - -Further ideas: - -- make print work in wasm32-unknown-unknown using "host functions" (https://docs.wasmtime.dev/wasm-rust.html#importing-host-functionality). -- try and bring an external dependency in your crate. You will probably run into `feature = std`. diff --git a/syllabus/5-Substrate/99-DEP-Substrate_CLI_Slides.md b/syllabus/5-Substrate/99-DEP-Substrate_CLI_Slides.md deleted file mode 100644 index 9a1deb09f..000000000 --- a/syllabus/5-Substrate/99-DEP-Substrate_CLI_Slides.md +++ /dev/null @@ -1,747 +0,0 @@ ---- -title: (Deprecated)Substrate CLI -description: A brief look at the Substrate CLI. -duration: 1 hour ---- - -# Substrate CLI - ---- - -## Substrate CLI - -In this section, we will quickly go over some of the common CLI commands you should be familiar with when working with Substrate. - ---- - -## Build - -Least Time to Execute - -```sh -cargo check -``` - -```sh -cargo build -``` - -```sh -cargo build --release -``` - ---- - -## Build - -Which crate is it exactly being executed when I type `cargo run`? Where's the damn `fn main() -> {}`. - -```toml -[[bin]] -name = "substrate" -path = "bin/main.rs" -required-features = ["cli"] -``` - -- Thus, `cargo b --release -p node-cli` is slightly faster. -- Or `cargo b --release -p node-template`. - ---- - -## Testing Specific Packages - -From: `substrate/bin/node-template/runtime/Cargo.toml` - -```toml -[package] -name = "node-template-runtime" -``` - -```sh -cargo test -p node-template-runtime -``` - -This will run the tests just in the `node-template-runtime` library. - ---- - -## Wasm Builder Environment Variables - -Some useful environment variables from the Wasm builder: - -- `SKIP_WASM_BUILD` - Skips building any Wasm binary. This is useful when only native should be recompiled. -- `FORCE_WASM_BUILD` - Can be set to force a Wasm build. - -For example, an even faster way to build just the client: - -```sh -SKIP_WASM_BUILD=1 cargo build --release -``` - ---- - -## Substrate Master Doesn't Compile? - -Probably just need to: - -```sh -rustup update -``` - -Generally, we ensure that Substrate master always works with the latest Rust compiler. - ---- - -## CLI Commands - -```sh -./target/release/substrate --help -``` - -````sh -Commands: - -inspect, benchmark, try-runtime, key, verify, vanity, sign, -build-spec, check-block, export-blocks, export-state, -import-blocks, purge-chain, revert, chain-info, help - -Options: - -...LOTs of these!!! -``` - ---- - -## Chain Specification - -- A JSON object which uniquely defines a blockchain. -- Contains various metadata and the genesis state. - ---- - -## Opinionated FRAME based JSON - -```sh -./target/release/substrate build-spec --chain=dev > spec.json -```` - -```json -{ - "name": "Development", - "id": "dev", - "chainType": "Development", - "bootNodes": ["/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWNsFq6B97vcYvjtx9RTQrptYqVFN8Nvtg7Nr2fD3jBUMz"], - "telemetryEndpoints": null, - "protocolId": null, - "properties": null, - "forkBlocks": null, - "badBlocks": null, - "lightSyncState": null, - "codeSubstitutes": {}, - "genesis": { - "runtime": { - "system": { - "code": "" - }, - "babe": { - "authorities": [], - "epochConfig": { - "c": [1, 4], - "allowed_slots": "PrimaryAndSecondaryPlainSlots" - } - }, - "indices": { - "indices": [] - }, - "balances": { - "balances": [ - ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 1000000000000000000000], - ["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", 1000000000000000000000], - ["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", 1000000000000000000000], - ["5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy", 1000000000000000000000], - ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", 1000000000000000000000], - ["5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", 1000000000000000000000], - ["5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", 1000000000000000000000], - ["5HpG9w8EBLe5XCrbczpwq5TSXvedjrBGCwqxK1iQ7qUsSWFc", 1000000000000000000000], - ["5Ck5SLSHYac6WFt5UZRSsdJjwmpSZq85fd5TRNAdZQVzEAPT", 1000000000000000000000], - ["5HKPmK9GYtE1PSLsS1qiYU9xQ9Si1NcEhdeCq9sw5bqu4ns8", 1000000000000000000000], - ["5FCfAonRZgTFrTd9HREEyeJjDpT397KMzizE6T3DvebLFE7n", 1000000000000000000000], - ["5CRmqmsiNFExV6VbdmPJViVxrWmkaXXvBrSX8oqBT8R9vmWk", 1000000000000000000000] - ] - }, - "transactionPayment": null, - "staking": { - "historyDepth": 84, - "validatorCount": 1, - "minimumValidatorCount": 1, - "invulnerables": ["5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY"], - "forceEra": "NotForcing", - "slashRewardFraction": 100000000, - "canceledPayout": 0, - "stakers": [ - [ - "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 1000000000000000000, - "Validator" - ] - ], - "minNominatorBond": 0, - "minValidatorBond": 0, - "maxValidatorCount": null, - "maxNominatorCount": null - }, - "session": { - "keys": [ - [ - "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", - "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", - { - "grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu", - "babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "im_online": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "authority_discovery": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" - } - ] - ] - }, - "democracy": { - "phantom": null - }, - "council": { - "phantom": null, - "members": [] - }, - "technicalCommittee": { - "phantom": null, - "members": [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy", - "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" - ] - }, - "elections": { - "members": [ - ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 1000000000000000000], - ["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", 1000000000000000000], - ["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", 1000000000000000000], - ["5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy", 1000000000000000000], - ["5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", 1000000000000000000], - ["5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", 1000000000000000000] - ] - }, - "technicalMembership": { - "members": [], - "phantom": null - }, - "grandpa": { - "authorities": [] - }, - "treasury": null, - "sudo": { - "key": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" - }, - "imOnline": { - "keys": [] - }, - "authorityDiscovery": { - "keys": [] - }, - "society": { - "pot": 0, - "members": [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy", - "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw", - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" - ], - "maxMembers": 999 - }, - "vesting": { - "vesting": [] - }, - "assets": { - "assets": [], - "metadata": [], - "accounts": [] - }, - "gilt": null, - "transactionStorage": { - "byteFee": 10, - "entryFee": 1000, - "storagePeriod": 100800 - }, - "allianceMotion": { - "phantom": null, - "members": [] - }, - "alliance": { - "founders": [], - "fellows": [], - "allies": [], - "phantom": null - }, - "nominationPools": { - "minJoinBond": 100000000000000, - "minCreateBond": 1000000000000000, - "maxPools": 16, - "maxMembersPerPool": 32, - "maxMembers": 512 - } - } - } -} -``` - -Notes: - -We will learn how specifically keys are generated in the FRAME section. - -But you can use tools like: - -https://github.com/shawntabrizi/substrate-known-keys/blob/master/known-keys.json - -Some simple ones: - -```js -// The Wasm Blob. -// Just hex representation of UTF-8 String. -":code" = 0x3a636f6465 - -// System Accounts -0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9 - -// Block Number -0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac -``` - ---- - -## Raw Chain Spec - -Totally un-opinionated. Just raw key-value pairs. - -```sh -./target/release/substrate build-spec --chain=dev --raw > spec.json -``` - -```json -{ - "name": "Development", - "id": "dev", - "chainType": "Development", - "bootNodes": ["/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWNsFq6B97vcYvjtx9RTQrptYqVFN8Nvtg7Nr2fD3jBUMz"], - "telemetryEndpoints": null, - "protocolId": null, - "properties": null, - "forkBlocks": null, - "badBlocks": null, - "lightSyncState": null, - "codeSubstitutes": {}, - "genesis": { - "raw": { - "top": { - "0x074b65e262fcd5bd9c785caf7f42e00a4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", - "0x0e7b504e5df47062be129a8958a7a1271689c014e0a5b9a8ca8aafdff753c41c": "0xe8030000000000000000000000000000", - "LOTS more hex keys": "0x0000" - }, - "childrenDefault": {} - } - } -} -``` - ---- - -## Loading Chain Spec - -```sh -./target/release/substrate --chain=spec.json -``` - ---- - -## Loading Chain Spec - -Some specs are included in the client binary: - -From: `substrate/bin/node/cli/src/command.rs` - -``` - --chain - Specify the chain specification. - - It can be one of the predefined ones (dev, local, or staging) .. -``` - ---- - -## Development Node - -```sh ---dev - Specify the development chain. - - This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and - `--tmp` flags, unless explicitly overridden. -``` - -The most common way to quickly launch a test network: - -```sh -./target/release/substrate --dev -``` - ---- - -## `--dev` Implications - -- `--chain=dev`: Use the dev chain specification. -- `--force-authoring`: Make blocks even if you are offline. (when you are not connected to any peers) -- `--rpc-cors=all`: Allow any browser Origin to access the HTTP & WS RPC servers. -- `--alice`: Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore. -- `--tmp`: Run a temporary node where blockchain data is stored in a temporary directory. - ---- - -## Development Accounts - -- `--alice` -- `--bob` -- `--charlie` -- `--dave` -- `--eve` -- `--ferdie` - -On a `--dev` node, these accounts are configured as validators and also given funds. - -```sh ---validator - Enable validator mode. - - The node will be started with the authority role and actively participate in any - consensus task that it can (e.g. depending on availability of local keys). -``` - ---- - -## Control Where Data is Stored - -```sh -./target/release/substrate --dev --base-path=./tmp/ -``` - -This will result in: - -``` -tmp/ -โ”œโ”€ chains/ -โ”‚ โ”œโ”€ dev/ -โ”‚ โ”‚ โ”œโ”€ db/ -โ”‚ โ”‚ โ”œโ”€ network/ -โ”‚ โ”‚ โ”œโ”€ keystore/ -``` - ---- - -## Purging Chain Data - -Without specifying a `--base-path`, you may not know where the blockchain data is being stored. - -`purge-chain` sub-command can help with that. - -```sh -./target/release/substrate purge-chain --dev - -Are you sure to remove "/Users/shawntabrizi/Library/Application Support/substrate/chains/dev/db/full"? [y/N]: - -y - -"/Users/shawntabrizi/Library/Application Support/substrate/chains/dev/db/full" removed. -``` - ---- - -## Database Stuff - -```sh ---database - Select database backend to use - - [possible values: rocksdb, paritydb, paritydb-experimental, auto] - ---db-cache - Limit the memory the database cache can use -``` - ---- - -## Execute as Native - -```sh ---execution - The execution strategy that should be used by all execution contexts - - [possible values: native, wasm, both, native-else-wasm] -``` - -```sh -./target/release/substrate --dev --execution=native -``` - ---- - -## Type of Wasm Execution - -``` ---wasm-execution - Method for executing Wasm runtime code - - [default: compiled] - - Possible values: - - interpreted-i-know-what-i-do: Uses an interpreter - - compiled: Uses a compiled runtime -``` - ---- - -## Block Pruning - -- You can control how many finalizes blocks to keep and the underlying block state. -- Note that changing this usually is not allowed. - -``` ---state-pruning - Specify the state pruning mode. - - Possible values: - - archive: - - 'archive-canonical' - - number - [default: 256] - ---blocks-pruning - Specify the blocks pruning mode. - Possible values: - - 'archive' - - 'archive-canonical' - - number - [default: archive-canonical] -``` - ---- - -## RPC and WS - -You probably want to control RPC and WS ports if you are launching multiple nodes on the same machine. - -```sh ---rpc-port - Specify HTTP RPC server TCP port - Default is 9934 - ---ws-port - Specify WebSockets RPC server TCP port - Default is 9944 -``` - -Bandwidth configurations: - -```sh ---rpc-max-request-size - Set the the maximum RPC request payload size for both HTTP and WS in megabytes. Default is 15MiB - ---rpc-max-response-size - Set the the maximum RPC response payload size for both HTTP and WS in megabytes. Default is 15MiB -``` - ---- - -## "Unsafe" RPC and WS Stuff - -```sh ---rpc-methods - RPC methods to expose. - - - `unsafe`: Exposes every RPC method. - - `safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods. - - `auto`: Acts as `safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is - passed, otherwise acts as `unsafe`. - - [default: auto] - [possible values: auto, safe, unsafe] - ---rpc-external - Listen to all RPC interfaces. - - Default is local. Notes: not all RPC methods are safe to be exposed publicly. Use an RPC - proxy server to filter out dangerous methods. More details: - . Use - `--unsafe-rpc-external` to suppress the warning if you understand the risks. - ---ws-external - Listen to all Websocket interfaces. - - Default is local. Notes: not all RPC methods are safe to be exposed publicly. Use an RPC - proxy server to filter out dangerous methods. More details: - . Use - `--unsafe-ws-external` to suppress the warning if you understand the risks. -``` - ---- - -## Enabling Logs - -```rust --l, --log ... - Sets a custom logging filter. Syntax is =, e.g. -lsync=debug. - - Log levels (least to most verbose) are error, warn, info, debug, and trace. By default, - all targets log `info`. The global log level can be set with -l. -``` - -Same as `RUST_LOG` environment variable. - -All `runtime` prefixed logs: - -```sh -RUST_LOG=runtime=debug ./target/release/substrate --dev -./target/release/substrate --dev --log=runtime=debug -``` - -All `runtime::staking` prefixed logs: - -```sh -./target/release/substrate --dev --log=runtime::staking=debug -``` - -Notes: - -Just an example of how you can add logs to your code: - -```rust -pub(crate) const LOG_TARGET: &str = "runtime::staking"; - -// syntactic sugar for logging. -#[macro_export] -macro_rules! log { - ($level:tt, $patter:expr $(, $values:expr)* $(,)?) => { - log::$level!( - target: crate::LOG_TARGET, - concat!("[{:?}] ๐Ÿ’ธ ", $patter), >::block_number() $(, $values)* - ) - }; -} -``` - -Then to log: - -```rust -log!(warn, "genesis election provider failed due to {:?}", e); -``` - ---- - -## Sync Flags - -You can control how you sync your node. - -```sh ---sync - Blockchain syncing mode. - - - `full`: Download and validate full blockchain history. - - `fast`: Download blocks and the latest state only. - - `fast-unsafe`: Same as `fast`, but skip downloading state proofs. - - `warp`: Download the latest state and proof. - - [default: full] - [possible values: full, fast, fast-unsafe, warp] -``` - ---- - -## Transaction Pool Size - -```sh ---pool-kbytes - Maximum number of kilobytes of all transactions stored in the pool - - [default: 20480] - ---pool-limit - Maximum number of transactions in the transaction pool - - [default: 8192] -``` - ---- - -## Sub Commands - -```sh -SUBCOMMANDS: - benchmark - Sub-commands concerned with benchmarking. The pallet benchmarking moved to the `pallet` - sub-command - build-spec - Build a chain specification - chain-info - Db meta columns information - check-block - Validate blocks - export-blocks - Export blocks - export-state - Export the state of a given block into a chain spec - help - Print this message or the help of the given subcommand(s) - import-blocks - Import blocks - inspect - Decode given block or extrinsic using current native runtime. - key - Key management cli utilities - purge-chain - Remove the whole chain - revert - Revert the chain to a previous state - sign - Sign a message, with a given (secret) key - try-runtime - Try some command against runtime state. N o t e: `try-runtime` feature must be enabled - vanity - Generate a seed that provides a vanity address - verify - Verify a signature for a message, provided on STDIN, with a given (public or secret) key -``` - ---- - -## Additional Resources! ๐Ÿ˜‹ - -> Check speaker notes (click "s" ๐Ÿ˜‰) - - - -Notes: - -Both Substrate and IPFS use LibP2P. - -It is pretty easy to turn a Substrate node into a IPFS client. - -```sh ---ipfs-server - Join the IPFS network and serve transactions over bitswap protocol -``` - -Additional ideas: - -1. Sync a new polkadot network with fast and warp -1. Then check yourself out in telemetry. From d4e7f22b5f7cedb4f9b6f83dadac7def60d41260 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 13 Aug 2023 22:38:35 -0700 Subject: [PATCH 2/3] add a few more further ideas for next rounds --- syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md b/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md index 81416dd64..5b6c8714b 100644 --- a/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md +++ b/syllabus/5-Substrate/9-Substrate-FRAME-Tips-Tricks-Slides.md @@ -1155,3 +1155,5 @@ Notes: - Cargo format - SignedExtension should technically be part of the substrate module. Integrate it in the assignment, perhaps. +- A section about `XXXNoBound` traits. +- A section about reading your compiler errors top to bottom, especially with an example in FRAME. From 94ded7c7e4f967f943d5c5fa10b68048710488c8 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 13 Aug 2023 22:39:25 -0700 Subject: [PATCH 3/3] remove bad example --- syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md b/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md index a29e3bf1f..051025d05 100644 --- a/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md +++ b/syllabus/5-Substrate/1-Intro-to-Substrate_Slides.md @@ -593,8 +593,6 @@ bug in it, everyone is affected. ## Consensus <> Runtime ๐Ÿค” - Yes, consensus is not a core part of a blockchain runtime. Why? -- Not often customized. - - Not part of your STF! - The consensus protocol is to your runtime what HTTP is to Facebook.