How to build up setchain private network - Second-Earth/setchain GitHub Wiki
Server environment minimum requirements:
System version: Ubuntu 18.04 64-bit
Bandwidth: 10Mbps
CPU (CPU): 4 cores
Hard disk: 256G
Memory: 8GB
>git clone https://github.com/setplatform/setchain.git
>cd setchain
>make
Note: Synchronize the master branch
The default block generation account is setchain.founder, we need to modify its corresponding public key to our own public key (before this, we need to have our own public and private key pair);
>cd build
>vim genesis.json
Find setchain.founder in the file and modify its corresponding pubKey to your own public key
>cd bin
>nohup ./set --genesis=../genesis.json --datadir=./data/ --http_host 0.0.0.0 --http_port 8080 --miner_start --contractlog --http_modules=fee,miner,dpos,account ,txpool,set &
>tail -f nohup.out // View output log
Start parameter description:
- miner_start: start the mining function
- contractlog: refers to recording internal transactions, available for RPC query
- http_modules=fee,miner,dpos,account,txpool,set: refers to open fee,miner,dpos,account,txpool,set RPC interface
- genesis=../genesis.json: Specify genesis file
- datadir=./data/: Specify the block data storage directory
- http_host 0.0.0.0 --http_port 8080: Open RPC interface to the outside (remember to open the server firewall port) -Note: At this time, the chain is not working normally, the following error will be found when checking the log
ERROR[05-21|13:07:12.003] failed to mint the block
timestamp=1558415232000000000 err="illegal candidate pubkey"
The reason for this error is that we haven't configured the miner's private key. Only after the private key is configured can the miner sign the block correctly, so the following commands need to be executed:
>./set miner -i ./data/set.ipc setcoinbase "setchain.founder" privateKey.txt
>tail -f nohup.out // At this point, you can see that blocks are being produced normally
-The private key is stored in privateKey.txt. Note that the private key does not need to be prefixed with 0x. After this command is executed, remember to delete the file privateKey.txt to prevent the private key from leaking. -After the miner restarts, the above command to configure the private key needs to be re-executed, and miner_stop and miner_force need to be called sequentially through the rpc interface to resume normal block production
4: Start a multi-node chain (start three nodes on the same server, one of which is a block node, and two synchronization nodes. Note that this step has nothing to do with step 3, and all nodes need to be restarted as follows Instruction operation)
-Modify the configuration file genesis.json first, and modify the node information ip:port in bootnodes to the information of the genesis node. For example, if the IP address of the machine where the genesis node is located is 120.20.20.20 and the P2P port is 2018, then add it to bootnodes :
"bootnodes": ["fnode://a85ccab0374c60ddea0a63b521ae3f8475100ff4e116090d6798a8618ceea193f5b7deffc14627b2f61bc374336983f6a6c6ed979478590d49906e8ce6041a18@120.20.20.20:2018"],
Note: If you use the servers of cloud service providers such as Alibaba or AWS, please open the port first, otherwise the P2P nodes cannot access each other through the public IP
-Start the block node first, note that the P2P port number does not display the configuration, which is the default 2018. At the same time, turn on the mining parameters and set the miner's private key
>cd bin
>nohup ./set --genesis=../genesis.json --datadir=./data/node1 --miner_start --contractlog --http_modules=fee,miner,dpos,account,txpool,set >> node1.log &
>tail -f node1.log // View output log
>./set miner -i ./data/node1/set.ipc setcoinbase "setchain.founder" privateKey.txt
-Start two synchronization nodes again, configure the P2P port numbers to 2019 and 2020 respectively, open the RPC of one of the nodes to outside access, you need to set http_host to 0.0.0.0 (default is only local access), http_port port is 8080
>cd bin
>nohup ./set --genesis=../genesis.json --datadir=./data/node2 --p2p_listenaddr :2019 --http_host 0.0.0.0 --http_port 8080 --ws_port 8081 --contractlog --http_modules= fee,miner,dpos,account,txpool,set >> node2.log &
>nohup ./set --genesis=../genesis.json --datadir=./data/node3 --p2p_listenaddr :2020 --http_port 8090 --ws_port 8091 --contractlog --http_modules=fee,miner,dpos, account,txpool,set >> node3.log &
-Question 1: How can a private chain modify the duration of a mining cycle? A: It needs to be configured in the genesis file. There is a genesis.json file under the build folder of the public chain source directory, which contains configuration information: "epchoInterval": 10800000, where the unit is milliseconds, that is, 3 hours is a cycle, Modify the configuration here and restart to change the mining cycle. It should be noted that this parameter must be specified when starting the chain: --genesis=genesis.json.
-Question 2: I want to clear the original chain data, and then start generating blocks from 0, what should I do? A: First kill the original private chain process, then clear all data in the data directory (such as emptying all data in the ./data directory), and then execute it again in accordance with the process described in "3: Start your own private chain" can.