Skip to content

Instantly share code, notes, and snippets.

@furusiyya
Last active August 26, 2017 12:52
Show Gist options
  • Save furusiyya/d58ea311309beeda572eb02c78d185f3 to your computer and use it in GitHub Desktop.
Save furusiyya/d58ea311309beeda572eb02c78d185f3 to your computer and use it in GitHub Desktop.

Setup should be followed one section after another.

For example you may need to set up 2 miners and 2 non-miners. You follow once through, (assuming it's tabula rasa state) Starting new Network, then Adding mining/signing node to existing network, then twice Adding non mining/signing node to existing network, after you've done it you should manually (for the purpose of testing) run: firstly run bootnode, then all other nodes. If you see that everyone is in sync (block mining appears on every one of them) you can prepare services for each of them.

Starting new network

Creating workplace

We will create a folder /home/cryptodaemon/poaGethNode and folder for blockchain database /home/cryptodaemon/poaGethNode/node mkdir -p /home/cryptodaemon/poaGethNode/node
Download PoA Geth binary and put it into /home/cryptodaemon/poaGethNode

Rename binary to geth

(warning) If you doing adding just another node, you do should skip this.
Also we will create tools folder if this new network /home/cryptodaemon/poaTools for puppeth (genesis creator) and bootnode
mkdir -p /home/cryptodaemon/poaTools
Download puppeth and bootnode and put them into /home/cryptodaemon/poaTools

Creating wallet(s) and pass file

1- Each PoA mining/signing node will require account to work with so depending on how many signers you need you should create that many accounts, if you create them on this server you will have to copy it to other server. So my suggestion would be: for each singer/miner Create workplace and Create wallet, then get back here. Here's how you create wallet:
a- Let's create new account which will request password which will be used later so (warning) don't forget it
b- /home/cryptodaemon/poaGethNode/geth --datadir /home/cryptodaemon/poaGethNode/node account new
2- Now we shall create file which will contain pass for the wallet we just created
3- vim/nano/touch/whateveryouhave /home/cryptodaemon/poaGethNode/keyPass
4- Put key you used for creation of this particular wallet
5- Save the file

Creating bootnode

1- Bootnode will be a server for node to gather and exchange information about other node locations, you only need to create one bootnode it will occupy (warning) 30301 port.
a- Lets create folder for /home/cryptodaemon/bootnode
b- mkdir /home/cryptodaemon/bootnode
2- First we need bootnode key file, lets create it
a- /home/cryptodaemon/poaTools/bootnode -genkey /home/cryptodaemon/bootnode bootnode.key
b- This created file bootnode.key in /home/cryptodaemon/poaTools/bootnode, continue if it there
3- Now we shall try running it
a- /home/cryptodaemon/poaTools/bootnode -verbosity 9 -nodekey /home/cryptodaemon/bootnode/bootnode.key
b- Cancel running process, previous command outputted long enode string something like: enode://564aefraf..much..chars..@[::]:30301
c- Save that string to home/cryptodaemon/poaTools/bootnode/enode.string file and change [::] at the end enode string to server's IP (you're currently running bootnode) so it looks like: enode://[email protected]:30301

Create static-nodes.json for enodes

1- Now will need to create a file which will contain gather point for nodes the one we created in Creating bootnode
2- You will need to use content of file home/cryptodaemon/poaTools/bootnode/enode.string
3- Let's create the file
4- vim/nano/touch/whateveryouhave /home/cryptodaemon/poaGethNode/node/static-nodes.json
5- Copy following into the file and replace enode with your enode string from enode.string file and don't remove parenthesis static-nodes.json

[
"enode"
]

6- Save and close the file

Creating genesis data

1- Now lets run puppeth which will generate genesis file for PoA Network we are doing. Before you do that you should've generated account for every miner/signer. Let's run puppeth:
2- /home/cryptodaemon/poaTools/puppeth
a- Use any name for admin
b- Select: 2. Configure new genesis
c- Select: 2. Clique - proof-of-authority
d- Press enter for default 15 seconds
e- Under "Which accounts are allowed to seal?" Provide all accounts you want be miners/signers
f- Under "Which accounts should be pre-funded?" you should provide one account
i- Under "Specify your chain/network ID" please provide: 21031986
j- Press enter to skip on last prompt about embedding message to genesis block.
k- By now you should dropped to main menu of puppeth with new function: 2. Save existing genesis
l- Select 2. Save existing genesis option and it will ask you to name genesis file, use /home/cryptodaemon/poaGethNode/genesis.json
m- You shall close puppeth (Ctrl + C)

Initialize genesis block

1- For all nodes to recognize each other we will need genesis block created 2- The following command will take genesis file we've created in Creating genesis data and be used to create genesis block for our node, so other nodes will now it's same blockchain Run the command: /home/cryptodaemon/poaGethNode/geth --datadir /home/cryptodaemon/poaGethNode/node init /home/cryptodaemon/poaGethNode/genesis.json You should get Successfully wrote genesis state, if so continue Creating bash script for bootnode Now we shall create a bash script which will be used be executed by service Let's create the file vim/nano/touch/whateveryouhave /home/cryptodaemon/poaGethNode/startBootnode Copy following into that file: startBootnode Collapse source #!/bin/sh /home/cryptodaemon/poaTools/bootnode -verbosity 9 -nodekey /home/cryptodaemon/bootnode/bootnode.key Save it lets apply executable mod for it: chmod +x /home/cryptodaemon/poaGethNode/startBootnode Try running script if it works you're good to go (you should cancel the process as we will not need if for now. Creating bash script for node Now we will create a bash script which will be used to test/debug and later by service. It will require you to know wallet address you created in step Creating wallet(s) which should be found in /home/cryptodaemon/poaGethNode/node/keystore by now The file will look like: UTC--2017-07-31T04-12-37.164309900Z–ef73c2f54e8f8447761c004f7b51fa25f7c251e0 You will need number which will be after UTC--2017-07-31T04-12-37.164309900Z– so in my case ef73c2f54e8f8447761c004f7b51fa25f7c251e0 Add 0x and that's your address of your wallet, in my case: 0xef73c2f54e8f8447761c004f7b51fa25f7c251e0 Let's create the file vim/nano/touch/whateveryouhave /home/cryptodaemon/poaGethNode/startNode Copy following into that file and change parameters after (warning) --etherbase and --unlock to your address startNodeTest Collapse source #!/bin/sh /home/cryptodaemon/poaGethNode --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --datadir /home/cryptodaemon/poaGethNode/node --networkid 21031986 --port 30305 --etherbase <change_to_your_address> --unlock <change_to_your_address> --password /home/cryptodaemon/poaGethNode/keyPass --gasprice 0 --mine Save and close the file Apply executable mod chmod +x /home/cryptodaemon/poaGethNode/startNode Checking if everything is correct If you have done everything correctly you should have the following tree: File/Folder tree Collapse source /home/cryptodaemon/poaGethNode/ ├── node/ │ ├── geth/ │ ├── keystore | └──UTC--2017-07-31T04-12-37.164309900Z–ef73c2f54e8f8447761c004f7b51fa25f7c251e0 # you wallet (diffrent number in your case) ├── geth # executable ├── genesis.json # genesis data ├── startBootnode # bash executable for starting bootnode ├── startNode # bash executable for starting node ├── nodepass # file which contains pass to wallet

/home/cryptodaemon/bootnode/ ├── bootnode.key

/home/cryptodaemon/poaTools/ ├── bootnode ├── puppeth If you have only one miner and other non-miner/non-signer nodes you should start bootnode in one console, otherwise skip this section: /home/cryptodaemon/poaGethNode/startBootnode Start your mining node /home/cryptodaemon/poaGethNode/startNode Now you can connect other nodes by proving enode of bootnode you created in other node static-nodes.json, assuming you created them with same genesis file used here If you have more then one miner you will need all them set up for (warning) exception of genesis (genesis.json) data creation, you need to copy created genesis file to other nodes and initialize them using that file. The approx. output you should get if everything works (in your case number should start from 0 and go on): output Collapse source INFO [08-25|07:43:54] Commit new mining work number=5175 txs=0 uncles=0 elapsed=1.014ms INFO [08-25|07:43:54] 🔗 block reached canonical chain number=5169 hash=9d91bc…356789 INFO [08-25|07:44:09] Successfully sealed new block number=5175 hash=d82127…b88b7c INFO [08-25|07:44:09] 🔨 mined potential block number=5175 hash=d82127…b88b7c INFO [08-25|07:44:09] Commit new mining work number=5176 txs=0 uncles=0 elapsed=1.132ms INFO [08-25|07:44:09] Signed recently, must wait for others INFO [08-25|07:44:24] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=1.271ms mgasps=0.000 number=5176 hash=6d0625…898eff INFO [08-25|07:44:24] Commit new mining work number=5177 txs=0 uncles=0 elapsed=647.98µs INFO [08-25|07:44:24] 🔗 block reached canonical chain number=5171 hash=2454c2…890102 INFO [08-25|07:44:39] Successfully sealed new block number=5177 hash=1a0e47…e72f8d INFO [08-25|07:44:39] 🔨 mined potential block number=5177 hash=1a0e47…e72f8d INFO [08-25|07:44:39] Commit new mining work number=5178 txs=0 uncles=0 elapsed=1.287ms INFO [08-25|07:44:39] Signed recently, must wait for others INFO [08-25|07:44:54] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=1.388ms mgasps=0.000 number=5178 hash=b849dc…ccb4d6 INFO [08-25|07:44:54] Commit new mining work number=5179 txs=0 uncles=0 elapsed=778.056µs INFO [08-25|07:44:54] 🔗 block reached canonical chain number=5173 hash=8d50d5…503469 Adding mining/signing node to existing network To add another mining node to existing network you should follow: Creating workplace Creating wallet(s) Create static-nodes.json for enodes (enode string should be taken from server which contains enode.string) Initialize genesis block Creating bash script for node If you have done everything correctly you should have the following tree: File/Folder tree Collapse source /home/cryptodaemon/poaGethNode/ ├── node/ │ ├── geth/ │ ├── keystore | └──UTC--2017-07-31T04-12-37.164309900Z–ef73c2f54e8f8447761c004f7b51fa25f7c251e0 # you wallet (diffrent number in your case) ├── geth # executable ├── genesis.json # genesis data ├── startNode # bash executable for starting node ├── nodepass # file which contains pass to wallet You should be able to test 2 nodes by executing two /home/cryptodaemon/poaGethNode/startNode from 2 servers The approx. output you should get if everything works (in your case number should start from 0 and go on): output Collapse source INFO [08-25|07:43:54] Commit new mining work number=5175 txs=0 uncles=0 elapsed=1.014ms INFO [08-25|07:43:54] 🔗 block reached canonical chain number=5169 hash=9d91bc…356789 INFO [08-25|07:44:09] Successfully sealed new block number=5175 hash=d82127…b88b7c INFO [08-25|07:44:09] 🔨 mined potential block number=5175 hash=d82127…b88b7c INFO [08-25|07:44:09] Commit new mining work number=5176 txs=0 uncles=0 elapsed=1.132ms INFO [08-25|07:44:09] Signed recently, must wait for others INFO [08-25|07:44:24] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=1.271ms mgasps=0.000 number=5176 hash=6d0625…898eff INFO [08-25|07:44:24] Commit new mining work number=5177 txs=0 uncles=0 elapsed=647.98µs INFO [08-25|07:44:24] 🔗 block reached canonical chain number=5171 hash=2454c2…890102 INFO [08-25|07:44:39] Successfully sealed new block number=5177 hash=1a0e47…e72f8d INFO [08-25|07:44:39] 🔨 mined potential block number=5177 hash=1a0e47…e72f8d INFO [08-25|07:44:39] Commit new mining work number=5178 txs=0 uncles=0 elapsed=1.287ms INFO [08-25|07:44:39] Signed recently, must wait for others INFO [08-25|07:44:54] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=1.388ms mgasps=0.000 number=5178 hash=b849dc…ccb4d6 INFO [08-25|07:44:54] Commit new mining work number=5179 txs=0 uncles=0 elapsed=778.056µs INFO [08-25|07:44:54] 🔗 block reached canonical chain number=5173 hash=8d50d5…503469 Adding non mining/signing node to existing network To add another non mining/signing node to existing network you should follow: Creating Workplace Create static-nodes.json for enodes Initialize genesis block Creating bash script for node If you have done everything correctly you should have the following tree: File/Folder tree Expand source Creating service for bootnode Let's create a service vim/nano/touch/whateveryouhave /etc/systemd/system/poaBootnode.service Copy/paste poaBootnode.service Collapse source [Unit] Description=PoA Bootnode

[Service] Type=simple ExecStart=/bin/bash /home/cryptodaemon/poaGethNode/startBootnode Restart=always User=root

[Install] WantedBy=multi-user.target Save and close file Create some magic but side effects may include dry mouth, nausea, vomiting, water retention, painful rectal itch, hallucination, dementia, psychosis, coma, death, and halitosis. Magic is not for everyone. Consult your doctor before use. Service should be ready to use Creating service for node start Let's create a service vim/nano/touch/showmewhatyougot /etc/systemd/system/poaGeth.service Copy/paste poaGeth.service Collapse source [Unit] Description=PoA Geth Node

[Service] Type=simple ExecStart=/bin/bash /home/cryptodaemon/poaGethNode/startNode Restart=always User=root

[Install] WantedBy=multi-user.target Resetting Network In order to reset network you will need to perfrom following actions on each of node in network: Stop node systemctl stop poaGeth.service Remove everything in /home/cryptodaemon/poaGethNode/node for (warning) exception of static-nodes.json and keystore (if it has it; miners/singer nodes should) Reinit genesis block Initialize genesis block You are good to go - start service Troubleshooting Appendix Flag/Parameter Explanation Collapse source --datadir # folder which will contain blockchain data and keys in keystore --password # path to file which contains password for node (password maybe passed instead of file) --verbosity # log level (6 for testing purposes) --ipcdisable # disables local pipe which can be instantiated only once there it's turned off and RPC used instead (1 node can have it enabled) --networkid # network identifier (should be same for every node) --port # p2p port --rpc # start RPC server --rpcaddr # if no specified allows only local connections --rpcapi # which modules should be loaded and allowed to access through RPC --rpcport # port for RPC access --gasprice # should be 0 because of the purpose of PoA is collaboration towards maintaining blockchain --mine # initializes mining, or in PoA case signing blocks if authorized --bootnodes # enode(s) address for node rendezvous console # enables console after node have been started

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