【go-filecoin】 编译安装
安装环境
- 系统:使用的是ubuntu 18.03.1 64位版本
- go语言环境(Go >= v1.11.2)
- Rush环境(Rust >= v1.31.0 and cargo)
- pkg-config工具(pkg-config)
- 添加环境变量,文件/etc/profile
export PATH=$PATH:/usr/local/go/bin:/root/go/bin
export GOROOT=/usr/local/go
export GOPATH=/root/go
安装
#!/bin/bash
wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.11.5.linux-amd64.tar.gz
curl https://sh.rustup.rs -sSf | sh
apt install -y pkg-config cargo
apt install -y jq libclang-dev clang
echo $GOPATH
mkdir -p ${GOPATH}/src/github.com/filecoin-project
git clone https://github.com/filecoin-project/go-filecoin.git ${GOPATH}/src/github.com/filecoin-project/go-filecoin
cd ${GOPATH}/src/github.com/filecoin-project/go-filecoin
FILECOIN_USE_PRECOMPILED_RUST_PROOFS=true go run ./build/*.go deps
# 首先构建二进制文件
go run ./build/*.go build
# Install go-filecoin to ${GOPATH}/bin
go run ./build/*.go install
# 运行测试
go run ./build/*.go test
# 构建和测试可以结合起来!
go run ./build/*.go best
编译运行
go-filecoin
- 使用已经编译好的二进制文件
wget https://github.com/filecoin-project/go-filecoin/releases/download/0.0.1/filecoin-Linux.tar.gz
tar -zxvf filecoin-Linux.tar.gz
cp filecoin/go-filecoin /usr/local/bin/
加入网络
- 注:由于filecoin还处于开发阶段,默认运行命令go-filecoin bootstrap ls 什么都没有,想要手动添加启动连接节点等设置。
#!/bin/bash
rm -rf ~/.filecoin
go-filecoin init --devnet-user --genesisfile=http://user.kittyhawk.wtf:8020/genesis.car
go-filecoin daemon
-
service filecoin start 运行go-filecoin swarm peers已经可以看到已经链接上的其他对等节点。
- 我们来设置一个昵称,地址不是这么好识别的,有一个昵称可以区分我,目前只能使用小写字母。
设置昵称推送的地址,这样他就可以记录我在网路上了。
heartbeat.nickname "FILECOIN"
go-filecoin config heartbeat.beatTarget "/dns4/stats-infra.kittyhawk.wtf/tcp/8080/ipfs/QmUWmZnpZb6xFryNDeNU7KcJ1Af5oHy7fB9npU67sseEjR"
- 进入 https://stats.kittyhawk.wtf/ 查看我自己。
- 运行go-filecoin daemon后会去同步区块,这时cpu是100%的,应该在验证块吧,在网页上看到自己的Block Height是30,同步到最新的区块.
- 完成go-filecoin的编译,拿着这个bin文件就可以去跑filecoin的节点了。
root@imba:~# go-filecoin
USAGE
go-filecoin - A decentralized storage network
go-filecoin [--cmdapiaddr=<cmdapiaddr>] [--repodir=<repodir>] [--encoding=<encoding> | --enc] [--help] [-h]
SUBCOMMANDS
START RUNNING FILECOIN
go-filecoin init - Initialize a filecoin repo
go-filecoin config <key> [<value>] - Get and set filecoin config values
go-filecoin daemon - Start a long-running daemon process
go-filecoin wallet - Manage your filecoin wallets
go-filecoin address - Interact with addresses
STORE AND RETRIEVE DATA
go-filecoin client - Make deals, store data, retrieve data
go-filecoin retrieval-client - Manage retrieval client operations
MINE
go-filecoin miner - Manage a single miner actor
go-filecoin mining - Manage all mining operations for a node
VIEW DATA STRUCTURES
go-filecoin chain - Inspect the filecoin blockchain
go-filecoin dag - Interact with IPLD DAG objects
go-filecoin show - Get human-readable representations of filecoin objects
NETWORK COMMANDS
go-filecoin bootstrap - Interact with bootstrap addresses
go-filecoin id - Show info about the network peers
go-filecoin ping <peer ID>... - Send echo request packets to p2p network members
go-filecoin swarm - Interact with the swarm
ACTOR COMMANDS
go-filecoin actor - Interact with actors. Actors are built-in smart contracts.
go-filecoin paych - Payment channel operations
MESSAGE COMMANDS
go-filecoin message - Manage messages
go-filecoin mpool - Manage the message pool
TOOL COMMANDS
go-filecoin log - Interact with the daemon event log output.
go-filecoin version - Show go-filecoin version information
启动连接节点
命令 go-filecoin bootstrap ls
- 显示启动连接节点列表,这里为手动指定的user.kittyhawk.wtf节点
root@imba:~# go-filecoin bootstrap
USAGE
go-filecoin bootstrap - Interact with bootstrap addresses
go-filecoin bootstrap
SUBCOMMANDS
go-filecoin bootstrap ls -
Use 'go-filecoin bootstrap --help' for more information about this command.
root@imba:~# go-filecoin bootstrap ls
&{[/dns4/user.kittyhawk.wtf/tcp/9000/ipfs/Qmd6xrWYHsxivfakYRy6MszTpuAiEoFbgE1LWw4EvwBpp4 /dns4/user.kittyhawk.wtf/tcp/9001/ipfs/QmXq6XEYeEmUzBFuuKbVEGgxEpVD4xbSkG2Rhek6zkFMp4 /dns4/user.kittyhawk.wtf/tcp/9002/ipfs/QmXhxqTKzBKHA5FcMuiKZv8YaMPwpbKGXHRVZcFB2DX9XY /dns4/user.kittyhawk.wtf/tcp/9003/ipfs/QmZGDLdQLUTi7uYTNavKwCd7SBc5KMfxzWxAyvqRQvwuiV /dns4/user.kittyhawk.wtf/tcp/9004/ipfs/QmZRnwmCjyNHgeNDiyT8mXRtGhP6uSzgHtrozc42crmVbg]}
查看自己的id
命令 go-filecoin id
root@imba:~# go-filecoin id
{
"Addresses": [
"/ip4/127.0.0.1/tcp/6000/ipfs/QmZFBFbfsGUfULZszVfdDVKE3xdsqCDeGyiuvYkPLkNCAH",
"/ip4/172.16.3.1/tcp/6000/ipfs/QmZFBFbfsGUfULZszVfdDVKE3xdsqCDeGyiuvYkPLkNCAH"
],
"ID": "QmZFBFbfsGUfULZszVfdDVKE3xdsqCDeGyiuvYkPLkNCAH"
}
ping通网络
命令 go-filecoin ping
root@imba:~# go-filecoin ping
ipfs: Reading from /dev/stdin; send Ctrl-d to stop.
QmW4Z8p7FCspLV1FeTRW6uCNApUXqkm8xYYw4yuBnqBGeB
PING <peer.ID Qm*nqBGeB>
Pong received: time=403.07 ms
Pong received: time=391.73 ms
Pong received: time=379.68 ms
^C
root@imba:~# go-filecoin ping QmW4Z8p7FCspLV1FeTRW6uCNApUXqkm8xYYw4yuBnqBGeB
PING <peer.ID Qm*nqBGeB>
Pong received: time=410.90 ms
Pong received: time=397.93 ms
Pong received: time=402.41 ms
^C
连接流
命令 go-filecoin swarm
root@imba:~# go-filecoin swarm
USAGE
go-filecoin swarm - Interact with the swarm
go-filecoin swarm
'go-filecoin swarm' is a tool to manipulate the libp2p swarm. The swarm is the
component that opens, listens for, and maintains connections to other
libp2p peers on the internet.
SUBCOMMANDS
go-filecoin swarm connect <address>... - Open connection to a given address.
go-filecoin swarm findpeer <peerID>... - Find the multiaddresses associated with a Peer ID.
go-filecoin swarm peers - List peers with open connections.
Use 'go-filecoin swarm --help' for more information about this command.
- go-filecoin swarm peers 查看自己连上的连接。
- go-filecoin swarm findpeer <peerID> 使用Peer ID寻找address。
- go-filecoin swarm connect <address> 去连接一个地址。
【go-filecoin】代币获取、储存挖矿
环境准备
- 一个纯净的Ubuntu18.04.2系统
- 编译好的go-filecoin二进制文件(52M)
- 互联网接入
- 将本机的6000端口做公网映射【非必须】。
- 一切就绪后将go-filecoin二进制文件放入系统目录 /usr/local/bin/,这样在任何目录下这个命令都可以使用了。
查看当前的区块高度
- 获取最高区块的索引值
go-filecoin chain head
- 查看这个索引值得内容
go-filecoin show block <____>
- 可以查看到我已经同步到24110高度了
申请代币
打开网站 http://user.kittyhawk.wtf:9797 填写自己的地址
自己的地址通过go-filecoin wallet addrs ls来查看,点击提交后会给你一个MESSAGE_CID,侦听这个消息就可以知道是否已经被打包了(go-filecoin message wait ${MESSAGE_CID}),等到消息发送后,再回过头来看自己的余额,发现已经有了900FIL,目前一个地址24小时内只能提交一次申请,申请到900FIL
开始挖矿
go-filecoin miner create 10 1 --price=0 --limit=1000 --peerid `go-filecoin id | jq -r '.ID'`