区块链|NetCloth测试环境搭建--霜之小刀
NetCloth测试环境搭建–霜之小刀
欢迎转载和引用
若有问题请联系请联系
Email : lihn1011@163.com
【区块链|NetCloth测试环境搭建--霜之小刀】
文章目录
- NetCloth测试环境搭建--霜之小刀
- 前言
- 准备工作
- 搭建相关环境
- GIT的安装
- GO环境的安装
- 检查当前go环境
- 安装go环境
- 设置环境变量
- 使环境变量生效
- 源码编译nch节点程序
- 配置节点
- 启动节点同步区块
- 查看节点同步状态
- 成为验证人
- 创建账号
- 设置nchcli环境变量
- 创建验证人
- 查询验证人列表
- 给自己抵押500000unch
- 再次确认验证人状态为活跃验证人
前言 最近看到区块链行业有一个新的公链挺有意思的,官方目前貌似还没有开始宣传,只给提供了一个点对点的加密聊天工具,试了下聊天工具,没有目前还没有微信那么全,但是基本能用了,但其主打是隐私,这块因为客户端还没有开源,不好评价~但是看官网,后面自己搭建聊天服务器,但是服务器的代码和聊天的代码目前还没有开源,不知道啥时候能开源,但是公链的代码已经开源了,我尝试的搭建了一下测试服务器,貌似可以成功!关注其下一步发展
准备工作 我从他们的官网https://www.netcloth.org找到了github的相关地址,也就是在https://github.com/NetCloth/netcloth-chain这里。然后找到了他们的环境搭建文档,https://docs.netcloth.org,本文主要参照该文档。
搭建相关环境 GIT的安装
sudo apt-get update
sudo apt-get install git
GO环境的安装 检查当前go环境
查看golang版本
go version在ubuntu上执行结果如下:
[20:09:04] root:~ # go version
go version go1.12.2 linux/amd64在mac os上执行结果如下:
?~ go version
go version go1.13 darwin/amd64如果版本号低于1.12.2请彻底卸载golang,并将GO相关的path从PATH环境变量中删除
安装go环境
# macOS系统执行如下命令
wget https://dl.google.com/go/go1.12.2.darwin-amd64.tar.gz
tar -xvf go1.12.2.darwin-amd64.tar.gz
mv go /usr/local# ubuntu系统执行如下命令
wget https://dl.google.com/go/go1.12.2.linux-amd64.tar.gz
tar -xvf go1.12.2.linux-amd64.tar.gz
sudo mv go /usr/local
设置环境变量
# 修改~/.bashrc,添加如下:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
export GO111MODULE=on
使环境变量生效
source ~/.bashrc
源码编译nch节点程序
# 获取nch 源码
git clone https://github.com/NetCloth/netcloth-chain.git
cd netcloth-chain && git checkout v1.0.2# 设置goproxy(make install过程会下载依赖的go模块,设置适合自己的代理,大陆用户可以设置以下代理来加快下载速度)
export GOPROXY=https://mirrors.aliyun.com/goproxy/# 安装statik
sudo apt-get update
sudo apt-get install golang-statik# 编译安装
make install# 编译完成后,检查版本号
nchd version
nchcli version
配置节点
nchd init local-nch-1 --chain-id nch-alphanet# 拷贝主节点genesis文件,此处从github下载
wget https://raw.githubusercontent.com/NetCloth/docs/master/alphanet/genesis.json -O~/.nchd/config/genesis.json
如果wget很慢或失败请尝试手动下载文件,地址:https://github.com/NetCloth/docs/blob/master/alphanet/genesis.json修改配置文件:~/.nchd/config/config.toml, 添加主节点seed, 如下:
# Comma separated list of seed nodes to connect to
seeds = "1d71d8f60a20a5a0f379226b092aa56b64348347@18.191.12.61:26656"# Comma separated list of nodes to keep persistent connections to
persistent_peers = "1d71d8f60a20a5a0f379226b092aa56b64348347@18.191.12.61:26656"
启动节点同步区块
# 执行下面的命令后,控制台会打印日志,同步区块
nchd start --log_level "*:debug" --trace
查看节点同步状态
# 打开一个新的终端
curl http://127.0.0.1:26657/status# 输出如下:
{
"jsonrpc": "2.0",
"id": "",
"result": {
"node_info": {
"protocol_version": {
"p2p": "7",
"block": "10",
"app": "0"
},
"id": "204d94d5a6dbf73a89101a0d084c2fb56462963a", //节点id
"listen_addr": "tcp://0.0.0.0:26656", // 节点p2p连接监听地址
"network": "nch-alphanet", //chain-id
"version": "0.32.2",
"channels": "4020212223303800",
"moniker": "local-nch-1", // 节点名称
"other": {
"tx_index": "on",
"rpc_address": "tcp://127.0.0.1:26657"
}
},
"sync_info": {//当前节点信息
"latest_block_hash": "A4E5D60DE7CFB6598846A4131302C8FD28F2697DF2291B33B0892A9EACB562D8", // 最新的区块 hash
"latest_app_hash": "32F0B29280EDF3BEAE98424D9AA256EDBEFC973D1C33431A8D74FCA3BC3B6582",
"latest_block_height": "1489",// 当前节点同步到的最新区块高度//最新区块高度
"latest_block_time": "2019-09-10T05:33:13.428333584Z",//最新区块时间
"catching_up": false
},
"validator_info": { // 验证人信息
"address": "92E0F0A50779E67A2AC25AAF6BCD1E5CF0841DFE",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "cGvHGxHXzOk/L5yVtxeyS9U1mGBNFszvAdYlQoQVGCw="
},
"voting_power": "0"
}
}
当节点同步到的区块高度和区块浏览器上一致时,表示节点已经同步完成,此时一个全节点就部署完成了。
至于在哪里查看呢:explorer.netcloth.org
成为验证人 创建账号
# usage: nchcli keys add # 示例:
nchcli keys add dan
# 按照提示输入加密账号用的密码(后续执行各种交易都需要用该密码),将命令返回的信息谨慎保存
可以得到类似
- name: dan
type: local
address: nch1p3fuppcxud5rjsaywuyuguh6achmj5p0r6z6ve// 地址
pubkey: nchpub1addwnpepqg8mfc6t9eaw9lal0c4tzma5vgmqzkgszwcgljcz3sy8rd2rukgxz9dtmph// 公钥
mnemonic: ""
threshold: 0
pubkeys: []**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.
# 下面的即助记词
connect plug cigar purchase inflict enroll ten limb quantum never supply grid home case process claw truly grape federal liberty tree remove side quantum
的输出,其中nch1p3fuppcxud5rjsaywuyuguh6achmj5p0r6z6ve就是我们的地址了
然后去测试网申请币
https://docs.netcloth.org/nch/get_token?
把尖括号和里面的address替换成我们生成的钱包地址即可,这样就可以领到币了,然后可以用这些币去抵押做验证人
设置nchcli环境变量
nchcli config chain-id nch-alphanet
nchcli config output json
nchcli config indent true
nchcli config trust-node true
创建验证人
# usage: nchcli tx staking create-validator --from= --amount=1000000unch --moniker=--commission-rate=0.1 --identity=# 示例:
nchcli tx staking create-validator \
--amount=10000unch \
--pubkey=$(nchd tendermint show-validator -o text) \
--moniker="dan" \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="100" \
--from=$(nchcli keys show dan -a)# 重点关注命令中最后一行--from=$(nchcli keys show dan -a),dan对应的账号作为抵押者将成为要创建的验证人
查询验证人列表
nchcli query staking validators可以发现多了一个moniker为dan的验证人[
{
"operator_address": "nchvaloper18q4pv9qvmqx7dcd2jq3dl3d0755urk8300709e",
"consensus_pubkey": "nchvalconspub1zcjduepqua3tt6kl7v7sd558m24fj3s039fhmsxcv9fc49rqn0uwcuelvrmsdp3hwt",
"jailed": false,
"status": 0,
"tokens": "10000",
"delegator_shares": "10000.000000000000000000",
"description": {
"moniker": "dan",
"identity": "",
"website": "",
"details": ""
},
"unbonding_height": "0",
"unbonding_time": "1970-01-01T00:00:00Z",
"commission": {
"commission_rates": {
"rate": "0.100000000000000000",
"max_rate": "0.200000000000000000",
"max_change_rate": "0.010000000000000000"
},
"update_time": "2019-10-30T11:21:01.013731989Z"
},
"min_self_delegation": "100",
"self_delegation": "10000.000000000000000000"
},
{
"operator_address": "nchvaloper133vmttt6n49jac5zn3z0klcpe7m8qluglfu58z",
"consensus_pubkey": "nchvalconspub1zcjduepq3zr5cyenfyz8qprts7344nl8gclm3st669hyrhgy9gae7l8ajuus5uttte",
"jailed": false,
"status": 2,
"tokens": "1000000",
"delegator_shares": "1000000.000000000000000000",
"description": {
"moniker": "local-nch",
"identity": "",
"website": "",
"details": ""
},
"unbonding_height": "0",
"unbonding_time": "1970-01-01T00:00:00Z",
"commission": {
"commission_rates": {
"rate": "0.100000000000000000",
"max_rate": "0.200000000000000000",
"max_change_rate": "0.100000000000000000"
},
"update_time": "2019-10-30T08:10:34.407927185Z"
},
"min_self_delegation": "1",
"self_delegation": "1000000.000000000000000000"
}
]
此时其状态为0,0表示还没有绑定,因为没有抵押足够的unch;
1000000unch为1个voting power,voting power的最小单位为1,只有它>=1时候才能够变成绑定状态2,才能成为活跃验证者出块,因此至少还需要抵押990000unch
给自己抵押500000unch
nchcli tx staking delegate nchvaloper18q4pv9qvmqx7dcd2jq3dl3d0755urk8300709e 500000unch --from $(nchcli keys show dan -a)
再次确认验证人状态为活跃验证人
nchcli query staking validators[
{
"operator_address": "nchvaloper18q4pv9qvmqx7dcd2jq3dl3d0755urk8300709e",
"consensus_pubkey": "nchvalconspub1zcjduepqua3tt6kl7v7sd558m24fj3s039fhmsxcv9fc49rqn0uwcuelvrmsdp3hwt",
"jailed": false,
"status": 2,
"tokens": "1000000",
"delegator_shares": "1000000.000000000000000000",
"description": {
"moniker": "dan",
"identity": "",
"website": "",
"details": ""
},
"unbonding_height": "0",
"unbonding_time": "1970-01-01T00:00:00Z",
"commission": {
"commission_rates": {
"rate": "0.100000000000000000",
"max_rate": "0.200000000000000000",
"max_change_rate": "0.010000000000000000"
},
"update_time": "2019-10-30T11:21:01.013731989Z"
},
"min_self_delegation": "100",
"self_delegation": "510000.000000000000000000"
},
{
"operator_address": "nchvaloper133vmttt6n49jac5zn3z0klcpe7m8qluglfu58z",
"consensus_pubkey": "nchvalconspub1zcjduepq3zr5cyenfyz8qprts7344nl8gclm3st669hyrhgy9gae7l8ajuus5uttte",
"jailed": false,
"status": 2,
"tokens": "1000000",
"delegator_shares": "1000000.000000000000000000",
"description": {
"moniker": "local-nch",
"identity": "",
"website": "",
"details": ""
},
"unbonding_height": "0",
"unbonding_time": "1970-01-01T00:00:00Z",
"commission": {
"commission_rates": {
"rate": "0.100000000000000000",
"max_rate": "0.200000000000000000",
"max_change_rate": "0.100000000000000000"
},
"update_time": "2019-10-30T08:10:34.407927185Z"
},
"min_self_delegation": "1",
"self_delegation": "1000000.000000000000000000"
}
]# 可以看到dan对应的status变成2,此时节点成为活跃验证人,可通过区块浏览器查看出块情况
然后查看
explorer.netcloth.org
我们就已经成为验证人,可以正常出块了!!!
推荐阅读
- 画解算法(1.|画解算法:1. 两数之和)
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。
- 「#1-颜龙武」区块链的价值是什么()
- leetcode|leetcode 92. 反转链表 II
- BNC公链|BNC公链 | Eth2.0测试网Topaz已质押超100万枚ETH
- 【#2-戴栋】区块链可以提升哪些商业上的效率改进
- Spectrum|Spectrum 区块偶尔停止同步问题排查与解决笔记
- 父母链接八~未了情结
- java|java 常用知识点链接
- cocosbcx白皮书解读(一)|cocosbcx白皮书解读(一)| 区块链如何统一开发者、发行商、用户之间的利益