【教程系列】教你如何在本地搭建hpb私链


#1

如果想进行DAPP 开发,那么在本地搭建一个测试链是非常方便划算的!直接部署到主链将会消耗代币以及很多不便,下面是搭建HPB测试链的详细步骤!
有任何不懂的都可以回复,也望各位大佬指正!

测试链本地搭建步骤

下表为完整的本地搭建测试链步骤。

编号 步骤 内容 说明
1 确定程序执行路径 确定程序执行路径 命令:sudo mkdir /home/ghpb-bin2
提示:/home/ghpb-bin2可改为指定路径。
2 切换成ROOT用户 切换成ROOT用户 命令:su root
根据提示输入ROOT账户密码
3 选择下载路径 选择下载路径 命令:cd /home/
提示:/home/可改为指定路径;
4 下载go-hpb源码 下载go-hpb源码 命令:sudo git clone -b version_x.x.x.x https://github.com/hpb-project/go-hpb
提示:x.x.x.x为主网程序最新版本号
5 编译源码 编译源码 命令:cd go-hpb/
命令:make all
6 拷贝程序到执行路径 拷贝程序到执行路径 命令:sudo cp build/bin/. /home/ghpb-bin2/
进入执行路径 命令:cd /home/ghpb-bin2/
7 创建新账户 创建第一个账户 命令:./ghpb --datadir node/data account new
根据提示设置账户密码并记录账户地址
创建第二个账户 命令:./ghpb --datadir node1/data account new
根据提示设置账户密码并记录账户地址
创建第三个账户 命令:./ghpb --datadir node2/data account new
根据提示设置账户密码并记录账户地址
8 生成创世区块 产生创世文件 命令:./promfile
根据提示以及示例完成生成步骤
9 初始化节点 初始化第一个节点 命令:./ghpb --datadir node/data init gensis.json
初始化第二个节点 命令:./ghpb --datadir node1/data init gensis.json
初始化第三个节点 命令:./ghpb --datadir node2/data init gensis.json
10 启动bootnode 启动bootnode 启动之前需参照示例拷贝binding.json文件。
命令:./ghpb --datadir node1/data --networkid 66300 --port 3001 --nodetype bootnode console
提示:66300为创建创世区块过程中用户设置的网络号,3001为端口号,在一台机器上启动不同节点时端口号需不同)
11 打开配置文件 打开配置文件 命令:exit
命令:vi /home/go-hpb/config/networkconfig.go
12 将hnode写入配置文件 将hnode写入配置文件 在var MainnetBootnodes中输入hnode信息(含公网ip);并在其余hnode信息前都输入//以注释掉不需要的hnode信息。
13 保存配置文件 保存配置文件 按下Esc,并输入:wq
14 编译源码 编译源码 命令:cd /home/go-hpb/
提示:/home/为go-hpb的下载路径.
命令:make all
15 拷贝到程序执行路径 拷贝到程序执行路径 命令:sudo cp build/bin/. /home/ghpb-bin2/
命令:cd /home/ghpb-bin2/
16 启动节点 启动bootnode 命令:sudo nohup ./ghpb --datadir node1/data --networkid 66300 --port 3001 --rpcaddr 0.0.0.0 --rpcport 8541 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net --nodetype bootnode . bootnode.log &
命令: sudo ./ghpb attach http://127.0.0.1:8541
启动第一个挖矿节点 命令:sudo ./ghpb --datadir node/data --unlock "第一个账户地址" --networkid 66300 --port 3002 --rpcaddr 0.0.0.0 --rpcport 8542 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net console --testmode
根据提示输入账户密码(需另开控制台窗口执行该命令);
命令:miner.start()
启动第二个挖矿节点 命令:sudo ./ghpb --datadir node2/data --unlock "第三个账户地址" --networkid 66300 --port 3003 --rpcaddr 0.0.0.0 --rpcport 8543 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net console --testmode
根据提示输入账户密码(需另开控制台窗口执行该命令);
命令:miner.start()

测试链本地搭建示例

(1)确定程序执行路径

输入sudo mkdir /home/ghpb-bin2创建程序执行路径;其中/home/ghpb-bin2可改为指定路径。

hpb@ dell-PowerEdge-R730:~$ sudo mkdir /home/ghpb-bin2
(2)切换成ROOT用户

输入su root,根据提示输入ROOT账户密码。

hpb@ dell-PowerEdge-R730:~$ su root
Password:
(3)选择下载路径

输入 cd /home/;其中/home/可改为指定路径;

root@ dell-PowerEdge-R730: ~$ cd /home/
(4)下载go-hpb源码

输入sudo git clone -b version_x.x.x.x https://github.com/hpb-project/go-hpb,当进度变为100%,出现"Checking conectivity … done"时,go-hpb下载成功,继续下一步;(x.x.x.x为主网程序最新版本号)

root@dell-PowerEdge-R730:/home# sudo git clone -b version_1.0.1.0 https://github.com/hpb-project/go-hpb
Cloning into 'go-hpb'...
remote: Counting objects: 10547, done.
remote: Compressing objects: 100% (150/150), done.
Receiving objects: 100% (10547/10547), 14.09 MiB | 395.00 KiB/s, done.
Resolving deltas: 100% (5824/5824), done.
Checking connectivity... done.
Note: checking out '89d88c8e23f7761a76dd8eebe9b08fd3750a04b6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>
(5)编译go-hpb

输入cd go-hpb/

继续输入make all编译go-hpb;

root@ dell-PowerEdge-R730:/home# cd go-hpb/
root@ dell-PowerEdge-R730:/home/go-hpb# make all
build/env.sh go run build/ci.go install ./cmd/ghpb
>>> /usr/lib/go-1.9/bin/go install -ldflags -X main.gitCommit=04fa6c874b447f0de0a4296b9e573119e1997fcc -v ./cmd/ghpb
github.com/hpb-project/go-hpb/vendor/github.com/prometheus/procfs/internal/util
github.com/hpb-project/go-hpb/common/bitutil
……
Done building.
Run "/home/go-hpb/build/bin/promfile" to launch promfile.
(6)拷贝程序到执行路径

输入sudo cp build/bin/. /home/ghpb-bin2/;继续输入cd /home/ghpb-bin2/。 其中/home/ghpb-bin2/为您设置的程序执行路径;

root@ dell-PowerEdge-R730:/home/go-hpb# sudo cp build/bin/* /home/ghpb-bin2/
root@ dell-PowerEdge-R730:/home/go-hpb#cd /home/ghpb-bin2/
(7)创建三个新账户
  • 输入./ghpb --datadir node/data account new创建第一个新账户,根据提示设置账户密码,记录得到的账户地址"04cbf60fdcc485a76b0b8a389da7bd87da180edd"。
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./ghpb --datadir node/data account new
INFO [09-19|08:21:43]  HPB : Create New HpbConfig object 
INFO [09-19|08:21:43]  HPB : Initialising Hpb node             network=1
INFO [09-19|08:21:43]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node/data/ghpb/chaindata cache=128 handles=1024
INFO [09-19|08:21:46]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {04cbf60fdcc485a76b0b8a389da7bd87da180edd}
  • 输入./ghpb --datadir node1/data account new 创建第二个新账户,根据提示设置账户密码,记录得到的账户地址"af4a70602be17074ad59555fa09239c0d811a99f"。
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./ghpb --datadir node1/data account new
INFO [09-19|08:26:17]  HPB : Create New HpbConfig object 
INFO [09-19|08:26:17]  HPB : Initialising Hpb node             network=1
INFO [09-19|08:26:17]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node1/data/ghpb/chaindata cache=128 handles=1024
INFO [09-19|08:26:20]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {af4a70602be17074ad59555fa09239c0d811a99f}
  • 输入./ghpb --datadir node2/data account new 创建第三个新账户,根据提示设置账户密码,记录得到的账户地址"552a49773698c75b7fbb47f1a3486f6394cc4385"。
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./ghpb --datadir node2/data account new 
INFO [09-19|08:28:33]  HPB : Create New HpbConfig object 
INFO [09-19|08:28:33]  HPB : Initialising Hpb node             network=1
INFO [09-19|08:28:33]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node2/data/ghpb/chaindata cache=128 handles=1024
INFO [09-19|08:28:36]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {552a49773698c75b7fbb47f1a3486f6394cc4385}
(8)生成创世区块

输入./promfile,根据提示完成创世区块的设置。

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./promfile
+-----------------------------------------------------------+
| Welcome to prometh, your HPB private network manager |
|                                                           |
| This tool lets you create a new HPB network down to  |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail.         |
|                                                           |
| Prometh uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset.                                   |
+-----------------------------------------------------------+
Please specify a network name to administer (no spaces, please)
> random`(给测试链命名,可随意命名,如random)
Sweet, you can set this via --network=random next time!
INFO [09-19|08:36:16]  HPB : Administering HPB network         name=random
WARN [09-19|08:36:16]  HPB : No previous configurations found  path=/root/.prometh/random
What would you like to do? (default = stats)
 1. Configure new genesis
 2. Manage existing genesis
> 1`(选择1,生成新的创世文件)

Welcome to HPB consensus engine file maker

How many seconds should blocks take? (default = 15)
> 5`(设置生成区块的间隔,如5)

How many blocks should voting epoch be ? (default = 30000)
> 100`(设置投票周期,如100)

Which accounts are allowed to seal? (initialise miner addresses)
> 0x04cbf60fdcc485a76b0b8a389da7bd87da180edd(设置初始挖矿地址,示例为新建的第一个账户)
> 0x`(可继续添加挖矿地址,按回车可进入下一步)

Which accounts should be pre-funded? (advisable at least one)
> 0x04cbf60fdcc485a76b0b8a389da7bd87da180edd(设置初始预存钱的地址,示例为新建的第一个账户)
> 0x`(可继续添加预存钱地址,按回车可进入下一步)

Please input the initialization hardware random
> 0x `(按回车直接进入下一步)      

Specify your chain/network ID if you want an explicit one (default = random)
> 66300`(设置网络号,可随意设置,后续启动命令中需用到该网络号) 

Anything fun to embed into the genesis block? (max 32 bytes)
> hhh`(可输入任意字符串,以示有趣)

What would you like to do? (default = stats)
 1. Configure new genesis
 2. Manage existing genesis
> 2`(选择2,导出刚设置的创世文件)

 1. Export genesis configuration
> 1`(选择1,将会打印出json文件,需在最后输入名称“gensis.json”)

Which file to save the genesis into? (default = random.json)
{
  "config": {
    "chainId": 66300,
    "prometheus": {
      "period": 5,
      "epoch": 100
    }
  },
  "nonce": "0x0",
  "timestamp": "0x5ba242c8",
  "extraData": "0x686868000000000000000000000000000000000000000000000000000000000004cbf60fdcc485a76b0b8a389da7bd87da180edd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x5f5e100",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "04cbf60fdcc485a76b0b8a389da7bd87da180edd": {
      "balance": "0x8"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "hardwareRandom": "0x0000000000000000000000000000000000000000000000000000000000000000"
}> gensis.json`(在此处输入名称“gensis.json”,并回车)
INFO [09-19|08:59:36]  HPB : Exported existing genesis block 

What would you like to do? (default = stats)
 1. Configure new genesis
 2. Manage existing genesis
> 

ctrl+c退出,输入ls可看到已导出创世文件gensis.json

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ls
binding.json  gensis.json   node   node2
config.json   ghpb         iperf3  node1  promfile
(9)初始化节点
  • 输入./ghpb --datadir node/data init gensis.json初始化第一个节点;
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2#  ./ghpb --datadir node/data init gensis.json
INFO [09-19|09:08:22]  HPB : Create New HpbConfig object 
INFO [09-19|09:08:22]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node/data/ghpb/chaindata cache=16 handles=16
INFO [09-19|09:08:22]  HPB : Writing custom genesis block 
INFO [09-19|09:08:22]  HPB : Successfully wrote genesis state  database=chaindata                                hash=e46058…896936
  • 输入./ghpb --datadir node1/data init gensis.json初始化第二个节点;
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2#  ./ghpb --datadir node1/data init gensis.json
INFO [09-19|09:08:53]  HPB : Create New HpbConfig object 
INFO [09-19|09:08:53]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node1/data/ghpb/chaindata cache=16 handles=16
INFO [09-19|09:08:53]  HPB : Writing custom genesis block 
INFO [09-19|09:08:53]  HPB : Successfully wrote genesis state  database=chaindata                                 hash=e46058…896936
  • 输入./ghpb --datadir node2/data init gensis.json初始化第三个节点;
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./ghpb --datadir node2/data init gensis.json
INFO [09-19|09:10:05]  HPB : Create New HpbConfig object 
INFO [09-19|09:10:05]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node2/data/ghpb/chaindata cache=16 handles=16
INFO [09-19|09:10:05]  HPB : Writing custom genesis block 
INFO [09-19|09:10:05]  HPB : Successfully wrote genesis state  database=chaindata                                 hash=e46058…896936
(10)启动bootnode
  • 配置binding.json

    输入vim binding.json将所有账户写入binding.json,

    root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# vim binding.json
    

    在打开的文件中按下I变为Insert可输入状态,并粘贴以下代码:

    (用户需将三个coinbase更改为三个新建账户的地址,CID和HID可随意填写,可与示例中的保持一致。)

    [    {"coinbase":"0xfc6661501b4faf424d2ed61855a134fa5b2de3ef","cid":"2cd504a93518fe0c9b60895602586efc4786cf9da9396d0a6d39403b94710b0a16092dcbd8458bb46cef1e71ba9953db881268ce5d773ce63ffb421a657a00e1","hid":"a3b8e1f3bd9cf3ed0a520744010bf2cc48e781b04af7f462e452f9c96e476abc"},    {"coinbase":"0xaf4a70602be17074ad59555fa09239c0d811a99f","cid":"2cd504a93518fe0c9b60895602586efc4786cf9da9396d0a6d39403b94710b0a16092dcbd8458bb46cef1e71ba9953db881268ce5d773ce63ffb421a657a00e1","hid":"a3b8e1f3bd9cf3ed0a520744010bf2cc48e781b04af7f462e452f9c96e476abc"},    {"coinbase":"0x552a49773698c75b7fbb47f1a3486f6394cc4385","cid":"2cd504a93518fe0c9b60895602586efc4786cf9da9396d0a6d39403b94710b0a16092dcbd8458bb46cef1e71ba9953db881268ce5d773ce63ffb421a657a00e1","hid":"a3b8e1f3bd9cf3ed0a520744010bf2cc48e781b04af7f462e452f9c96e476abc"}                                                                                                                                                     ]
    
    

    按下Esc键并输入:wq即可保存文件并退出。

  • 拷贝binding.json

    输入cp binding.json node1/data拷贝binding.json到bootnode数据文件里。

    root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# cp binding.json node1/data 
    
  • 启动bootnode

输入./ghpb --datadir node1/data --networkid 66300 --port 3001 --nodetype bootnode console;(66300为创建创世区块过程中设置的网络号,3001为端口号,不同节点不同以作区分)

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# ./ghpb --datadir node1/data --networkid 66300 --port 3001 --nodetype bootnode console
INFO [09-19|09:23:23]  HPB : Create New HpbConfig object 
INFO [09-19|09:23:23]  HPB : Initialising Hpb node             network=66300
INFO [09-19|09:23:23]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node/data/ghpb/chaindata cache=128 handles=1024
INFO [09-19|09:23:26]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
INFO [09-19|09:23:26]  HPB : Loaded most recent local header   number=0 hash=e46058…896936 td=1
INFO [09-19|09:23:26]  HPB : Loaded most recent local full block number=0 hash=e46058…896936 td=1
INFO [09-19|09:23:26]  HPB : Loaded most recent local fast block number=0 hash=e46058…896936 td=1
INFO [09-19|09:23:26]  HPB : Set coinbase address by start     address=0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
INFO [09-19|09:23:26]  HPB : Change node local type            from=UnknownNode to=BootNode
INFO [09-19|09:23:26]  HPB : Set Init Local Type by p2p        type=BootNode
INFO [09-19|09:23:26]  HPB : Starting P2P networking 
INFO [09-19|09:23:28]  HPB : UDP listener up                   self=hnode://ad65b8d7efc85c50b13f63a0a7234d1398136a200dbe104ff759daf7912fe7ce2c996db38135883599e0802f24849c2e1e5ee4502d401e6b39823552dba331a9@[::]:3001(记录打印出的hnode信息)
INFO [09-19|09:23:28]  HPB : Server start with type.           NodeType=BootNode
INFO [09-19|09:23:28]  HPB : Start server of bandwidth test.   port=3101
ERROR[09-19|09:23:28]  HPB : Can't load node file /home/ghpb-bin2/node/data/binding.json: open /home/ghpb-bin2/node/data/binding.json: no such file or directory 
INFO [09-19|09:23:28]  HPB : IPC endpoint opened: /home/ghpb-bin2/node/data/ghpb.ipc 
Welcome to the GHPB JavaScript console!
instance: 
coinbase: 0xfc6661501b4faf424d2ed61855a134fa5b2de3ef
at block: 0 (Wed, 19 Sep 2018 08:57:13 EDT)
 datadir: /home/ghpb-bin2/node/data
 modules: admin:1.0 debug:1.0 hpb:1.0 miner:1.0 net:1.0 personal:1.0 prometheus:1.0 rpc:1.0 txpool:1.0 web3:1.0

记录hnode信息,并在端口号前添加公网ip(公网Ip即为bootnode所在服务器的公网ip地址,示例中为192.168.1.50,开发者需改为自己的公网Ip): hnode://ad65b8d7efc85c50b13f63a0a7234d1398136a200dbe104ff759daf7912fe7ce2c996db38135883599e0802f24849c2e1e5ee4502d401e6b39823552dba331a9@192.168.1.50:3001

(11)打开配置文件

输入exit退出,继续输入vi /home/go-hpb/config/networkconfig.go打开配置文件;

> exit
INFO [09-19|09:31:32]  HPB : Hpb data sync stopped 
root@hpb-PowerEdge-R730xd:/home/ghpb-bin# vi /home/go-hpb/config/networkconfig.go
(12)将hnode写入配置文件

在打开的文件中找到var MainnetBootnodes方法,在该方法中输入hnode信息(含公网ip);并在其余hnode信息前都输入//,表示注释掉不需要的hnode信息。

提示:将光标移到方法里的第一行,按下字母o,即自动插入空的一行,此时即可粘贴hnode信息,注意带上双引号和逗号,格式为英文。

var MainnetBootnodes = []string{
        //"hnode://73c8ac9dddc8f094d28f42e1ec5c3e8000cad25be152c147fceacc27953d58e64bfe9f555145d93f9f6b995bab984411941751fef3bd460f74c0151eb0432b56@47.94.20.30:30303",

"hnode://ad65b8d7efc85c50b13f63a0a7234d1398136a200dbe104ff759daf7912fe7ce2c996db38135883599e0802f24849c2e1e5ee4502d401e6b39823552dba331a9@192.168.1.50:3001",(粘贴hnode信息)
        //"hnode://1c129009d0e9c56e79b6f4157497d8ac2810ea83fc1f6ed4b6244406597d821f52bb0d210157854d861d2f6099fa948bc5a03d2f4f1bcae70dc6e9c535e586f9@47.100.250.120:30303",
      //"hnode://f3282847f29cfea1dd741246cc17b9a0dcdd8b0b9dfce2a985d2358497458135e81942ae7155cfd2fe23e1da30f18fc1fa2c56d3675aba51e7c67f83681fded5@47.75.213.166:30303",
        //"hnode://dd2fd6ea314041c0e20aed4ee4159ab172a4ddb944459d147bdb28461937841ee069c44fe0915be9f74d929562968fb9720362937a898e2ec3a598fa3fe1f33b@47.88.60.227:30303",
        //"hnode://a6ef92a46adb69f94f2d48ff20f7800fb057d6aba7945e5af062ef27be5598072c5ce083ec5a2c89f80d112401c261b9ba9dacbd53aeb7c8243685d537edadb9@47.254.133.46:30303",
}
(13)保存配置文件

按下Esc,并输入:wq,回车即可保存。 提示:如果想退出不保存文件,则需按下Esc,并输入:q!回车即可;如果无法编辑, 可按下字母i即可。

:wq
(14)编译源码

输入cd /home/go-hpb/,其中/home/为go-hpb的下载路径;继续输入make all编译。

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# cd /home/go-hpb/
root@hpb-PowerEdge-R730xd:/home/go-hpb# make all
build/env.sh go run build/ci.go install ./cmd/ghpb
>>> /usr/lib/go-1.9/bin/go install -ldflags -X main.gitCommit=89d88c8e23f7761a76dd8eebe9b08fd3750a04b6 -v ./cmd/ghpb
github.com/hpb-project/go-hpb/vendor/golang.org/x/text/encoding/internal/identifier
...
Done building.
Run "/home/go-hpb/build/bin/promfile" to launch promfile.
cp "/home/go-hpb/network/iperf3/iperf3" "/home/go-hpb/build/bin/iperf3"
cp "/home/go-hpb/network/p2p/binding.json" "/home/go-hpb/build/bin/binding.json"
cp "/home/go-hpb/network/p2p/config.json" "/home/go-hpb/build/bin/config.json"
(15)拷贝到程序执行路径

输入sudo cp build/bin/. /home/ghpb-bin2/;.继续输入cd /home/ghpb-bin2/。 其中/home/ghpb-bin2/为您设置的程序执行路径;

root@hpb-PowerEdge-R730xd:/home/go-hpb# sudo cp build/bin/* /home/ghpb-bin2/
root@hpb-PowerEdge-R730xd:/home/go-hpb# cd /home/ghpb-bin2/
(16)启动节点
  • 启动bootnode

输入sudo nohup ./ghpb --datadir node1/data --networkid 66300 --port 3001 --rpcaddr 0.0.0.0 --rpcport 8541 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net --nodetype bootnode . bootnode.log &启动bootnode; 继续输入sudo ./ghpb attach http://127.0.0.1:8541连入节点。 示例里为创建的第二个账户;

提示:66300为步骤8中设置的网络号。

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# sudo nohup ./ghpb --datadir node1/data --networkid 66300 --port 3001  --rpcaddr 0.0.0.0 --rpcport 8541  --verbosity  3  --rpc  --rpcapi    hpb,web3,admin,txpool,debug,personal,net --nodetype bootnode > bootnode.log &
[1] 29938
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# nohup: ignoring input and redirecting stderr to stdout
root@hpb-PowerEdge-R730xd:/home/ghpb-bin2# sudo ./ghpb attach http://127.0.0.1:8541
Welcome to the GHPB JavaScript console!
instance: 
coinbase: 0xfc6661501b4faf424d2ed61855a134fa5b2de3ef
at block: 0 (Wed, 19 Sep 2018 08:57:13 EDT)
 datadir: /home/ghpb-bin2/node1/data
 modules: admin:1.0 debug:1.0 hpb:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>

• 启动第一个挖矿节点
另开一个控制台窗口输入sudo ./ghpb --datadir node/data --unlock “第一个账户地址” --networkid 66300 --port 3002 --rpcaddr 0.0.0.0 --rpcport 8542 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net console --testmode根据提示输入账户密码; 继续输入miner.start()开始挖矿。 示例里为创建的第一个账户“0x04cbf60fdcc485a76b0b8a389da7bd87da180edd”;

 root@hpb-PowerEdge-R730xd:/home/ghpb-bin2#sudo ./ghpb --datadir node/data  --unlock "0x04cbf60fdcc485a76b0b8a389da7bd87da180edd" --networkid 66300 --port 3002  --rpcaddr 0.0.0.0 --rpcport 8542  --verbosity  3  --rpc  --rpcapi    hpb,web3,admin,txpool,debug,personal,net console --testmode
 INFO [09-19|22:59:21]  HPB : Create New HpbConfig object 
 INFO [09-19|22:59:21]  HPB : Initialising Hpb node             network=66300
 INFO [09-19|22:59:21]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node/data/ghpb/chaindata cache=128 handles=1024
 INFO [09-19|22:59:25]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
 Unlocking account 0x04cbf60fdcc485a76b0b8a389da7bd87da180edd | Attempt 1/3
 Passphrase: 
 ERROR[09-19|22:59:28]  HPB : ---------the password file is     : =123
 INFO [09-19|22:59:29]  HPB : Unlocked account                  address=0x04CbF60FdCc485a76b0B8a389Da7BD87dA180eDd
 INFO [09-19|22:59:29]  HPB : Loaded most recent local header   number=0 hash=e46058…896936 td=1
 INFO [09-19|22:59:29]  HPB : Loaded most recent local full block number=0 hash=e46058…896936 td=1
 INFO [09-19|22:59:29]  HPB : Loaded most recent local fast block number=0 hash=e46058…896936 td=1
 INFO [09-19|22:59:29]  HPB : Set coinbase address by start     address=0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
 INFO [09-19|22:59:29]  HPB : Change node local type            from=UnknownNode to=PreNode
 INFO [09-19|22:59:29]  HPB : Set Init Local Type by p2p        type=PreNode
 INFO [09-19|22:59:29]  HPB : Starting P2P networking 
 INFO [09-19|22:59:31]  HPB : UDP listener up                   self=hnode://edab938abbc31c4c94a55123d4384739ccbfa525f60269a96ec78196b498b47798c874fb3be6af4cde08ad18fba8e14936c20374fab7c6e3ad0bf5d1816c5ae5@[::]:3002
 WARN [09-19|22:59:31]  HPB : Can't load file /home/ghpb-bin2/synnode.json: open /home/ghpb-bin2/synnode.json: no such file or directory 
 INFO [09-19|22:59:31]  HPB : Server start with type.           NodeType=PreNode
 INFO [09-19|22:59:31]  HPB : Start server of bandwidth test.   port=3102
 INFO [09-19|22:59:31]  HPB : IPC endpoint opened: /home/ghpb-bin2/node/data/ghpb.ipc 
 INFO [09-19|22:59:31]  HPB : HTTP endpoint opened: http://0.0.0.0:8542 
 Welcome to the GHPB JavaScript console!
 
 instance: 
 coinbase: 0xfc6661501b4faf424d2ed61855a134fa5b2de3ef
 at block: 0 (Wed, 19 Sep 2018 08:57:13 EDT)
  datadir: /home/ghpb-bin2/node/data
  modules: admin:1.0 debug:1.0 hpb:1.0 miner:1.0 net:1.0 personal:1.0 prometheus:1.0 rpc:1.0 txpool:1.0 web3:1.0

 > miner.start()
 INFO [09-20|02:51:23]  HPB : miner start : : 
 INFO [09-20|02:51:23]  HPB : Transaction pool price threshold updated price=18000000000
INFO [09-20|02:51:23]  HPB : Starting mining operation 
 null
  • 启动第二个挖矿节点

另开一个控制台窗口输入sudo ./ghpb --datadir node2/data --unlock “第三个账户地址” --networkid 66300 --port 3003 --rpcaddr 0.0.0.0 --rpcport 8543 --verbosity 3 --rpc --rpcapi hpb,web3,admin,txpool,debug,personal,net console --testmode根据提示输入账户密码;

继续输入miner.start()开始挖矿。示例里为创建的第三个账户 “0x552a49773698c75b7fbb47f1a3486f6394cc4385”(注意加上0x前缀);

root@hpb-PowerEdge-R730xd:/home/ghpb-bin2#sudo ./ghpb --datadir node2/data  --unlock "0x552a49773698c75b7fbb47f1a3486f6394cc4385" --networkid 66300 --port 3003  --rpcaddr 0.0.0.0 --rpcport 8543  --verbosity  3  --rpc  --rpcapi    hpb,web3,admin,txpool,debug,personal,net console --testmode
INFO [09-19|22:43:55]  HPB : Create New HpbConfig object 
INFO [09-19|22:43:55]  HPB : Initialising Hpb node             network=66300
INFO [09-19|22:43:55]  HPB : Allocated cache and file handles  database=/home/ghpb-bin2/node2/data/ghpb/chaindata cache=128 handles=1024
INFO [09-19|22:43:58]  HPB : set coinbase of node              : =0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
Unlocking account 0x552a49773698c75b7fbb47f1a3486f6394cc4385 | Attempt 1/3
Passphrase: 
ERROR[09-19|22:44:00]  HPB : ---------the password file is     : =123
INFO [09-19|22:44:01]  HPB : Unlocked account                  address=0x552a49773698c75b7fbb47f1a3486f6394cC4385
INFO [09-19|22:44:01]  HPB : Loaded most recent local header   number=0 hash=e46058…896936 td=1
INFO [09-19|22:44:01]  HPB : Loaded most recent local full block number=0 hash=e46058…896936 td=1
INFO [09-19|22:44:01]  HPB : Loaded most recent local fast block number=0 hash=e46058…896936 td=1
INFO [09-19|22:44:01]  HPB : Set coinbase address by start     address=0xfc6661501B4faf424D2ed61855A134fa5b2dE3EF
INFO [09-19|22:44:01]  HPB : Change node local type            from=UnknownNode to=PreNode
INFO [09-19|22:44:01]  HPB : Set Init Local Type by p2p        type=PreNode
INFO [09-19|22:44:01]  HPB : Starting P2P networking 
INFO [09-19|22:44:03]  HPB : UDP listener up                   self=hnode://24eae2a34e82cfb520d508c54f9a06e0951f37a78455f418296bbe011a1bd2e24b386758bbe45ad39e648d1ec375f438a45af2ec6796b7576c5dd4732ea5cccc@[::]:3003
WARN [09-19|22:44:03]  HPB : Can't load file /home/ghpb-bin2/synnode.json: open /home/ghpb-bin2/synnode.json: no such file or directory 
INFO [09-19|22:44:03]  HPB : Server start with type.           NodeType=PreNode
INFO [09-19|22:44:03]  HPB : Start server of bandwidth test.   port=3103
INFO [09-19|22:44:03]  HPB : IPC endpoint opened: /home/ghpb-bin2/node2/data/ghpb.ipc 
INFO [09-19|22:44:03]  HPB : HTTP endpoint opened: http://0.0.0.0:8543 
Welcome to the GHPB JavaScript console!

instance: 
coinbase: 0xfc6661501b4faf424d2ed61855a134fa5b2de3ef
at block: 0 (Wed, 19 Sep 2018 08:57:13 EDT)
 datadir: /home/ghpb-bin2/node2/data
 modules: admin:1.0 debug:1.0 hpb:1.0 miner:1.0 net:1.0 personal:1.0 prometheus:1.0 rpc:1.0 txpool:1.0 web3:1.0

> INFO [09-19|22:44:05]  HPB : Verify the remote hardware.       id=ad65b8d7efc85c50 result=false
INFO [09-19|22:44:05]  HPB : P2P set init peer remote type prenode (TestMode) id=ad65b8d7efc85c50 port=3001
INFO [09-19|22:44:05]  HPB : Network has register peer to syncer id=ad65b8d7efc85c50 port=3001
INFO [09-19|22:44:05]  HPB : Start hpb message loop.           id=ad65b8d7efc85c50 port=3001

#2

描述很清楚,排版也美观!非常实用的一篇技术操作文档, 向大佬学习~


#3

黄金作者说的话就是不一样,灌水都如此清新脱俗,学习了!


#4

例子很详细:face_with_raised_eyebrow:


#5

值得学习,还有什么介绍hpb的资料么? :thinking:


#6

:thinking: 介绍hpb的呀,,我回去想想