diff --git a/config.json b/config.json index f2996db..0d8891c 100644 --- a/config.json +++ b/config.json @@ -5,6 +5,7 @@ "build-a-dapp", "start-a-private-network", "add-a-pallet", - "pallet-in-own-crate" + "pallet-in-own-crate", + "clone-a-live-chain" ] } diff --git a/tuts/clone-a-live-chain/assets/private-network-apps-insert-key-aura.png b/tuts/clone-a-live-chain/assets/private-network-apps-insert-key-aura.png new file mode 100644 index 0000000..6837301 Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-apps-insert-key-aura.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-apps-insert-key.png b/tuts/clone-a-live-chain/assets/private-network-apps-insert-key.png new file mode 100644 index 0000000..786fb4c Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-apps-insert-key.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-apps-keygen.png b/tuts/clone-a-live-chain/assets/private-network-apps-keygen.png new file mode 100644 index 0000000..142bd7d Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-apps-keygen.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-custom-endpoint.png b/tuts/clone-a-live-chain/assets/private-network-custom-endpoint.png new file mode 100644 index 0000000..5f7ea00 Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-custom-endpoint.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-no-blocks.png b/tuts/clone-a-live-chain/assets/private-network-no-blocks.png new file mode 100644 index 0000000..fbaba37 Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-no-blocks.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-select-network.png b/tuts/clone-a-live-chain/assets/private-network-select-network.png new file mode 100644 index 0000000..d8a1bad Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-select-network.png differ diff --git a/tuts/clone-a-live-chain/assets/private-network-top-left-network-icon.png b/tuts/clone-a-live-chain/assets/private-network-top-left-network-icon.png new file mode 100644 index 0000000..1055b02 Binary files /dev/null and b/tuts/clone-a-live-chain/assets/private-network-top-left-network-icon.png differ diff --git a/tuts/clone-a-live-chain/config.json b/tuts/clone-a-live-chain/config.json new file mode 100644 index 0000000..ae37646 --- /dev/null +++ b/tuts/clone-a-live-chain/config.json @@ -0,0 +1,14 @@ +{ + "slug": "config", + "lang": "en", + "title": "Clone a Live Chain", + "excerpt": "Clone a Live Substrate Chain", + "tags": [ "Medium", "2 Hours", "Prerequisites" ], + "versions": [ "v2.0.0-alpha.6" ], + "menu": [ + { "title": "Overview", "slug": "index" }, + { "title": "Start the Original Chain", "slug": "original-chain" }, + { "title": "Export Chain State", "slug": "export" }, + { "title": "Start the Clone Chain", "slug": "clone-chain"} + ] +} diff --git a/tuts/clone-a-live-chain/featured-image.png b/tuts/clone-a-live-chain/featured-image.png new file mode 100644 index 0000000..9f2d353 Binary files /dev/null and b/tuts/clone-a-live-chain/featured-image.png differ diff --git a/tuts/clone-a-live-chain/v2.0.0-alpha.6/clone-chain.md b/tuts/clone-a-live-chain/v2.0.0-alpha.6/clone-chain.md new file mode 100644 index 0000000..b0f712a --- /dev/null +++ b/tuts/clone-a-live-chain/v2.0.0-alpha.6/clone-chain.md @@ -0,0 +1,34 @@ +--- +slug: clone-chain +lang: en +title: Start the Clone Chain +--- + +Now that we've exported the state of the original chain into a chain spec file, we are able to use that as the genesis state of our new clone chain. Before starting the process, it is useful to observe some properties about the clone chain and this process. + +The clone chain will: +* Have the same state (including token balances) as the original + +The clone chain will not +* Have the same number of blocks or transactions as the original +* Have the same transactions as the original +* Be a hard fork of the original + +Unsure need to experiment: +* Be able to execute transactions designed for the original - definitely not if it has the checkGenesis. unsure about if it doesn't have that. + +## Starting the new Chain + +```bash +./target/release/node-template --chain=clone-spec.json --alice --base-path /tmp/clone/alice +``` + +## Submitting a Transaction + +Connect Apps or another UI. Ensure the balances and othe rstate are as expected. Submit a transaction and ensure it works. + +## Observing the Difference + +Connect Apps to the original chain and see that the transaction you submitted to the clone has not executed on the original. + +Submit a transaction to the original and ensure it doesn't execute on the clone. diff --git a/tuts/clone-a-live-chain/v2.0.0-alpha.6/export.md b/tuts/clone-a-live-chain/v2.0.0-alpha.6/export.md new file mode 100644 index 0000000..1a618a1 --- /dev/null +++ b/tuts/clone-a-live-chain/v2.0.0-alpha.6/export.md @@ -0,0 +1,16 @@ +--- +slug: export +lang: en +title: Export Chain State +--- + +To clone a live chain in the wild, you will need a synchronized node from which you can export the existing state. In this tutorial, we already have a node to do this, and we will use it. + +## Create the export + +```bash +./target/release/node-template export-state --dev --base-path /tmp/original/alice > clone-spec.json +``` + + +I got stuck here because latest node template won't start, and old node templates don't have the `export-state`. I'll still sketch out the rest of the idea though. diff --git a/tuts/clone-a-live-chain/v2.0.0-alpha.6/index.md b/tuts/clone-a-live-chain/v2.0.0-alpha.6/index.md new file mode 100644 index 0000000..daded53 --- /dev/null +++ b/tuts/clone-a-live-chain/v2.0.0-alpha.6/index.md @@ -0,0 +1,28 @@ +--- +slug: index +lang: en +title: Clone a Live Chain +--- + +In this tutorial we will learn to start a Substrate chain that takes its initial state from an existing live blockchain. This technique is useful for investigating bugs, testing runtime upgrades, performing airdrops, and "forking" a community during a contentious disagreement. + +## Install the Node Template + +You should already have version `v2.0.0-alpha.6` of the [Substrate Node +Template](https://github.com/substrate-developer-hub/substrate-node-template) compiled on your +computer from when you completed the [Create Your First Substrate Chain +Tutorial](/tutorials/create-your-first-substrate-chain/v2.0.0-alpha.6). If you do not, please complete that +tutorial. + +> Experienced developers who truly prefer to skip that tutorial, you may install the node template according to the instructions in its readme. + +## What you will be doing + +Before we even get started, let's lay out what we are going to do over the course of this tutorial. +We will: + +1. Launch a Substrate blockchain based on a template project. +3. Export that chain's state to a file. +4. Use the file to create a second chain that is a clone of the first. + +Sound reasonable? Good, then let's begin! diff --git a/tuts/clone-a-live-chain/v2.0.0-alpha.6/original-chain.md b/tuts/clone-a-live-chain/v2.0.0-alpha.6/original-chain.md new file mode 100644 index 0000000..d119e81 --- /dev/null +++ b/tuts/clone-a-live-chain/v2.0.0-alpha.6/original-chain.md @@ -0,0 +1,26 @@ +--- +slug: original chain +lang: en +title: Start the Original Chain +--- + +Before we can perform any cloning, we need an original chain that will be coned. + +## Start the chain + +`./target/release/node-template --dev --base-path /tmp/original/alice` + +The custom base path will help us avoid mixing up our two chains. + +## Accumulate some State + +There's no use forking a chain that doesn't yet have any interesting state. IT would be easier to jsut start a new chain. Let's build up some interesting state. The exact state is up to you. But for example you might. + +* Transfer tokens to various accounts +* Create your own account and get some tokens +* Store a value in the template pallet +* Perform some kind of runtime upgrade (would need to test whether this works) + +## Kill your chain + +It isn't truly necessary to kill it. In the wild, the original chain wouldn't die. But it may help prevent confusion or mixing up the two chains to not have it actively running.