1.服务器准备
这次测试网准备了3台服务器,分别命名为node-1,node-2和node-3,条件允许的话可以准备更多台。
服务器使用ubuntu 16.4 LTS版本,是编译最方便的linux版本,具体的编译方法参见《在ubuntu上编译比特股核心代码》
新建testnet目录,将witness_node文件拷贝到testnet目录
mkdir /testnet
cp program/witness_node/witness_node /testnet/
2.生成秘钥对和地址
programs/genesis_util/get_dev_key BTS w1 w2 w3 admin
运行以上命令会生成四对秘钥对和地址,分别对应w1,w2,w3和admin的私钥、公钥和地址如下
[{"private_key":"5JjzogP6V1TciYQHthBLPnmj5cyrYLfwfoDeY6rpG4mcNUd7hDq","public_key":"BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm","address":"BTSMZq4SyNoFGraCNuV5ZjbJHMvcYBLSV3rM"},
{"private_key":"5JpX8v4y7HQ9EXLRGPXcPCVCqw5BLzP2drAbwJ94P3QXFxxwzkw","public_key":"BTS8ftmc4mCUjnR43SPtQFg8xuJgUr82MKuBjvegrmdDasohZcpZw","address":"BTSP1gitSEvGzCLCa9rsCCfQiRSzNQquDUxX"},
{"private_key":"5HtEtfFYt1eGpE6uVWMyzMXzh8BBYfPyfH2A8Q8FQvXgdFXsc7N","public_key":"BTS7hKorE5txmsT6qee9NNqcYqNvBU1Umxk1cV93Q1XPEbYCacpfM","address":"BTSCSSgBtAUAGkhFbo6rbUMqtNTJteWaxHdG"},
{"private_key":"5KNP4D9K3FL1gBtRtanhfgLZTpz1wcJVsLEQXonRMeAwzMDL2se","public_key":"BTS51ABY2MWbn3W5NNW3JNJRDraEi4JbzEAmBa3jiTQJ7f99Z7xJ6","address":"BTS21sMK9h93c1i29wLKi29xqKxqjvLSEarw"}]
3.初始化创始区块配置文件
cd /tesnet
./witness_node --create-genesis-json testnet.json
编辑testnet.json文件
vim testnet.json
找到initial_accounts一节,修改初始账号的名称和公钥,将初始的11个witness账号都改成w1对应的公钥,如下:
{
"name": "w1-0",
"owner_key": "BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm",
"active_key": "BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm",
"is_lifetime_member": true
}
修改初始账号中nathan用户的名称和公钥,如下
{
"name": "admin",
"owner_key": "BTS51ABY2MWbn3W5NNW3JNJRDraEi4JbzEAmBa3jiTQJ7f99Z7xJ6",
"active_key": "BTS51ABY2MWbn3W5NNW3JNJRDraEi4JbzEAmBa3jiTQJ7f99Z7xJ6",
"is_lifetime_member": true
}
找到initial_balances一节,修改初始账号余额,这里我们把所有的核心资产都交给admin用户,如下:
{
"owner": "BTS21sMK9h93c1i29wLKi29xqKxqjvLSEarw", //填写admin的address
"asset_symbol": "BTS",
"amount": "1000000000000000"
}
找到initial_witness_candidates一节,修改初始的witness见证人,如下
{
"owner_name": "w1-0",
"block_signing_key": "BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm" //公钥
}
找到initial_committee_candidates,修改初始的委员会成员,如下
{
"owner_name": "w1-0"
}
保存退出
3.初始化创世区块和配置文件
运行以下命令,初始化创世区块
./witness_node --data-dir data --genesis-json test-net.json
这一步会新建data目录,并且运行到最后会打印出chain-id,这时候ctrl-c停止程序运行,并且记录chain-id备用。
打开data目录下的config.ini文件
vim data/config.ini
修改如下:
p2p-endpoint = 0.0.0.0:10101 //seed节点的ip和端口,端口可以自定义
rpc-endpoint = 0.0.0.0:11011 //rpc的ip和端口
genesis-json = testnet.json
enable-stale-production = true
witness-id = "1.6.1"
...
witness-id = "1.6.11"
private-keys = ["BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm","5JjzogP6V1TciYQHthBLPnmj5cyrYLfwfoDeY6rpG4mcNUd7hDq"] //公钥、私钥对
debug-private-keys = ["BTS6WqFcNmb8DA8SG2HJDL23TzSKk67HrCf6qTeqXhbCcohi11epm","5JjzogP6V1TciYQHthBLPnmj5cyrYLfwfoDeY6rpG4mcNUd7hDq"] //公钥、私钥对
保存退出
4.运行网络中的第一个节点
./witness_node --data-dir data
看到不断的产生区块就成功了,第一个节点就运行完毕了。
5.往网络中加入新的节点
复制前面的witness_node文件和testnet.json文件到node-2和node-3
运行以下命令
./witness_node --data-dir data --genesis-json testnet.json -s [node1的ip或域名]:10101
看到接收到新的区块就大功告成了。
经过以上步骤,我们就搭建了一个有3个节点的比特股网络,但是现在所有的witness都在node-1上,一旦node-1死机或者离线,网络就无法正常运转,接下去我们要将node-2和node-3也变成witness节点,具体的敬请期待《搭建你自己的比特股测试网下篇》
比特股开发系列文章
网友评论
```
3523973ms th_a application.cpp:1038 startup ] 11 eof_exception: End Of File
stringstream
{}
th_a sstream.cpp:66 readsome
{"str":""}
th_a json.cpp:463 from_string
rethrow
{"data_dir":"/data/bitshares/testnet/data/blockchain"}
th_a db_management.cpp:190 open
rethrow
{}
th_a application.cpp:452 startup
3523973ms th_a main.cpp:282 main ] Exiting with error:
11 eof_exception: End Of File
stringstream
{}
th_a sstream.cpp:66 readsome
{"str":""}
th_a json.cpp:463 from_string
rethrow
{"data_dir":"/data/bitshares/testnet/data/blockchain"}
th_a db_management.cpp:190 open
rethrow
{}
th_a application.cpp:452 startup
Segmentation fault (core dumped)
```
windows下找不到这些,这是哪个目录和命令呢?第一个测试网络的账户名和密码不是只有Nathan吗?