1647619200
A UTXO chain implementation on Substrate, with two self-guided workshops. Original UXTO inspiration by Dmitriy Kashitsyn.
Substrate Version: 2.0.0-rc6
. For educational purposes only.
Installation: Setting up Rust & Substrate dependencies
UI Demo: Demo of UTXO implementation in a simple UI
Beginner Workshop: A self guided, 1 hour workshop that familiarizes you with Substrate.
Advanced Workshop: A self guided, 2 hour video tutorial, that teaches you how to build a UTXO blockchain from scratch.
Helpful Resources: Additional supporting documentation and references for troubleshooting.
curl https://sh.rustup.rs -sSf | sh
# On Windows, download and run rustup-init.exe
# from https://rustup.rs instead
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup update stable
Clone your copy of the workshop codebase
git clone https://github.com/substrate-developer-hub/utxo-workshop.git
In this UI demo, you will interact with the UTXO blockchain via the Polkadot UI.
The following example takes you through a scenario where:
cargo build --release
./target/release/utxo-workshop --dev --tmp
Compile and build a release node
Start a node. The --dev
flag will start a single mining node, and the --tmp
flag will start it in a new temporary directory.
In the console note the helper printouts. In particular, notice the default account Alice
already has 100 UTXO
within the genesis block.
Open Polkadot JS making sure the client is connected to your local node by going to Settings > General and selecting Local Node
in the remote node
dropdown.
Declare custom datatypes in PolkadotJS as the frontend cannot automatically detect this information. To do this, go to Settings > Developer tab and paste in the following JSON:
{
"Address": "AccountId",
"LookupSource": "AccountId",
"Value": "u128",
"TransactionInput": {
"outpoint": "Hash",
"sigscript": "H512"
},
"TransactionOutput": {
"value": "Value",
"pubkey": "Hash"
},
"Transaction": {
"inputs": "Vec<TransactionInput>",
"outputs": "Vec<TransactionOutput>"
},
"Difficulty": "U256",
"DifficultyAndTimestamp": {
"difficulty": "Difficulty",
"timestamp": "Moment"
},
"Public": "H256"
}
Confirm that Alice already has 100 UTXO at genesis. In Chain State
> Storage
, select utxo
. Input the hash 0x76584168d10a20084082ed80ec71e2a783abbb8dd6eb9d4893b089228498e9ff
. Click the +
notation to query blockchain state.
Notice that:
100
Spend Alice's UTXO, giving 50 to Bob. In the Extrinsics
tab, invoke the spend
function from the utxo
pallet, using Alice as the transaction sender. Use the following input parameters:
0x76584168d10a20084082ed80ec71e2a783abbb8dd6eb9d4893b089228498e9ff
0x6ceab99702c60b111c12c2867679c5555c00dcd4d6ab40efa01e3a65083bfb6c6f5c1ed3356d7141ec61894153b8ba7fb413bf1e990ed99ff6dee5da1b24fd83
50
0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48
Verify that your transaction succeeded. In Chain State
, look up the newly created UTXO hash: 0xdbc75ab8ee9b83dcbcea4695f9c42754d94e92c3c397d63b1bc627c2a2ef94e6
to verify that a new UTXO of 50, belonging to Bob, now exists! Also you can verify that Alice's original UTXO has been spent and no longer exists in UtxoStore.
Coming soon: A video walkthrough of the above demo.
Estimated time: 2 hours
In this workshop you will:
Your challenge is to fix the code such that:
utxo.rs
pass, ensuring secure transactionsworkshop
branch. The Master
branch has the solutions, so don't peek!git fetch origin workshop:workshop
git checkout workshop
cargo test -p utxo-runtime
.compiling utxo-runtime v2.0.0 (/Users/nicole/Desktop/utxo-workshop/runtime)
error[E0433]: failed to resolve: use of undeclared type or module `H512`
--> /Users/nicole/Desktop/utxo-workshop/runtime/src/utxo.rs:236:31
|
236 | input.sigscript = H512::zero();
| ^^^^ use of undeclared type or module `H512`
...
Your first task: fix all the compiler errors! Hint: Look for the TODO
comments in utxo.rs
to see where to fix errors.
Once your code compiles, it's now time to fix the 8
failing tests!
failures:
utxo::tests::attack_by_double_counting_input
utxo::tests::attack_by_double_generating_output
utxo::tests::attack_by_over_spending
utxo::tests::attack_by_overflowing_value
utxo::tests::attack_by_permanently_sinking_outputs
utxo::tests::attack_with_empty_transactions
utxo::tests::attack_with_invalid_signature
utxo::tests::test_simple_transaction
utxo.rs
, edit the logic in validate_transaction()
function to make all tests pass.running 8 tests
test utxo::tests::attack_by_overflowing_value ... ok
test utxo::tests::attack_by_double_counting_input ... ok
test utxo::tests::attack_by_double_generating_output ... ok
test utxo::tests::attack_by_over_spending ... ok
test utxo::tests::attack_with_empty_transactions ... ok
test utxo::tests::attack_with_invalid_signature ... ok
test utxo::tests::attack_by_permanently_sinking_outputs ... ok
test utxo::tests::test_simple_transaction ... ok
VIDEO TUTORIALS COMING SOON
Estimated time: 2 hours
In this workshop, you will implement this UTXO project from scratch using Substrate.
You will learn:
Checkout the startercode
branch to get the boilerplate for this workshop.
git fetch origin startercode:startercode
git checkout startercode
Author: substrate-developer-hub
Source Code: https://github.com/substrate-developer-hub/utxo-workshop
License: Unlicense License
1647619200
A UTXO chain implementation on Substrate, with two self-guided workshops. Original UXTO inspiration by Dmitriy Kashitsyn.
Substrate Version: 2.0.0-rc6
. For educational purposes only.
Installation: Setting up Rust & Substrate dependencies
UI Demo: Demo of UTXO implementation in a simple UI
Beginner Workshop: A self guided, 1 hour workshop that familiarizes you with Substrate.
Advanced Workshop: A self guided, 2 hour video tutorial, that teaches you how to build a UTXO blockchain from scratch.
Helpful Resources: Additional supporting documentation and references for troubleshooting.
curl https://sh.rustup.rs -sSf | sh
# On Windows, download and run rustup-init.exe
# from https://rustup.rs instead
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup update stable
Clone your copy of the workshop codebase
git clone https://github.com/substrate-developer-hub/utxo-workshop.git
In this UI demo, you will interact with the UTXO blockchain via the Polkadot UI.
The following example takes you through a scenario where:
cargo build --release
./target/release/utxo-workshop --dev --tmp
Compile and build a release node
Start a node. The --dev
flag will start a single mining node, and the --tmp
flag will start it in a new temporary directory.
In the console note the helper printouts. In particular, notice the default account Alice
already has 100 UTXO
within the genesis block.
Open Polkadot JS making sure the client is connected to your local node by going to Settings > General and selecting Local Node
in the remote node
dropdown.
Declare custom datatypes in PolkadotJS as the frontend cannot automatically detect this information. To do this, go to Settings > Developer tab and paste in the following JSON:
{
"Address": "AccountId",
"LookupSource": "AccountId",
"Value": "u128",
"TransactionInput": {
"outpoint": "Hash",
"sigscript": "H512"
},
"TransactionOutput": {
"value": "Value",
"pubkey": "Hash"
},
"Transaction": {
"inputs": "Vec<TransactionInput>",
"outputs": "Vec<TransactionOutput>"
},
"Difficulty": "U256",
"DifficultyAndTimestamp": {
"difficulty": "Difficulty",
"timestamp": "Moment"
},
"Public": "H256"
}
Confirm that Alice already has 100 UTXO at genesis. In Chain State
> Storage
, select utxo
. Input the hash 0x76584168d10a20084082ed80ec71e2a783abbb8dd6eb9d4893b089228498e9ff
. Click the +
notation to query blockchain state.
Notice that:
100
Spend Alice's UTXO, giving 50 to Bob. In the Extrinsics
tab, invoke the spend
function from the utxo
pallet, using Alice as the transaction sender. Use the following input parameters:
0x76584168d10a20084082ed80ec71e2a783abbb8dd6eb9d4893b089228498e9ff
0x6ceab99702c60b111c12c2867679c5555c00dcd4d6ab40efa01e3a65083bfb6c6f5c1ed3356d7141ec61894153b8ba7fb413bf1e990ed99ff6dee5da1b24fd83
50
0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48
Verify that your transaction succeeded. In Chain State
, look up the newly created UTXO hash: 0xdbc75ab8ee9b83dcbcea4695f9c42754d94e92c3c397d63b1bc627c2a2ef94e6
to verify that a new UTXO of 50, belonging to Bob, now exists! Also you can verify that Alice's original UTXO has been spent and no longer exists in UtxoStore.
Coming soon: A video walkthrough of the above demo.
Estimated time: 2 hours
In this workshop you will:
Your challenge is to fix the code such that:
utxo.rs
pass, ensuring secure transactionsworkshop
branch. The Master
branch has the solutions, so don't peek!git fetch origin workshop:workshop
git checkout workshop
cargo test -p utxo-runtime
.compiling utxo-runtime v2.0.0 (/Users/nicole/Desktop/utxo-workshop/runtime)
error[E0433]: failed to resolve: use of undeclared type or module `H512`
--> /Users/nicole/Desktop/utxo-workshop/runtime/src/utxo.rs:236:31
|
236 | input.sigscript = H512::zero();
| ^^^^ use of undeclared type or module `H512`
...
Your first task: fix all the compiler errors! Hint: Look for the TODO
comments in utxo.rs
to see where to fix errors.
Once your code compiles, it's now time to fix the 8
failing tests!
failures:
utxo::tests::attack_by_double_counting_input
utxo::tests::attack_by_double_generating_output
utxo::tests::attack_by_over_spending
utxo::tests::attack_by_overflowing_value
utxo::tests::attack_by_permanently_sinking_outputs
utxo::tests::attack_with_empty_transactions
utxo::tests::attack_with_invalid_signature
utxo::tests::test_simple_transaction
utxo.rs
, edit the logic in validate_transaction()
function to make all tests pass.running 8 tests
test utxo::tests::attack_by_overflowing_value ... ok
test utxo::tests::attack_by_double_counting_input ... ok
test utxo::tests::attack_by_double_generating_output ... ok
test utxo::tests::attack_by_over_spending ... ok
test utxo::tests::attack_with_empty_transactions ... ok
test utxo::tests::attack_with_invalid_signature ... ok
test utxo::tests::attack_by_permanently_sinking_outputs ... ok
test utxo::tests::test_simple_transaction ... ok
VIDEO TUTORIALS COMING SOON
Estimated time: 2 hours
In this workshop, you will implement this UTXO project from scratch using Substrate.
You will learn:
Checkout the startercode
branch to get the boilerplate for this workshop.
git fetch origin startercode:startercode
git checkout startercode
Author: substrate-developer-hub
Source Code: https://github.com/substrate-developer-hub/utxo-workshop
License: Unlicense License
1617355640
The Association of Data Scientists (AdaSci), a global professional body of data science and ML practitioners, is holding a full-day workshop on building games using reinforcement learning on Saturday, February 20.
Artificial intelligence systems are outperforming humans at many tasks, starting from driving cars, recognising images and objects, generating voices to imitating art, predicting weather, playing chess etc. AlphaGo, DOTA2, StarCraft II etc are a study in reinforcement learning.
Reinforcement learning enables the agent to learn and perform a task under uncertainty in a complex environment. The machine learning paradigm is currently applied to various fields like robotics, pattern recognition, personalised medical treatment, drug discovery, speech recognition, and more.
With an increase in the exciting applications of reinforcement learning across the industries, the demand for RL experts has soared. Taking the cue, the Association of Data Scientists, in collaboration with Analytics India Magazine, is bringing an extensive workshop on reinforcement learning aimed at developers and machine learning practitioners.
#ai workshops #deep reinforcement learning workshop #future of deep reinforcement learning #reinforcement learning #workshop on a saturday #workshop on deep reinforcement learning
1643578320
Blockchain Indexing Engine
Run alongside a substrate-backed chain to index all Blocks, State, and Extrinsic data into PostgreSQL.
The schema for the PostgreSQL database is described in the PDF File at the root of this directory.
Examples for how to use substrate-archive are in the examples/
directory
Extended requirements list found in the wiki
--pruning=archive
The CLI is an easier way to get started with substrate-archive. It provides a batteries-included binary, so that you don't have to write any rust code. All thats required is setting up a PostgreSQL DB, and modifying a config file. More information in the wiki
The node-template CLI (in /bin/node-template-archive) is provided as an example of implementing substrate-archive for your chain.
git clone https://github.com/paritytech/substrate-archive.git
# Set up the databases
source ./substrate-archive/scripts/up.sh # Run ./scripts/down.sh to drop the database
cd substrate-archive/bin/polkadot-archive/
# Start the normal polkadot node with `pruning` set to `archive`
polkadot --chain=polkadot --pruning=archive
# Start up the substrate-archive node. `chain` can be one of `polkadot`, `kusama`, or `westend`.
cargo run --release -- -c test_conf.toml --chain=polkadot
You can access the help dialog via cargo run --release -- --help
. Note that up
and down
scripts are meant for convenience and are not meant to be complete. Look in the wiki for more information about the database setup.
Contributors are welcome!
Read the Doc
You can build the documentation for this crate by running cargo doc
. More Docs here
too many open files
error.Because of the way a RocksDB Secondary Instance works, it requires that all the files of the primary instance remain open in the secondary instance. This could trigger the error on linux, but simply requires that you raise the max open files limit (ulimit
):
$ docker run --ulimit nofile=90000:90000 <image-tag>
ulimit -a 90000
/etc/security/limits.conf
# /etc/security/limits.conf
* hard nofile 4096
* soft nofile 1024
some_usr hard nofile 90000
some_usr soft nofile 90000
insipx hard nofile 90000
insipx soft nofile 90000
root hard nofile 90000
root soft nofile 90000
For macOS and Linux, a warning message will be raised on the startup when there is a low fd sources limit in the current system, but Windows won't have such a low fd limit warning.
You can contact us at:
# /etc/security/limits.conf
* hard nofile 4096
* soft nofile 1024
some_usr hard nofile 90000
some_usr soft nofile 90000
insipx hard nofile 90000
insipx soft nofile 90000
root hard nofile 90000
root soft nofile 90000
Download Details:
Author: paritytech
Source Code: https://github.com/paritytech/substrate-archive
License: GPL-3.0 License
1593103980
Parity’s Joe Petrowski and Shawn Tabrizi give an introductory code walkthrough for the Substrate executive module, a Rust module for executing blocks in Substrate-based blockchains.
#substrate #rust module #substrate
1647568800
A collaborative workshop to learn how to use Substrate
Setting Up The Bootnode
This workshop depends on two bootnodes running somewhere publicly accessible. In practice this will usually be two nodes on a single cloud vps such as Digital Ocean or Google Cloud. This document guides the workshop host through the process of setting up this configuration.
Create a new VPS starting with Ubuntu 18.04 with SSH permissions. Many of these commands need to be run as root, so it is convenient to start a persistent sudo session with sudo -i
.
We will use Nginx as a reverse proxy and to host a simple web page. Let's start by installing it.
apt install nginx
Confirm the server is working by going directly to your IP in the browser. Should see the nginx test page. The file you just viewed lives at /var/www/html/index.nginx-debian.html
. This file is only used when a regular index.html
file is not present. Let's create our own index file.
cd /var/www/html
vim index.html
Then paste in this content
<!DOCTYPE html>
<html>
<head>
<title>Denver Substrate Testnet</title>
<style>
body {
width: 35em;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Denver Substrate Testnet</h1>
<p>Thanks for joining our Substrate testnet!</p>
<ul>
<li>Follow along with <a href="https://substrate.dev/substrate-beginner-workshop/#/0/">The Workshop</a></li>
<li>Clone the <a href="https://github.com/substrate-developer-hub/substrate-node-template">Substrate Node Template</a>.</li>
<li>Download the <a href="spec.json">Chain Specification</a>.</li>
<li>Download the <a href="alice.json">Prefunded Alice Key</a>.</li>
<li>Connect to <a href="https://polkadot.js.org/apps?rpc=wss://denver.bootnodes.net/alice">Alice's Node</a></li>
<li>Connect to <a href="https://polkadot.js.org/apps?rpc=wss://denver.bootnodes.net/bob">Bob's Node</a></li>
</ul>
</body>
</html>
We'll create those linked files later. Confirm the new webpage loads.
We need a domain in order to use SSL. Register it and setup dns so it points to your server. This process varies a lot by registrar. When your domain loads the webpage we just created, you may proceed to setup SSL.
For setting up subdomains like sfbw.bootnodes.net just use an A record sfbw A 1.2.3.4 3600
Install certbot, a tool that makes it easy to register new SSL certificates.
add-apt-repository ppa:certbot/certbot
apt install python-certbot-nginx
Configure nginx to work as a reverse proxy for both Alice's and Bob's nodes
cd /etc/nginx/sites-available
vim sfbw.bootnodes.net
Replace the contents of the file with this
server {
listen 80;
server_name denver.bootnodes.net;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location /alice {
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_pass http://localhost:9944;
proxy_http_version 1.1;
}
location /bob {
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_pass http://localhost:9945;
proxy_http_version 1.1;
}
# Uncomment these lines to enable reverse proxy for http rpcs as well
# location /alice/rpc {
# proxy_buffers 16 4k;
# proxy_buffer_size 2k;
# proxy_pass http://localhost:9933;
# proxy_http_version 1.1;
# }
# location /bob/rpc {
# proxy_buffers 16 4k;
# proxy_buffer_size 2k;
# proxy_pass http://localhost:9934;
# proxy_http_version 1.1;
# }
}
Enable the new config by linking it from sites-available
to sites-enabled
.
ln -s /etc/nginx/sites-available/sfbw.bootnodes.net /etc/nginx/sites-enabled/
Confirm config format is ok, and if it is, reload nginx.
# Check nginx config syntax
nginx -t
# Reload the server
systemctl reload nginx
Use certbot to setup ssl certbot --nginx -d sfbw.bootnodes.net --register-unsafely-without-email
You could also fork over your email. It only goes to EFF. I chose not to redirect http, but we should experiment with it. If it doesn't break anything, we should do it.
Confirm your site loads with ssl https://sfbw.bootnodes.net
# First time around I did the apt/rustup installs manually
# Script also works as of 1Nov2019
curl https://getsubstrate.io -sSf | bash -s -- --fast
git clone https://github.com/substrate-developer-hub/substrate-node-template
cd substrate-node-template
cargo build --release # If cargo was _just_ installed, start a new shell so it's on your path
To test that our reverse proxy is working, we'll start a node at Alice's ports and confirm we can connect to it throug hApps, then do likewise for Bob's ports.
# Test Alice's ports
./target/release/node-template --dev
# Test Bob's ports
./target/release/node-template --dev --ws-port 9945 --rpc-port 9934 --port 30303
Confirm you can connect with hosted apps. On settings tab use wss://sfbw.bootnodes.net/alice
and /bob.
Create a basic chainspec based on local testnet node-template build-spec --chain local > spec.json
Edit the name and id of the network, the root key, the prefunded accounts etc.
Before we can add bootnodes to the chainspec, we need to know their node identities. That means we need to start each node once to let it generate node keys.
Start Alice's node like node-template --chain=spec.json --alice
Once the node starts, observe its node identity, then kill it with ^C. Repeat this for any other nodes you'd like in the chainspec's bootnodes section.
Now edit the chainspec again, adding each bootnode in the format
"bootNodes": [
"/dns4/sfbw.bootnodes.net/tcp/30333/p2p/QmNdzun5tXSo7TPEntmujvU3eLEjTJKfXpJAvwp1ikpa6T",
"/ip4/167.71.86.67/tcp/30333/p2p/QmdP4qG1ZSgzmsdFpBwuPAVWG9zjPRHV3dSkTT8v4TGP4J"
],
Warning: You should not delete the node's entire data directory from this point on. You may purge the chain with the purge-chain
sub command, but if you delete the entire directory, it will delete the node key and change the node's identity.
Finally, publish the chainspec by copying it to the web directory
cp spec.json /var/www/html/spec.json
Comfirm you can access it over the web https://sfbw.bootnodes.net/spec.json
If your nodes need many flags, it may be wise to make a startup script just so you don't mess it up live. I usually write one like this.
# Purge any old chain.
# Only wise for chains that will be restarted frequently (eg workshops)
# Long running chains should not be purged to avoid constant re-syncs
./target/release/node-template purge-chain --chain=spec.json -y
./target/release/node-template \
--chain=spec.json \
--alice \
--ws-port 9994 \
--rpc-port 9993
Remember at that our website offers users to download the pre-funded key. Add the Alice key to apps and export it to json. Dev phrase
bottom drive obey lake curtain smoke basket hold race lonely fit walk //Alice I use password: Alice Upload the json key to the server
Back in /root, clone the front end template git clone https://github.com/substrate-developer-hub/substrate-front-end-template/
Install yarn following https://yarnpkg.com/lang/en/docs/install/#debian-stable
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn
install dependencies yarn
modify production server to match your needs vim src/config/production.json
and use wss://sfbw.bootnodes.net:9944
build production release with yarn build
then move build output directory inside of web root mv build /var/www/html/front-end
This is where I'm stuck. Loading https://sfbw.bootnodes.net/front-end shows a blank page, and the console shows warnings about scripts that didn't load.
I've failed many different ways at this point, and rarely even succeeded.
If you are leading this workshop, you will need to ahve a bootnode running in advance. Steps (more like notes) to do that are provided in Setting Up The Bootnode.
Author: substrate-developer-hub
Source Code: https://github.com/substrate-developer-hub/substrate-beginner-workshop
License: MIT License