RSK: multiple nodes setup in private network + send transactions from different nodes
Thanks to ajlopez · GitHub from RSKJ gitter, 2017/12/10.
-----------
2 ways: use genconf, a tool to set up automatically and to set up manually.
GENCONF: Automatic setup tool:
RskUtils/genconf at master · ajlopez/RskUtils · GitHub
Git clone & go to genconf directory to install node and type commands.
*... to get the config to work, users need to modify generated config files as follows;
1: put coinbase.secret OUTSIDE of a { }
2: set solc path
-----------
Manual guide:
[To set up multiple nodes in a privatenet & send transactions from different nodes]
Use same Jar file and different config file and truffle projects.
Before you go ahead: Check: that you can run 1 node in private net
STEPS:
0: Set genesis block of the private network
Use file rsk-dev.json as below:
*rsk-dev.json is in the published jar as a resource
1: Set config for a private network
a: blockchain.config.name = "regtest" for the first line of the config file
b: enable wallet
In this way, there is an special account cd2a3d9f938e13cd947ec05abc7fe734df8dd826 with initial funds (maybe is the first OR the second account in account list)
The account with funds is only available for "regtest", use case private network
That account is called the "cow" account.
2: copy your local config file, and ALTER the following key/values
a: rpc port (from 4444 to 4445 to 4446, etc)
b: peer listen.port (from 30305 to 30306 to 30307, etc)
c: peer.discovery enable SHOULD be false
d:set database different for each config (from {dir = "/Users/name/rskjdir/database"} to "{dir = "/Users/name/rskjdir/databases/node1"}" , etc)
e: you must have generated the node id and private key FOR EACH NODE. the private key should be put at peer privateKey
e(1): To check node information / nodeinfo
$ java -Drsk.conf.file=node1.conf -cp rskj-core-0.2.5-GINGER-all.jar co.rsk.GenNodeKeyId
{
"privateKey": "2492e05b0feeal...",
"publicKey": "04c2e1...",
"address": "0eusirg.....",
"nodeId": "c2e177b...."
}
from: https://github.com/rsksmart/rskj/wiki/How-to-initialize-RSK-node-configuration-file-settings
f: see the peer active section
*port = peer listen.port of the other nodes you wish to connect to
Set the variables so that the first node config points to the OTHER TWO nodes
The second node config points to the FIRST and the THIRD ones, etc....
e(1): To know your ip on Mac:
https://www.wikihow.com/Find-Your-IP-Address-on-a-Mac
3: check: ONE or more nodes should be miner
This is because if don't have a miner NO TRANSACTION WILL BE PROCESSED in the private net
To set a miner:
put true into miner client.enabled AND miner.server.enabled
* If you have MORE THAN ONE miner, use a different coinbase.secret for each one (the above config is valid for bamboo release)
------------------
<CHECK: set up multiple nodes in a private network, connected as peers>
1: start RSK network with edited conf files on different terminals
eg:
$ java -Drsk.conf.file=node1.conf -cp rskj-core-0.2.5-GINGER-all.jar co.rsk.Start
and
$ java -Drsk.conf.file=minernode1.conf -cp rskj-core-0.2.5-GINGER-all.jar co.rsk.Start
2: see log for something like this:
2017-12-10-21:50:18.0238 TRACE [sync] Peer c2e177b3: initiate connection
*c2e177b3 = first letters of nodeId of the added peer
---------------------
4: to send a transaction from a specific node of choice
You can use web3, truffle, or your own javascript script, pointint to http://localhost:4444 or http://localhost:4445 and so on
To use truffle, alter the truffle.js file. Change the port from 8545 to 4444, etc
As below:
*... port is the rpc port
*..."from" account is set to be the "cow" account, from step 1.
The address is : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'
Only 1 "cow" account exists in 1 "regtest" network. So each truffle project's truffle.js should have the same cow account in config.
5: check that you have the acconts set up
a: start truffle console
truffle(development)> web3.eth.accounts
[ '0xf4fe95909b7f3bd0f96f93811c29e14e6f97aff5',
'0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' ] <= "cow" account
truffle(development)> web3.eth.getBalance(web3.eth.accounts[0])
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(development)> web3.eth.getBalance(web3.eth.accounts[1])
BigNumber { s: 1, e: 21, c: [ 20000000 ] }