Skip to content

Commit

Permalink
Kian singapore Day 0 (#1038)
Browse files Browse the repository at this point in the history
* Fix a few things

* rename

* more updates from kian

* final touches

* add meme

* lint
  • Loading branch information
kianenigma authored Jun 3, 2024
1 parent 16cd7dd commit 97eb0d1
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 186 deletions.
Binary file added assets/img/5-Substrate/endian-egg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/5-Substrate/endian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/5-Substrate/lib-bincode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/5-Substrate/lib-scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions syllabus/6-Polkadot-SDK/Polkadot-SDK-slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ This lecture is about learning two things:

There will be amazing modules going into further details of each. This will be very high level.

meta questions for ice breaker:

- how many ppl know substrate/frame already?
- how many ppl feel like they are comfortable with rust
- with rust generics, traits and associated types
- how many ppl know what polkadot-sdk is?
- how many ppl know jam already? do you have the question of why are we still leaning all of this?

---

## Learning Outcomes
Expand Down Expand Up @@ -253,6 +261,20 @@ About Polkadot SDK

---

## Schedule

(tentative)

- 🤓 _Substrate_: Tuesday -> Thursday
- More theory, 2 ungraded activities
- 🧑‍💻 _FRAME_: Thursday -> Thursday
- Main graded assignment
- Mix lecture and live-coding
- 🚀 _XCM_: Friday + Saturday
- Hands-on

---

## Additional Resources! 😋

> Check speaker notes (click "s" 😉)
Expand Down
72 changes: 55 additions & 17 deletions syllabus/6-Polkadot-SDK/Substrate/1-Intro-to-Substrate-slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ _The way to make a protocol truly upgradeable is to design a (fixed) meta-protoc

---

## Core Substrate Philosophies

In one figure

<img style="width: 1200px" style="width: 1400px;" src="./img/centuries.png" />

- Don't care about a timeless system -> Substrate is not the right tool
- Don't care about a truly resilient platform -> Polkadot is not the right platform

---

## Positive Consequences of _Wasm_ Runtime 🔥

---v
Expand Down Expand Up @@ -574,8 +585,11 @@ https://forum.polkadot.network/t/announcing-polkavm-a-new-risc-v-based-vm-for-sm

### Example: SCALE vs JSON

<div class="flex-container text-smaller">
<div class="left">

```rust
use parity_scale_codec::{Encode};
use parity_scale_codec::{ Encode };

#[derive(Encode)]
struct Example {
Expand All @@ -591,18 +605,20 @@ fn main() {
optional: Some(69),
};
println!("{:?}", my_struct.encode());
// [42, 1, 1, 69, 0, 0, 0]
println!("{:?}", my_struct.encode().len());
// 7
}
```

---v
```sh
[42, 1, 1, 69, 0, 0, 0]
7
```

### Example: SCALE vs JSON
</div>
<div class="right" style="margin-left: 10px;">

```rust
use serde::{Serialize};
use serde::{ Serialize };

#[derive(Serialize)]
struct Example {
Expand All @@ -618,12 +634,18 @@ fn main() {
optional: Some(69),
};
println!("{:?}", serde_json::to_string(&my_struct).unwrap());
// "{\"number\":42,\"is_cool\":true,\"optional\":69}"
println!("{:?}", serde_json::to_string(&my_struct).unwrap().len());
// 42
}
```

```sh
"{\"number\":42,\"is_cool\":true,\"optional\":69}"
42
```

</div>
</div>

---

## Substrate and Smart Contracts
Expand Down Expand Up @@ -769,7 +791,27 @@ Another good analogy: Node is the FPGA, and FRAME/Wasm is the VHDL.

---

## Substrate Architecture
## Lecture Recap - Part 1

- Substrate's design stems from 3 core principles:
- **Rust**, **Generic Design**, **Upgradeability/Governance**
- **Runtime <> Node** Architecture
- Positive and negative consequences of Wasm
- Substrate next to Polkadot and other chains.
- Development Options
- Substrate and Smart Contracts.

---v

## Lecture Recap - Part 1

- Questions?

<img src="../../../assets/img/5-Substrate/dev-4-1-substrate.svg" />

---

## Part 2: Substrate Architecture

So far we covered high level facts about Substrate. Now let's dive deeper into its architecture using the Runtime/STF.

Expand Down Expand Up @@ -940,19 +982,15 @@ state is sometimes called "storage" asd well.

---

## Lecture Recap
## Lecture Recap - Part 2

- Substrate's design stems from 3 core principles:
- **Rust**, **Generic Design**, **Upgradeability/Governance**
- Positive and negative consequences of Wasm
- Substrate next to Polkadot and other chains.
- Substrate and Smart Contracts.
- Node / Runtime architecture
- Full Substrate Architecture
- State Transition Deep Dive -> Forkless Upgrade
- Consensus / Database being in node.

---v

### Recap: Substrate Architecture
### Lecture Recap - Part 2

<img style="width: 1400px;" src="../../../assets/img/5-Substrate/dev-4-3-full.svg" />

Expand Down
121 changes: 60 additions & 61 deletions syllabus/6-Polkadot-SDK/Substrate/2-Wasm-Meta-Protocol-Slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,49 +365,6 @@ Note: make sure roots in the header match!

---

## Detour: Extrinsic

- Previous slides used the term "transactions" in a simplified way. Let's correct it.

---v

### Detour: Extrinsic

<diagram class="mermaid" center>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true }}}%%
flowchart TD
E(Extrinsic) ---> I(Inherent);
E --> T(Transaction)
T --> ST("Signed (aka. Transaction)")
T --> UT(Unsigned)
</diagram>

---v

### Detour: Extrinsic

- An Extrinsic is data that come from outside of the runtime.
- &shy;<!-- .element: class="fragment" -->Inherents are data that is put into the block by the block author, directly.
- &shy;<!-- .element: class="fragment" -->Yes, transactions are **a type of extrinsic**, but not all extrinsics are transactions.
- &shy;<!-- .element: class="fragment" -->So, why is it called _Transaction Pool_ and not _Extrinsic Pool_?

Notes:

extrinsics are just blobs of data which can be included in a block. inherents are types of extrinsic
which are crafted by the block builder itself in the production process. they are unsigned because
the assertion is that they are "inherently true" by virtue of getting past all validators.

notionally the origin can be said to be a plurality of validators. take for example the timestamp
set inherent. if the data were sufficiently incorrect (i.e. the wrong time), then the block would
not be accepted by enough validators and would not become canonicalised. so the "nobody" origin is
actually the tacit approval of the validators.

transactions are generally statements of opinion which are valuable to the chain to have included
(because fees are paid or some other good is done). the transaction pool filters out which of these
are indeed valuable and nodes share them.

---

## Example #3: Block Authoring

---v
Expand Down Expand Up @@ -692,6 +649,7 @@ time to ask any missing questions.
- look for `impl_runtime_apis! {...}` and `decl_runtime_apis! {...}` macro calls.
- Try and find the corresponding the node code calling a given api as well.
- Look for `#[runtime_interface]` macro, and try and find usage of the host functions!
- Look for `sp_io::storage`
- You have 15 minutes!

---v
Expand Down Expand Up @@ -830,6 +788,57 @@ sp_io::storage::root();

---

## Detour: Extrinsic

- Previous slides used the term "transactions" in a simplified way. Let's correct it.

---v

### Detour: Extrinsic

<diagram class="mermaid" center>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true }}}%%
flowchart TD
E(Extrinsic) ---> I(Inherent);
E --> T(Transaction)
T --> ST("Signed (aka. Transaction)")
T --> UT(Unsigned)
</diagram>

---v

### Detour: Extrinsic

- An Extrinsic is data that come from outside of the runtime.
- &shy;<!-- .element: class="fragment" -->Inherents are data that is put into the block by the block author, directly.
- &shy;<!-- .element: class="fragment" -->Yes, transactions are **a type of extrinsic**, but not all extrinsics are transactions.
- &shy;<!-- .element: class="fragment" -->So, why is it called _Transaction Pool_ and not _Extrinsic Pool_?

Notes:

extrinsics are just blobs of data which can be included in a block. inherents are types of extrinsic
which are crafted by the block builder itself in the production process. they are unsigned because
the assertion is that they are "inherently true" by virtue of getting past all validators.

notionally the origin can be said to be a plurality of validators. take for example the timestamp
set inherent. if the data were sufficiently incorrect (i.e. the wrong time), then the block would
not be accepted by enough validators and would not become canonicalised. so the "nobody" origin is
actually the tacit approval of the validators.

transactions are generally statements of opinion which are valuable to the chain to have included
(because fees are paid or some other good is done). the transaction pool filters out which of these
are indeed valuable and nodes share them.

---v

### Detour: Extrinsic

More change is coming; advance topic; not needed, but FYI:

https://github.com/paritytech/polkadot-sdk/issues/2415

---

## Considerations: Speed

- (new) Wasmtime is near-native 🏎️.
Expand Down Expand Up @@ -925,15 +934,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
## Considerations: Panic

- What if any of the runtime calls, like `execute_block` or `apply_extrinsic` panics 😱?
- To answer this, let's take a step back toward validator economics.

---v

### Considerations: Panic

- All validators/nodes want to avoid wasting their time.
- While building a block, sometimes it is unavoidable (when?). <!-- .element: class="fragment" -->
- While importing a block, nodes will not tolerate this. <!-- .element: class="fragment" -->

---v

Expand Down Expand Up @@ -963,9 +963,9 @@ workshop idea for FRAME: find all instances where the runtime actually correctly
### Considerations: Panic

- Panic in a user-callable code path?
- 🤬 annoy/DOS your poor validators <!-- .element: class="fragment" -->
- Panic on "automatic" part of your blockchain like "initialize_block"? <!-- .element: class="fragment" -->
- 😱 Stuck forever <!-- .element: class="fragment" -->
- 🤬 annoy/DOS your poor validators
- Panic on "automatic" part of your blockchain like "initialize_block"?
- 😱 Stuck forever

---v

Expand Down Expand Up @@ -1229,7 +1229,7 @@ panic if any transaction fails to apply.
- Considerations:

- Speed
- Native Execution and Versioning
- Versioning
- Panics
- Altering Host Functions

Expand All @@ -1247,12 +1247,10 @@ panic if any transaction fails to apply.

Notes:

TODO: update links, most are outdated.

- Some very recent change the the block building API set: https://github.com/paritytech/substrate/pull/14414 / https://github.com/paritytech/polkadot-sdk/pull/1781

- New runtime API for building genesis config: https://github.com/paritytech/substrate/pull/14310 / https://github.com/paritytech/polkadot-sdk/pull/1492

- New changes to `initialize_block` to support MBM: https://polkadot-fellows.github.io/RFCs/approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html

- New metadata version, including types for the runtime API: https://github.com/paritytech/substrate/issues/12939

- Recent development on api versioning: https://github.com/paritytech/substrate/issues/13138
Expand All @@ -1272,7 +1270,8 @@ SomeExternalities.execute_with(|| {

HK:

- The panic section is so important and it comes at the end, therefore hard to understand. Simplify it and deliver it sooner.
- The panic section is so important and it comes at the end, therefore hard to understand. Simplify
it and deliver it sooner.
- More examples of unsigned tx

---
Expand Down
Loading

0 comments on commit 97eb0d1

Please sign in to comment.