Skip to main content

Private Network

This document describes how to quickly deploy a private blockchain.

  • Before building the private chain, you need to compile the binary. You can refer to the Install PlatON document.

  • Take the private chain deployment under Ubuntu as an example, including single node and cluster deployment. The deployment procedures under Windows is similar to Ubuntu.

If you can't easily connect to an external network, you can choose to build your own private network.PlatON supports single node mode and cluster mode to run private networks.Take the Ubuntu environment as an example and suppose the node data directory is ~/platon-node/data , which the users should modify accordingly:

Standalone or Single Node Mode#

  • Generate nodekey and blskey files
mkdir -p ~/platon-node/data && platonkey genkeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ~/platon-node/data/nodekey) >(grep "PublicKey" | awk '{print $3}' > ~/platon-node/data/nodeid) && platonkey genblskeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ~/platon-node/data/blskey) >(grep "PublicKey" | awk '{print $3}' > ~/platon-node/data/blspub)

Note:

  • nodeid: node public key (ID) file, which stores the public key of the node and is used to identify the node
  • nodekey: node private key file which stores the node's private key and can not be public and need to do a backup.
  • blspub: node BLS public key file which stores the BLS public key of the node, and is used for fast verification of signatures in the consensus protocol.
  • blskey: node BLS private key file which stores the node's BLS private key, cannot be published and need to make a backup.
  • Generate wallet file
mkdir -p ~/platon-node/data && platon --datadir ~/platon-node/data account new

Your new account is locked with a password. Please give a password. Do not forget this password.

Passphrase:

Repeat passphrase:

Address: {lat1q25u0zphmre6tz8nt3cuen0ekmas7qfzaalgh4}

Note:

The wallet file and password are very important for the generated account address. Losing the wallet file or forgetting the password will cause the token in the account to be lost. Please make a backup of the wallet file and remember the password.

  • Editing the genesis block configuration file platon.json

Create the genesis block configuration file platon.json in the ~/platon-node directory, then copy the following genesis block configuration file template content to platon.json file, modify your-node-pubkey as the previously generated node public key (nodeid), your-node-blspubkey as node BLS public key (blspub), your-account-address as the wallet address:

……    "cbft": {    "initialNodes": [{        "node": "enode://your-node-pubkey@127.0.0.1:16789",        "blsPubKey": "your-node-blspubkey"    }],    ……    "alloc": {      "your-account-address": {            "balance": "999000000000000000000"      }    },……
  • Genesis block configuration file template
{    "config": {        "chainId": 1021,        "eip155Block": 3,        "cbft": {            "initialNodes": [              {                    "node":"enode://4fcc251cf6bf3ea53a748971a223f5676225ee4380b65c7889a2b491e1551d45fe9fcc19c6af54dcf0d5323b5aa8ee1d919791695082bae1f86dd282dba4150f@127.0.0.1:16790",                    "blsPubKey":"d341a0c485c9ec00cecf7ea16323c547900f6a1bacb9daacb00c2b8bacee631f75d5d31b75814b7f1ae3a4e18b71c617bc2f230daa0c893746ed87b08b2df93ca4ddde2816b3ac410b9980bcc048521562a3b2d00e900fd777d3cf88ce678719"              }            ],            "amount": 10,            "period": 10000,            "validatorMode": "ppos"        },        "genesisVersion": 3328    },    "economicModel":{        "common":{            "maxEpochMinutes":4,            "maxConsensusVals":4,            "additionalCycleTime":28        },        "staking":{            "stakeThreshold": 100000000000000000000000,            "operatingThreshold": 10000000000000000000,            "maxValidators": 30,            "unStakeFreezeDuration": 2,            "rewardPerMaxChangeRange": 500,            "rewardPerChangeInterval": 10        },        "slashing":{           "slashFractionDuplicateSign": 100,           "duplicateSignReportReward": 50,           "maxEvidenceAge":1,           "slashBlocksReward":20,           "zeroProduceCumulativeTime":3,           "zeroProduceNumberThreshold":2,           "zeroProduceFreezeDuration":1        },         "gov": {            "versionProposalVoteDurationSeconds": 160,            "versionProposalSupportRate": 6670,            "textProposalVoteDurationSeconds": 160,            "textProposalVoteRate": 5000,            "textProposalSupportRate": 6670,                      "cancelProposalVoteRate": 5000,            "cancelProposalSupportRate": 6670,            "paramProposalVoteDurationSeconds": 160,            "paramProposalVoteRate": 5000,            "paramProposalSupportRate": 6670              },        "reward":{            "newBlockRate": 50,            "platonFoundationYear": 10,            "increaseIssuanceRatio": 250        },        "innerAcc":{            "platonFundAccount": "lat1q25u0zphmre6tz8nt3cuen0ekmas7qfzaalgh4",            "platonFundBalance": 0,            "cdfAccount": "lat10kvcm60zhmlsfmsjjdqggnsu6nccl5q2v6kqw2",            "cdfBalance": 331811981000000000000000000        }    },    "nonce": "0x0376e56dffd12ab53bb149bda4e0cbce2b6aabe4cccc0df0b5a39e12977a2fcd23",    "timestamp": "0x5bc94a8a",    "extraData": "0xd782070186706c61746f6e86676f312e3131856c696e757800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",    "gasLimit": "4712388",    "alloc": {        "lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrdyjj2v": {            "balance": "200000000000000000000000000"        },        "lat1jvm3ljpeyrc6k9c7d6x0sq4dq9m42skueugvxy": {            "balance": "9718188019000000000000000000"        }    },    "number": "0x0",    "gasUsed": "0x0",    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"}
  • Initialize the genesis block
cd ~/platon-node && platon --datadir ./data init platon.json

Note:

The Successfully genesis state prompt appears to indicate that the initialization of the genesis information is complete.

  • Start Node

    In general, the platon process is always in the foreground, so we cannot do anything else, and if we exit the terminal in the middle, the program will exit.Ubuntu can launch programs in nohup mode:

cd ~/platon-node && nohup platon --identity "platon" --datadir ./data --port 16789 --rpcaddr 127.0.0.1 --rpcport 6789 --rpcapi "db,platon,net,web3,admin,personal" --rpc --nodiscover --nodekey ./data/nodekey --cbft.blskey ./data/blskey & > ./data/platon.log 2>&1 &

When succeed in excuting the command of nohup, press enter again to ensure that the process does not exit because the terminal is closed by mistake.

  • Check the running status of the node
platon attach http://localhost:6789 --exec platon.blockNumber

Execute the above command several times. If the block height keeps growing, the single-node private chain deployment is successful.

Cluster Deployment#

PlatON cluster is a private chain with multiple nodes. Here we assume that you can already build a single node. And we will build a network of two nodes on one server.The deployment of more than two nodes is similar.U:

  • Each node instance has a separate data directory (--datadir)
  • Each instance runs on a different port, whether it is a p2p port or an rpc port (--port and --rpcport)
  • Nodes can be interconnected with each other
  • RPC server port is not occupied

1.Create directory

Create directories data0 and data1 under the platon-node directory as the data directories for the two nodes. Generate two coinbase accounts for each node.

mkdir -p ~/platon-node/data0 ~/platon-node/data1

2. Generate key pair

Save the nodekey and blskey of the two nodes to 'data0' and 'data1' respectively.

cd ~/platon-node/data0 && platonkey genkeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ./nodekey) >(grep "PublicKey" | awk '{print $3}' > ./nodeid) && platonkey genblskeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ./blskey) >(grep "PublicKey" | awk '{print $3}' > ./blspub)
cd ~/platon-node/data1 && platonkey genkeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ./nodekey) >(grep "PublicKey" | awk '{print $3}' > ./nodeid) && platonkey genblskeypair | tee >(grep "PrivateKey" | awk '{print $2}' > ./blskey) >(grep "PublicKey" | awk '{print $3}' > ./blspub)

3. Editing genesis files

Modify the genesis block configuration file platon.json.

Add the node information of the two nodes to the initialNodes array, which is 2 because we are generating a two-node cluster environment.The platon.json file needs to be modified: please replace the contents of the following files 'node0-nodekey ', 'node1-nodekey', 'node0-blspubkey' and 'node1-blspubkey' with the node public key and node BLS public key generated in the previous step.Replace 'your account-address' with the wallet address.

……  "cbft": {  "initialNodes": [{        "node": "enode://node0-pubkey@127.0.0.1:16789",        "blsPubKey": "node0-blspubkey"    },{        "node": "enode://node1-pubkey@127.0.0.1:16790",        "blsPubKey": "node1-blspubkey"    }],    ……  "alloc": {    "your-account-address": {        "balance": "999000000000000000000"    },    "1000000000000000000000000000000000000003": {        "balance": "200000000000000000000000000"    }  },……

4. Initialization and startup

Initialize genesis block information for node 0 and node 1, respectively:

platon --datadir ~/platon-node/data0 init platon.json && platon --datadir ~/platon-node/data1 init platon.json

After successful initialization, start node 0 and node 1 in nohup mode:

cd ~/platon-node && nohup platon --identity "platon0" --datadir ./data0 --port 16789 --rpcaddr 0.0.0.0 --rpcport 6789 --rpcapi "db,platon,net,web3,admin,personal" --rpc --nodiscover --nodekey ./data0/nodekey --cbft.blskey ./data0/blskey > ./data0/platon.log 2>&1 &
cd ~/platon-node && nohup platon --identity "platon1" --datadir ./data1 --port 16790 --rpcaddr 0.0.0.0 --rpcport 6790 --rpcapi "db,platon,net,web3,admin,personal" --rpc --nodiscover --nodekey ./data1/nodekey --cbft.blskey ./data1/blskey  > ./data1/platon.log 2>&1 &

5. Check

Go to the platon console for any node as described above to see if the node is connected to its counterpart and to see if the cluster has started successfully by seeing if blockNumber continues to grow.

platon attach http://localhost:6789 --exec platon.blockNumberplaton attach http://localhost:6790 --exec platon.blockNumber

Do this multiple times and watch if the block height increases.