Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Sketch the idea. #27

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tuts/clone-a-live-chain/config.json
Original file line number Diff line number Diff line change
@@ -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"}
]
}
Binary file added tuts/clone-a-live-chain/featured-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tuts/clone-a-live-chain/v2.0.0-alpha.6/clone-chain.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions tuts/clone-a-live-chain/v2.0.0-alpha.6/export.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 28 additions & 0 deletions tuts/clone-a-live-chain/v2.0.0-alpha.6/index.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting for this tutorial to be wrapped up in an exercise of investigating a bug or testing an upgrade...or both. It would also be nice to hear about how this technique can be used for airdops or forking. Also may want to consider rewording the events that may lead to a fork.


## 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!
26 changes: 26 additions & 0 deletions tuts/clone-a-live-chain/v2.0.0-alpha.6/original-chain.md
Original file line number Diff line number Diff line change
@@ -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.