Skip to content

Instantly share code, notes, and snippets.

@JoshOrndorff
Last active September 24, 2019 16:09
Show Gist options
  • Save JoshOrndorff/a956e89cb63eb21920db7e3b7cfb0cf5 to your computer and use it in GitHub Desktop.
Save JoshOrndorff/a956e89cb63eb21920db7e3b7cfb0cf5 to your computer and use it in GitHub Desktop.
Start local network v2.0 draft

These are my notes trying to figure out how to update my local testnet document for Substrate master. I haven't been successful yet.

Reproducability

In case any of these issues are version related, I'm using Substrate, node-template, and subkey from 13fc71c6 and I'm using polkadot-js apps from 75bc4f3d

Here are the keys I've tried to use in case you want to use the exact same keys. Also feel free t oconfirm that I've recorded them correctly by verifying them with subkey inspect //Alice and subkey -e inspect //Alice etc.

Alice SR25519

Secret Key URI `//Alice` is account:
  Public key (hex): 0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee
  Address (SS58): 5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu

Alice ED25519

Secret Key URI `//Alice` is account:
  Public key (hex): 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
  Address (SS58): 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

Random SR25519

Secret phrase `analyst flock put hungry happy another diesel awake day small calm pride` is account:
  Secret seed: 0x957b2b8600dadbf91f5e7f61deda3d39375c7fc11232ee1e6fda230f387b04d0
  Public key (hex): 0x3471cd5dcabfb5222b66b3a20952b1a3ca4bd0154a58313c1df3dd40ecf1d10c
  Address (SS58): 5DFU9ra8Ps6mZRYgyaUVAo96DXYDefuavyAuFLTrkWF9hATV

Random ED25519

Secret phrase `analyst flock put hungry happy another diesel awake day small calm pride` is account:
  Secret seed: 0x957b2b8600dadbf91f5e7f61deda3d39375c7fc11232ee1e6fda230f387b04d0
  Public key (hex): 0x41bf971dc8fdf36dd76952880ce96c3c12aabdc52ffab3ebce6305c552b046f0
  Address (SS58): 5DYutDbrpZP6eXyfa8BjMUCp2ipTj9zof4o7Ze4gxrWqN8kV

Joshy SR25519

Secret Key URI `//Joshy` is account:
  Public key (hex): 0x006f5081d495811a16724b317fcd70b8e42c9317da2ba1f5c36756a41fadec67
  Address (SS58): 5C5GvaAWfruRLnCJYgJrut1JovGeMMXV2VzXeiua7f691J9R

Joshy ED25519

Secret Key URI `//Joshy` is account:
  Public key (hex): 0xe7d056b9abbaeee0c54812b22eb8b33254325dbeb452b65633b389ac7781cf89
  Address (SS58): 5HJeopbgk9g7zRX9f26TyLEMd7eqVfMg6nK6Z32hKohVuR8T

Building a chain spec

I started with node template, because I had luck with it in the past, and it removes the complexity of the sessions module. I start by building a chainspec based on the --dev profile with node-template build-spec --dev > spec.json. Near the end of that file I see.

      "babe": {
        "authorities": [
          [
            "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
            1
          ]
        ]
      },
      "grandpa": {
        "authorities": [
          [
            "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu",
            1
          ]
        ]
      },

Based on the keys recorded above, I see that babe is using an sr25519 key while grandpa is using an ed25519 key. That was a little surprising to me because in substrate v1.0 aura (analogous to babe) used ed25519 keys. So I double checked and indeed babe uses an sr25519 key. I updated the chainspec to look like this using the //Joshy keys.

      "babe": {
        "authorities": [
          [
            "5C5GvaAWfruRLnCJYgJrut1JovGeMMXV2VzXeiua7f691J9R",
            1
          ]
        ]
      },
      "grandpa": {
        "authorities": [
          [
            "5HJeopbgk9g7zRX9f26TyLEMd7eqVfMg6nK6Z32hKohVuR8T",
            1
          ]
        ]
      },

I then created the raw chainspec with ./target/release/node-template build-spec --chain=spec.json --raw > specRaw.json.

Starting the Node

purge chain ./target/release/node-template purge-chain --chain=specRaw.json start a fresh node ./target/release/node-template --chain=specRaw.json --validator

Things looked normal and there was no block production which is to be expected because the node does not have the //Joshy keys in its keystore.

2019-09-19 16:09:46 Substrate Node
2019-09-19 16:09:46   version 2.0.0-13fc71c68-x86_64-linux-gnu
2019-09-19 16:09:46   by Anonymous, 2017, 2018
2019-09-19 16:09:46 Chain specification: Development
2019-09-19 16:09:46 Node name: womanly-impulse-2368
2019-09-19 16:09:46 Roles: FULL
2019-09-19 16:09:47 Initializing Genesis block/state (state: 0x59b2…d4e6, header-hash: 0xeb67…551c)
2019-09-19 16:09:47 Loading GRANDPA authority set from genesis on what appears to be first startup.
2019-09-19 16:09:47 Loaded block-time = BabeConfiguration { slot_duration: 6000, c: (1, 4), median_required_blocks: 1000 } seconds from genesis on first-launch
2019-09-19 16:09:47 Creating empty BABE epoch changes on what appears to be first startup.
2019-09-19 16:09:47 Highest known block at #0
2019-09-19 16:09:47 Using default protocol ID "sup" because none is configured in the chain specs
2019-09-19 16:09:47 Local node identity is: QmZSAqo9qrKh7uStUZucgwoYsnnYQnDW9fQMzZ4gAxBPRf
2019-09-19 16:09:52 Idle (0 peers), best: #0 (0xeb67…551c), finalized #0 (0xeb67…551c), ⬇ 0 ⬆ 0
2019-09-19 16:09:57 Idle (0 peers), best: #0 (0xeb67…551c), finalized #0 (0xeb67…551c), ⬇ 0 ⬆ 0

Adding the keys

I started apps with yarn start. Using the hosted version of apps proved unsuccessful as it is older and my node logged error messages when trying it. I've omitted that part of the journey from these notes because it was a deadend. Navigated to the settings tab and confirmed I was connected localhost:9944, then navigated to the toolbox tab and RPC subtab.

Choose the author and insertKey RPC method with these parameters. (Documentation on passing parameters https://github.com/paritytech/substrate#key-management)

keytype: babe
sURI //Joshy
publicKey: 0x006f5081d495811a16724b317fcd70b8e42c9317da2ba1f5c36756a41fadec67

The notification is green and says "Sent" and the reply from the node is just 0x. At this point I expect the node to be producing blocks because it has the sr25519 key necessary for babe, but not finalizing them becuase it doesn't have the ed25519 key for grandpa.

Next add the ed25519 key for grandpa.

keytype: gran
sURI //Joshy
publicKey: 0xe7d056b9abbaeee0c54812b22eb8b33254325dbeb452b65633b389ac7781cf89

Finalization doesn't start immediately, but upon a node reboot it will.

Trying with real random keys

I tried the entire experiment again exactly as described above with the truly randomly generated keys rather than //Joshy with the same results.

Trying with full Substrate node

TODO

Fuxing with rotate keys

Just for experimentation, I made the author rotateKeys RPC and my local node-template did reply with what appears to be a public key. Given that it's only a hex string I don't know whether its ed25519, sr25519, or other.

Curl instead of apps

If you wanna look extra hacker, you can skip apps and just use curl

$ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["babe", "//Alice", "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"],"id":1 }' localhost:9933

{"jsonrpc":"2.0","result":null,"id":1}
@iammelea
Copy link

iammelea commented Sep 22, 2019

Ty for the help on Riot,
After doing some tests, I will share my experience here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment