Skip to content

Deploy private chain

cross-chain edited this page Jul 14, 2020 · 5 revisions

Deploy Fusion Private Chain

1. clone efsn source code

git clone https://github.com/FUSIONFoundation/efsn.git
cd efsn

2. build the source code

make efsn bootnode

binaries will be in generated in `./build/bin` directory

3. generate bootnode key

./build/bin/bootnode -genkey bootnode.key

4. start bootnode

```shell
# bootnode.key is the file generated in the above step.
# we can change port number 40407 to others if conflict with other program
./build/bin/bootnode -nodekey bootnode.key -addr :40407 > bootnode.address 2>&1 &
```

5. get the running bootnode's address

bootnode.address is the file generated in the above step.

cat bootnode.address

bootnode.address content is something like this:

INFO [11-07|17:05:37.719] UDP listener up self=enode://9237f5d9144f170817dc01a236fc31340e9b793fe62760aae89c9b1d91cb4033988dfca75642453399ed751f3dec2accff489540b26486e2633019b0cbdd5593@[::]:40407

the bootnode's address is enode://...@[::]:40407, we should replace [::] with 127.0.0.1.
for the above example, the final bootnode's address is
enode://9237f5d9144f170817dc01a236fc31340e9b793fe62760aae89c9b1d91cb4033988dfca75642453399ed751f3dec2accff489540b26486e2633019b0cbdd5593@127.0.0.1:40407

bootnode's address is required for multiple nodes to communicate with each other through bootnode.

6. start fusion node

6.1 deploy private chain by genesis.json

We can specify our own genesis.json to create private chain genesis block, and run a private chain on this genesis.

The following are the concrete steps.

firstly,

create your own genesis.json file. the following is an example. you can modify it accordingly, especially the chainId, ticketsCreate and alloc parts.

{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "daoForkBlock": 0,
    "daoForkSupport": false,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "DaTong": {
      "period": 15
    }
  },
  "nonce": "0x1",
  "timestamp": "0x5d17fb80",
  "extraData": "0x00000000000000000000000000000000000000000000000000000000000000000000000000010000000001020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "ticketsCreate" : {
    "owner": "0x0122bf3930c1201a21133937ad5c83eb4ded1b08",
    "time": 1594711540,
    "count": 5
  },
  "alloc": {
    "0x0122bf3930c1201a21133937ad5c83eb4ded1b08": {"balance": "100000000000000000000000000"},
    "0x37a200388caa75edcc53a2bd329f7e9563c6acb6": {"balance": "100000000000000000000000000"},
    "0x07f35aba9555a532c0edc2bd6350c891b6f2c8d0": {"balance": "100000000000000000000000000"}
  }
}

then,

run the following command to create genesis block locally for each node.

./efsn init --datadir node1 genesis.json

now, you can start the fusion node.

notice --networkid 666 (666 should be same as chainId in the above genesis.json)

./efsn --datadir node1 --port 12341 --bootnodes enode://9237f5d9144f170817dc01a236fc31340e9b793fe62760aae89c9b1d91cb4033988dfca75642453399ed751f3dec2accff489540b26486e2633019b0cbdd5593@127.0.0.1:40407 --rpc --rpcport 12001 --rpcapi web3,eth,net,db,personal,fsn,fsntx --rpcaddr 0.0.0.0 --rpccorsdomain "*" --ws --wsport 13001 --wsapi web3,eth,net,db,personal,fsn,fsntx --wsaddr 0.0.0.0 --wsorigins "*" --unlock $YOUR_OWN_ADDRESS --miner.etherbase $YOUR_OWN_ADDRESS --password passwd --networkid 666 --mine --autobt 2>&1 |tee -a node1.log

6.2 deploy private chain by devnet option

Deploy private chain use --devnet and -devnetaddr options.

Suppose your own addres is $YOUR_OWN_ADDRESS, please replace it with your real address.

And all your nodes' --devnetaddr value must be same

Notice that devnet private chain's chainID is 55555.

  • start mining node

    ./build/bin/efsn --devnet --datadir node1 --port 12341 --bootnodes enode://9237f5d9144f170817dc01a236fc31340e9b793fe62760aae89c9b1d91cb4033988dfca75642453399ed751f3dec2accff489540b26486e2633019b0cbdd5593@127.0.0.1:40407 --rpc --rpcport 12001 --rpcapi web3,eth,net,db,personal,fsn,fsntx --rpcaddr 0.0.0.0 --rpccorsdomain "*" --ws --wsport 13001 --wsapi web3,eth,net,db,personal,fsn,fsntx --wsaddr 0.0.0.0 --wsorigins "*" --devnetaddr $YOUR_OWN_ADDRESS  --unlock $YOUR_OWN_ADDRESS --miner.etherbase $YOUR_OWN_ADDRESS --password passwd --networkid 55555 --mine --autobt 2>&1 |tee -a node1.log
  • start syncing node

    ./build/bin/efsn --devnet --datadir node2 --port 12342 --bootnodes enode://9237f5d9144f170817dc01a236fc31340e9b793fe62760aae89c9b1d91cb4033988dfca75642453399ed751f3dec2accff489540b26486e2633019b0cbdd5593@127.0.0.1:40407 --rpc --rpcport 12002 --rpcapi web3,eth,net,db,personal,fsn,fsntx --rpcaddr 0.0.0.0 --rpccorsdomain "*" --ws --wsport 13002 --wsapi web3,eth,net,db,personal,fsn,fsntx --wsaddr 0.0.0.0 --wsorigins "*" --devnetaddr $YOUR_OWN_ADDRESS --networkid 55555 2>&1 |tee -a node2.log

    Note for options:

    1. we should use your own bootnode address in option --bootnodes <YOUR-BOOTNODE-ADDRESS>
    2. we can change --port --rpcport --wsport these port numbers if it conflicts with other program.
    3. we can also change your datadir name in option --datadir <YOUR-DATA-DIR>, block chain data will store in this directory.
    4. we should specify your own account address to unlock option --unlock <YOUR-ACCOUNT-ADDRSS>
    5. we should specify you own password file path to password option --password <YOUR_PASSWORD-FILE>
    6. if we want to mining, we should specify --mine option
    7. if we want to auto buy ticket, we should specify --autobt option

7. check your node state

we can attach to any running node, and execute commands in the concole

./build/bin/efsn attach node1/efsn.ipc

then input commads in the console, (double press tab keyboard to completes command)

eg.,

eth.blockNumber
admin.nodeInfo
fsn.getStakeInfo()
fsn.getAllBalances(eth.coinbase)
personal.unlockAccount(eth.coinbase, null, 0)
miner.start()

8. connect nodes manually

sometimes nodes can not connect with each other (even though bootnode is running)
for this situation, we can connect them manually use the following way,
for example, we'll connect node1 with node2 manually.

  1. firstly, we should know the node info of node2.

    we can do like this:

    ./build/bin/efsn attach node2/efsn.ipc
    
    admin.nodeInfo.enode

    we will get result like the following format: "enode://90629a1c849c22249562f7c15f156e6a821fb4db6822c3c62c79f56f77edcfd8bbf7d8eedb9bd66c2c2314ea74684e8d0353ecbb3a592b97a4c2e6e9af248ed9@[::]:12342"
    we should replace [::] with 127.0.0.1, so the final node info of node2 is:
    "enode://90629a1c849c22249562f7c15f156e6a821fb4db6822c3c62c79f56f77edcfd8bbf7d8eedb9bd66c2c2314ea74684e8d0353ecbb3a592b97a4c2e6e9af248ed9@127.0.0.1:12342"

  2. then we can add peer of node2

    we can do like this:

    ./build/bin/efsn attach node1/efsn.ipc
    
    admin.addPeer("enode://90629a1c849c22249562f7c15f156e6a821fb4db6822c3c62c79f56f77edcfd8bbf7d8eedb9bd66c2c2314ea74684e8d0353ecbb3a592b97a4c2e6e9af248ed9@127.0.0.1:12342")
  3. check peers of my node

    we can do like this:

    ./build/bin/efsn attach node1/efsn.ipc
    
    admin.peers

    if connect succsessfuly, the peers would contain node2 now. that means node1 and node2 is connected now. they can communicate through p2p protocol now.


9. additional

  • generate new account

    ./efsn account new --datadir node2

    it will generate a new keystore file in your specified datadir (node2 in the above example)