Git Product home page Git Product logo

fork-off-substrate's Introduction

Fork off substrate

This script allows bootstrapping a new substrate chain with the current state of a live chain. Using this, you can create a fork of Polkadot, Kusama and other substrate chain for development purposes.

Usage

  1. Clone this repository and install dependencies

    git clone https://github.com/maxsam4/fork-off-substrate.git
    cd fork-off-substrate
    npm i
  2. Create a folder called data inside the top folder (fork-off-substrate).

    mkdir data
  3. Copy the executable/binary of your substrate based node inside the data folder and rename it to binary.

  4. Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to runtime.wasm. To get the WASM blob, compile your blockchain and look for ./target/release/wbuild/runtime/runtime.compact.wasm. If you are forking Polkadot/Kusama/Westend, you can download the WASM blobs from Polkadot's release page.

  5. If your substrate chain uses additional custom types than what are available in polkadot.js, define them in a JSON file of format { "types": { <YOUR_TYPES> } }. Copy the file to the data folder and rename it to schema.json.

  6. Either run a full node for your blockchain locally(Recommended) or have an external endpoint handy.

  7. Run the script

    • If using a local node, simply run the script using

      npm start
    • If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP_RPC_ENDPOINT environment variable

      HTTP_RPC_ENDPOINT=https://example.com npm start
  8. You should have the genesis file for the forked chain inside the data folder. It will be called fork.json.

  9. You can now run a new chain using this genesis file

    ./binary --chain fork.json --alice

Configuration

The script can be tweaked and configured using various environment variables -

Environment Variable Effects Default value
HTTP_RPC_ENDPOINT HTTP RPC endpoint that should be used to query state http://localhost:9933
FORK_CHUNKS_LEVEL Determines how many chunks to split the RPC download in. Effect is exponential, recommended value for most is 1. You can try 0 for small chains and 2 for large chains for potential speed improvements 1
ORIG_CHAIN Chain to use as the original chain. $default_of_the_binary
FORK_CHAIN Chain to use as base for the forked chain. dev
ALICE If set, the script will replace the chain's sudo account with //Alice NULL
QUICK_MODE If set, it parallelizes the data download from the RPC endpoint NULL

Read more

If you would like to understand how this script works, please read this blog post

Using Docker

Build the image

docker build -t fork-off-substrate .

Run

BINARY=/full/path/to/your/linux/binary
HTTP_RPC_ENDPOINT=http://localhost:9933
docker run --rm -it \
    -e HTTP_RPC_ENDPOINT=$HTTP_RPC_ENDPOINT \
    -v "$BINARY":/data/binary
    fork-off-substrate

Credits

This script is based on a script shared in the substrate riot channel

fork-off-substrate's People

Contributors

apopiak avatar dependabot[bot] avatar eteissonniere avatar ethernomad avatar maxsam4 avatar xcaptain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fork-off-substrate's Issues

Error starting script

➜  fork-off-substrate git:(master) npm start

> [email protected] start /home/dylan/Projects/fork-off-substrate
> node index.js

We are intentionally using the HTTP endpoint. If you see any warnings about that, please ignore them.
2022-02-16 18:34:11        API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
2022-02-16 18:34:11        API/INIT: Error: FATAL: Unable to initialize the API: Cannot convert undefined or null to object
    at ApiPromise.value (/home/dylan/Projects/fork-off-substrate/node_modules/@polkadot/api/base/Init.cjs:88:25)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Any idea what this means?

The finalized block alway 0

Follow the README and show such logs. I have no idea why the finalized block is 0 all the time. Does anyone know what happened here?

$ ./binary --chain fork.json --alice
2022-04-22 15:44:56 👶 Creating empty BABE epoch changes on what appears to be first startup.    
2022-04-22 15:44:56 🏷 Local node identity is: 12D3KooWF6hM2mHQf5U8AtyhCvB2RvdY5S4NxQuRfVptYY9JRrSQ    
2022-04-22 15:44:56 Can't listen on /ip6/::/tcp/30333 because: Other(Custom { kind: Other, error: Other(A(A(A(A(Transport(B(Os { code: 98, kind: AddrInUse, message: "Address already in use" }))))))) })    
2022-04-22 15:44:56 Can't listen on /ip4/0.0.0.0/tcp/30333 because: Other(Custom { kind: Other, error: Other(A(A(A(A(Transport(B(Os { code: 98, kind: AddrInUse, message: "Address already in use" }))))))) })    
2022-04-22 15:44:57 📦 Highest known block at #0    
2022-04-22 15:44:57 Unable to bind RPC server to 127.0.0.1:9933. Trying random port.    
2022-04-22 15:44:57 Unable to listen on 127.0.0.1:9944    
2022-04-22 15:44:57 Unable to bind RPC server to 127.0.0.1:9944. Trying random port.    
2022-04-22 15:44:57 Listening for new connections on 127.0.0.1:41053.    
2022-04-22 15:44:57 👶 Starting BABE Authorship worker    
2022-04-22 15:45:02 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 134.9kiB/s ⬆ 20.1kiB/s    
2022-04-22 15:45:07 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 130.7kiB/s ⬆ 9.5kiB/s    
2022-04-22 15:45:12 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 41.8kiB/s ⬆ 4.7kiB/s    
2022-04-22 15:45:17 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 100.2kiB/s ⬆ 7.4kiB/s    
2022-04-22 15:45:22 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 0.8kiB/s ⬆ 0.8kiB/s    
2022-04-22 15:45:27 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 0.8kiB/s ⬆ 0.7kiB/s    
2022-04-22 15:45:32 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 111.5kiB/s ⬆ 7.3kiB/s    
2022-04-22 15:45:37 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 3.7kiB/s ⬆ 1.0kiB/s    
2022-04-22 15:45:42 💤 Idle (0 peers), best: #0 (0x5b7b…dbe6), finalized #0 (0x5b7b…dbe6), ⬇ 0.1kiB/s ⬆ 0.1kiB/s 

Unknown types on latest westend

Tried this on latest westend and I'm getting errors related to unknown types

2021-05-13 08:14:50 API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
2021-05-13 08:14:51 REGISTRY: Unable to resolve type Outcome, it will fail on construction
2021-05-13 08:14:51 REGISTRY: Unable to resolve type PalletId, it will fail on construction
2021-05-13 08:14:51 REGISTRY: Error: Cannot construct unknown type PalletId
2021-05-13 08:14:51 API/INIT: Error: FATAL: Unable to initialize the API: createType(PalletId):: Cannot construct unknown type PalletId
2021-05-13 08:14:51 API/INIT: Error: createType(PalletId):: Cannot construct unknown type PalletId

`spec_name` Mismatched

Unable to author block in slot 270671004,. `can_author_with` returned: `spec_name` does not match `Darwinia` vs `Crab` Probably a node update is required!    

Cannot convert undefined or null to object

Hey,
I'm trying to get fork-off-substrate to work with https://github.com/edgeware-network/edgeware-node/tree/erup-5-latest.

I assume it's because I have not added the custom types but, I have imported them into the index.js file(const { spec } = require('@edgeware/node-types');) and that should work. Am I missing something here that causes problems?

HTTP_RPC_ENDPOINT=http://mynode:9988 npm start

> [email protected] start
> node index.js

We are intentionally using the HTTP endpoint. If you see any warnings about that, please ignore them.
Custom Schema missing, using default schema.
2022-07-26 22:54:26        API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
2022-07-26 22:54:27        API/INIT: RPC methods not decorated: contracts_upload_code, dev_getBlockStats, eth_feeHistory, eth_maxPriorityFeePerGas
2022-07-26 22:54:27        API/INIT: Error: FATAL: Unable to initialize the API: Cannot convert undefined or null to object
    at ApiPromise.value (/fork-off-substrate/node_modules/@polkadot/api/base/Init.cjs:88:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Custom types imported:
https://github.com/hicommonwealth/edgeware-node-types

Fetch Error

 HTTP_RPC_ENDPOINT=http://office.nkg:20000 npm start

> fork-off-substrate@1.0.0 start /home/xavier/Documents/paritytech/fork-off-substrate
> node index.js

We are intentionally using the HTTP endpoint. If you see any warnings about that, please ignore them.
2021-03-02 12:18:28        API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
2021-03-02 12:18:28        API-HTTP: HTTP Provider does not have 'on' emitters, use WebSockets instead
2021-03-02 12:18:28        API-HTTP: HTTP Provider does not have 'on' emitters, use WebSockets instead
2021-03-02 12:18:28        API-HTTP: HTTP Provider does not have 'on' emitters, use WebSockets instead
2021-03-02 12:18:29        API/INIT: RPC methods not decorated: balances_usableBalance, headerMMR_genProof, staking_powerOf
Unable to resolve type Status, it will fail on construction
Unknown signed extensions CheckEthereumRelayHeaderParcel found, treating them as no-effect
Unknown types found, no types for Status
Fetching current state of the live chain. Please wait, it can take a while depending on the size of your chain.

/home/xavier/Documents/paritytech/fork-off-substrate/node_modules/node-fetch/lib/index.js:272
				return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
				                           ^
FetchError: invalid json response body at http://office.nkg:20000/ reason: Cannot create a string longer than 0x1fffffe8 characters
    at /home/xavier/Documents/paritytech/fork-off-substrate/node_modules/node-fetch/lib/index.js:272:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async HttpProvider.send (/home/xavier/Documents/paritytech/fork-off-substrate/node_modules/@polkadot/rpc-provider/http/index.js:149:20)
    at async main (/home/xavier/Documents/paritytech/fork-off-substrate/index.js:65:17) {
  type: 'invalid-json'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xavier/.npm/_logs/2021-03-02T04_22_46_261Z-debug.log

How to get rid of the validator set?

Hello!

I'm a member of the Kusama Society and we are developing a dedicated interface as a development plan for the society. We want to create some integration tests and for that we want to run a development node reflecting the state of Society members at some point in time.

I'm trying to run a development chain forked off from Kusama. So far I synched an archived node and created the fork against said node. Apparently all went well, but I'm unable to produce blocks and execute extrinsics. I suppose it's because the chain is waiting for the current Kusama validator set. How do I change the validator set and get control over the chain?

I tried editing fork.json but I don't understand its structure.

Unknown error occurred

I got error message like this when I tried exporting chain state following the readme:

etching current state of the live chain. Please wait, it can take a while depending on the size of your chain.
 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0% | ETA: 0s | 0/256(node:564735) UnhandledPromiseRejectionWarning: Error: -32603: Unknown error occurred: Ur
    at RpcCoder._checkError (/home/bear/working/darwinia/fork-off-substrate/node_modules/@polkadot/rpc-provider/coder/index.cjs:84:13)
    at RpcCoder.decodeResponse (/home/bear/working/darwinia/fork-off-substrate/node_modules/@polkadot/rpc-provider/coder/index.cjs:47:10)
    at HttpProvider.send (/home/bear/working/darwinia/fork-off-substrate/node_modules/@polkadot/rpc-provider/http/index.cjs:150:76)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async fetchChunks (/home/bear/working/darwinia/fork-off-substrate/index.js:135:19)
    at async fetchChunks (/home/bear/working/darwinia/fork-off-substrate/index.js:153:7)
    at async main (/home/bear/working/darwinia/fork-off-substrate/index.js:81:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:564735) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function with)
(node:564735) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will t.

Polkadot state JSON not parsable

When I run npm start with a Polkadot archive node locally, it results in:

node:buffer:593
    slice: (buf, start, end) => buf.utf8Slice(start, end),
                                    ^
Error: Cannot create a string longer than 0x1fffffe8 characters
    at Object.slice (node:buffer:593:37)
    at Buffer.toString (node:buffer:811:14)
    at Object.readFileSync (node:fs:497:41)
    at main (/home/vados/fork-off-substrate/index.js:123:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_STRING_TOO_LONG'
}

NodeJS only allows for strings to be 512 MiB, currently the state of Polkadot seems to be larger that that.
Example file.

There are some async parsing libs, but they are slow and I dont know how to write the state back to disk with them either...

Can this script backup the whole blockchain?

I tried to run this script, but I found I can only backup the current state, all the blocks since block 1 in the fork chain are different with the original chain, just want to make sure can this script backup the whole blockchain?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.