<style>
body, h1, h2, h3, h4 {
font-weight 200;
}
strong, b {
font-weight: normal;
color: #FF1864;
}
ul {
list-style: "... ";
}
ul li {
}
</style>
# Substrate 101
<!-- Put the link to this slide here so people can follow -->
1. slides: tiny.cc/haski-sl
2. download node: tiny.cc/haski-dl
4. install substrate
`curl https://getsubstrate.io -sSf | bash -s -- --fast` <!-- .element: style="font-size: 0.5em" -->
----
This is an interactive workshop. Here is what we will do today:
1. short intro to substrate
2. setup a substrate-based blockchain locally
4. live code a new runtime
6. **hot upgrade the running blockchain**
7. conclusion
---
![](https://s3.amazonaws.com/media-p.slid.es/uploads/351278/images/5425886/logo-parity-substrate-4.svg)<!-- .element: style="border: 0; box-shadow: unset"-->
----
## Substrate ...
- is a generic **Blockchain development Framework**
- written in Rust :heart: & WASM
- grew out of Polkadot development framework
----
### How geneirc is substrate?
<!-- .slide: data-background-image="https://s3.amazonaws.com/media-p.slid.es/uploads/351278/images/5446293/pen.png" data-background-position="bottom right" data-background-size="contain" -->
- ## Abstract block format <!-- .element: class="fragment" data-fragment-index="1" style="font-size: 0.6em;"-->
- ## Crypto Database(s) agnostict <!-- .element: class="fragment" data-fragment-index="2" style="font-size: 0.6em; padding-bottom:0; margin-bottom: 0" -->
Base-16 modified Merkle trie (aka Ethereum); Binary Merkle trie (a la Shasper) (planned); Dynamic create, modify, delete so you can<!-- .element: class="fragment" data-fragment-index="2" style="margin-top: 0; font-size: 0.35em; max-width: 65%" --> **roll your own**<!-- .element: class="fragment" data-fragment-index="2" -->
- ## Pluggable Consensus Engine<!-- .element: class="fragment" data-fragment-index="3" style="font-size: 0.6em; padding-bottom:0; margin-bottom: 0" -->
AURA (probabilistic finality, constant blocktime); BABE (probabilistic finality, constant blocktime); GRANDPA (progressive, adaptive finality); configurable PoW (e.g., Ethash); Parachain (PoV, Polkadot consensus) (WIP); Ouroboros (live, probabilistic finality) (planned); Rhododendron (PBFT, instant finality) (planned) or<!-- .element: class="fragment" data-fragment-index="3" style="margin-top: 0; font-size: 0.35em; max-width: 55%" --> **roll your own**<!-- .element: class="fragment" data-fragment-index="3" -->
- ## Extensible networking, CLI, RPC <!-- .element: class="fragment" data-fragment-index="4" style="font-size: 0.6em;"-->
- ## Wasm "execute_block" function <!-- .element: class="fragment" data-fragment-index="5" style="font-size: 0.6em;"-->
----
<!-- .slide: data-background-image="https://s3.amazonaws.com/media-p.slid.es/uploads/351278/images/6324317/IPFSCamp_2019_Lightning_Talk___Changing_the_record__Using_substrate_to_add_a_custom_blockchain_to_your_IPFS_dweb_app__2_.svg" data-background-position="bottom right" data-background-size="contain" -->
## Chain-Specific Runtime <!-- .element: class="fragment" data-fragment-index="2" style="font-size:0.75em; text-transform: uppercase; text-align: right; font-weight: 300; max-width: 30%; "-->
stored and upgradable as WASM blob on-chain<!-- .element: class="fragment" data-fragment-index="2" style="font-size:0.3em; text-align: right; font-weight: 300; max-width: 30%; "-->
## Client Infrastructure <!-- .element: class="fragment" data-fragment-index="1" style="font-size:0.75em; text-transform: uppercase; text-align: right; font-weight: 300; max-width: 30%; margin-top: 20%"-->
everything every blockchain needs to run <!-- .element: class="fragment" data-fragment-index="1" style="font-size:0.3em; max-width: 30%; text-align: right"-->
---
# Let's play with substrate
hope you all have downloaded tiny.cc/haski-dl by now
----
## What we will be doing
1. start the node
1. connect the nodes locally
1. explore the local chain
----
### Start your node
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
start your node: `haski --chain local`
```
2019-10-11 11:28:24 Substrate HAckathon Starter Kit
2019-10-11 11:28:24 version 2.0.0-4927510-x86_64-linux-gnu
2019-10-11 11:28:24 by Anonymous, 2017, 2018
2019-10-11 11:28:24 Chain specification: Local Testnet
2019-10-11 11:28:24 Node name: irritating-beetle-6202
2019-10-11 11:28:24 Roles: AUTHORITY
2019-10-11 11:28:25 Highest known block at #62
2019-10-11 11:28:25 Using default protocol ID "sup" because none is configured in the chain specs
2019-10-11 11:28:25 Local node identity is: QmUN677u2W...
```
----
### Sync nodes
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
It should find our node via mDNS and sync:
```
2019-10-11 11:32:06 Imported #78 (0x92d3…97aa)
2019-10-11 11:32:07 Idle (1 peers), best: #78 (0x92d3…97aa), finalized #78 (0x92d3…97aa), ⬇ 5.3kiB/s ⬆ 0.6kiB/s
2019-10-11 11:32:12 Imported #79 (0xcdf1…2f53)
2019-10-11 11:32:12 Idle (1 peers), best: #79 (0xcdf1…2f53), finalized #78 (0x92d3…97aa), ⬇ 0.4kiB/s ⬆ 0.1kiB/s
2019-10-11 11:32:17 Idle (1 peers), best: #79 (0xcdf1…2f53), finalized #79 (0xcdf1…2f53), ⬇ 0.6kiB/s ⬆ 0.2kiB/s
2019-10-11 11:32:18 Imported #80 (0xc53a…81e6)
```
If it doesn't find us, try connecting to us directly:
`haski --chain local --bootnodes /ip4/159.65.127.121/tcp/30333/p2p/QmXbTdGCHkfWvzrgK5h7ce9kc2Uj9dSjRyYkyZQxLYYynz` <!-- .element: style="font-size: 0.5em" -->
----
### Connect UI to our chain
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
1. Go to polkadot.js.org/apps
2. In `Settings` switch `remote endpoint` to `localhost` & click `Save & Reload`
![Polkadot JS Settings switch](https://i.imgur.com/jvEJ3na.png)
----
### Explore our local chain
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
![](https://i.imgur.com/wQ94boa.png)
----
### Accounts on local chain
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
![](https://i.imgur.com/WNVTUI6.png)
----
### Create an Account
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
Click `Add Account` and create a new account:
![](https://i.imgur.com/DM6ENC0.png)
----
### Baby's first interaction
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
Go to `Extrinsics`, select your new Account and `haski`'s `faucet`
![](https://i.imgur.com/Q4jeawy.png)
----
### Baby's first interaction
download: <!-- .element: style="font-size: 0.5em" --> tiny.cc/haski-dl
then `Submit Transaction`, enter the password and `sign & submit`
![](https://i.imgur.com/8LRc9KK.png)
----
### Yay, we got some moneys
![](https://i.imgur.com/nfgvW32.png)
----
### So what else can we do?
![](https://i.imgur.com/McOoBvi.png)
----
### simplistic Hackathon team "management"
- you can `createTeam`, using a byte-code ID (e.g. `0x1234`)
- you can `joinTeam`, using the same code - if the team exists
- you can `leaveTeam`, if you are in a team
let's [look at the code](https://github.com/gnunicorn/haski/blob/5fafa465c3dda8011948d974aa078f5e4b880ec4/runtime/src/haski.rs#L65-L109)!
---
## Time to build a new feature :muscle:
_time for some live coding_
.. err copy-pasting (we don't have the time) <!-- .element: style="font-size: 0.5em" -->
----
### Let's add projects
A new storage entry, mapping Projects to the Teams:
```rust
Projects get(projects): map ProjectId => TeamId;
```
----
### And methods to manage them:
```rust
fn add_project(origin, team: TeamId, project: ProjectId) {
// ... snip
}
fn drop_project(origin, project: ProjectId){
// ... snip
}
```
----
### And update the spec version!
```diff
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -97,7 +97,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("haski"),
impl_name: create_runtime_str!("haski"),
authoring_version: 3,
- spec_version: 4,
+ spec_version: 5,
impl_version: 4,
apis: RUNTIME_API_VERSIONS,
};
```
[Full diff on feat-projects branch](https://github.com/gnunicorn/haski/compare/master...gnunicorn:feat-projects).
----
### Now let's hot upgrade:
1. `cargo build --release`
2. on chain go to: Sudo (as `Alice`) -> `system` -> `set_code`
3. click on :file_folder: icon, upload file
`target/release/wbuild/haski-runtime/haski_runtime.compact.wasm`
4. submit
![](https://i.imgur.com/K4KrWXt.png)
----
5. reload UI & check the Extrinsics -> haski
## :100: :muscle: :tada:
![](https://i.imgur.com/R7GN5nG.png)
---
but wait
## What just happened?
----
## Recap
1. we changed the <!-- .element: class="fragment" data-fragment-index="1" --> **Runtime** <!-- .element: class="fragment" data-fragment-index="2" -->
2. compiled the runtime to <!-- .element: class="fragment" data-fragment-index="3" --> **WASM** <!-- .element: class="fragment" data-fragment-index="4" -->
3. uploaded the wasm block <!-- .element: class="fragment" data-fragment-index="5" --> **on-chain** <!-- .element: class="fragment" data-fragment-index="6" -->
----
## What Substrate does
1. on every `execute_block` check the `:code` key
- if it matches the local native version, run it natively <!-- .element: class="fragment" data-fragment-index="1" -->
- if not, fire up a _wasm runtime_ with the blob at `:code`, then call `execute_block(block)` on it <!-- .element: class="fragment" data-fragment-index="2" -->
**forkless upgrades** <!-- .element: class="fragment" data-fragment-index="3" --> (through on-chain governance) <!-- .element: class="fragment" data-fragment-index="3" style="font-size: 0.8em;" -->
---
<!-- .slide: data-background-image="https://s3.amazonaws.com/media-p.slid.es/uploads/351278/images/5445839/what_do_i_get_with_substrate.png" data-background-position="bottom right" data-background-size="contain" style="text-align: left; font-size:0.8em" -->
## What do I get with **Substrate**?
- **Hot-upgradable chain Runtime**
- Interchain connectivity via Polkadot <!-- .element: class="fragment" data-fragment-index="1" -->
- Hot-swappable, pluggable consensus <!-- .element: class="fragment" data-fragment-index="2" -->
- Light client <!-- .element: class="fragment" data-fragment-index="3" -->
- Chain synchronisation <!-- .element: class="fragment" data-fragment-index="4" -->
- Pub/Sub WebSocket JSON-RPC <!-- .element: class="fragment" data-fragment-index="5" -->
- Transaction queue <!-- .element: class="fragment" data-fragment-index="6" -->
- secure networking <!-- .element: class="fragment" data-fragment-index="7" -->
- JS implementation <!-- .element: class="fragment" data-fragment-index="8" -->
- Telemetry <!-- .element: class="fragment" data-fragment-index="9" -->
- optional SRML Modules for your chain <!-- .element: class="fragment" data-fragment-index="10" -->
----
## SRML Modules <!-- .element: style="margin-top: 50%;" -->
<!-- .slide: data-background-image="https://s3.amazonaws.com/media-p.slid.es/uploads/351278/images/5446682/modules.png" data-background-position="bottom center" data-background-size="contain" -->
---
### Get started today :rocket:
- [substrate.dev](https://substrate.dev)
- tiny.cc/haski-sl
```
git clone https://github.com/gnunicorn/haski
cd haski
cargo run --dev
````
Find us for questions, on telegram, twitter, riot, [devpost](https://devpost.com/software/substrate-helpdesk) or in person. <!-- .element: class="fragment" data-fragment-index="1" style="font-size: 0.5em;" -->
You can also check out [gather](https://devpost.com/software/gather-nv7304) - the project we are hacking on this weekend. <!-- .element: class="fragment" data-fragment-index="2" style="font-size: 0.5em;" -->
{"metaMigratedAt":"2023-06-15T00:29:01.691Z","metaMigratedFrom":"YAML","title":"Substrate 101 @ Diffusion Hackathon 2019","breaks":"true","description":"Corresponding slides (view in \"Slide Mode\").","slideOptions":"{\"transition\":\"slide\",\"theme\":\"white\"}","contributors":"[{\"id\":\"7c6aab33-6425-4708-b066-3fd2f68e020f\",\"add\":18155,\"del\":8577}]"}