go-filecoin编译安装与命令解释

go-filecoin 源码已经在2019年2月15日3:00(+8:00)发布了,可以使用github上已经编译好的0.0.1版本,还可以自己编译。

自己编译

安装环境

  1. 系统:我这里使用的是ubuntu 18.03.1 64位版本
  2. go语言环境(Go >= v1.11.2)
  3. Rush环境(Rust >= v1.31.0 and cargo)
  4. pkg-config工具(pkg-config)
  5. 国际互联网接入服务(部分代码会从golang.org拉取,需要科学上网工具)

添加环境变量,文件/etc/profile

export http_proxy=
export https_proxy=

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

# First, build the binary
go run ./build/*.go build

# Install go-filecoin to ${GOPATH}/bin (necessary for tests)
go run ./build/*.go install

# Then, run the tests.
go run ./build/*.go test

# Build and test can be combined!
go run ./build/*.go best

需要注意一下,这里与官方给出的文档稍微有些差异,已经做了更改。

编译好之后,就可以运行这个命令了 go-filecoin
go-filecoin编译安装与命令解释_第1张图片
与官方已经编译好的二进制文件不一样,我这个代码更新一点,预编译好的版本是0.0.1版本
0.0.1版本在加入开发网络时有出错的情况,应该是代码还没完善吧。

注意:
go run ./build/*.go deps时遇到一些问题,网络状况不是很好,连接经常中断,可以自己分步运行这些指令,在代码./build/main.go的115行~150行
go-filecoin编译安装与命令解释_第2张图片

#!/bin/bash
go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
gx install
gx-go rewrite
go get -u github.com/alecthomas/gometalinter
gometalinter --install
go get -u github.com/stretchr/testify
go get -u github.com/xeipuuv/gojsonschema
go get -u github.com/ipfs/iptb
go get -u github.com/docker/docker/api/types
go get -u github.com/docker/docker/api/types/container
go get -u github.com/docker/docker/client
go get -u github.com/docker/docker/pkg/stdcopy
go get -u github.com/ipsn/go-secp256k1
go get -u github.com/json-iterator/go
go get -u github.com/prometheus/client_golang/prometheus
go get -u github.com/prometheus/client_golang/prometheus/promhttp
go get -u github.com/jstemmer/go-junit-report
go get -u github.com/pmezard/go-difflib/difflib
./scripts/install-rust-proofs.sh
./scripts/install-bls-signatures.sh
./proofs/bin/paramcache
./scripts/copy-groth-params.sh

在上文中

curl https://sh.rustup.rs -sSf | sh
apt install -y jq libclang-dev clang

不能改变顺序,这里涉及到依赖的版本问题,apt install 时会安装Rust,但是不是我们想要的版本,先安装rust,在apt,可以避免版本依赖问题。

使用已经编译好的二进制文件

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

注意这里go-filecoin daemon和ipfs daemon一样,会占用一个会话,这样可以做出服务启动:
vim /lib/systemd/system/filecoin.service
我已经将编译好的go-filecoin放入/usr/local/bin/目录,
cp ${GOPATH}/bin/go-filecoin /usr/local/bin/go-filecoin

[Unit]
Description=FileCoin
[Service]
ExecStart=/usr/local/bin/go-filecoin daemon
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target

service filecoin start

这时候我们运行go-filecoin swarm peers已经可以看到已经链接上的其他对等节点。
go-filecoin编译安装与命令解释_第3张图片

我们来设置一个昵称,地址不是这么好识别的,有一个昵称可以区分我,目前只能使用小写字母。
设置昵称推送的地址,这样他就可以记录我在网路上了。

go-filecoin config heartbeat.nickname "billimba"
go-filecoin config heartbeat.beatTarget "/dns4/stats-infra.kittyhawk.wtf/tcp/8080/ipfs/QmUWmZnpZb6xFryNDeNU7KcJ1Af5oHy7fB9npU67sseEjR"

进入 https://stats.kittyhawk.wtf/ 查看我自己。
go-filecoin编译安装与命令解释_第4张图片

go-filecoin编译安装与命令解释_第5张图片
看到我自己了。
注意:
运行go-filecoin daemon后会去同步区块,这时cpu是100%的,应该在验证块吧,在网页上看到自己的Block Height是30,等了很久没有上涨,于是我放了一个晚上,第二天已经同步上了,Block Height已经很别人一样了,同步到最新的区块了。

昨天已经完成了go-filecoin的编译,文件大小52M,拿着这个bin文件就可以去跑filecoin的节点了。

root@imba:~# go-filecoin 
USAGE
  go-filecoin - A decentralized storage network

  go-filecoin [--cmdapiaddr=] [--repodir=] [--encoding= | --enc] [--help] [-h]

SUBCOMMANDS
  START RUNNING FILECOIN
    go-filecoin init                   - Initialize a filecoin repo
    go-filecoin config  [] - 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 ...      - 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
功能和icmp协议的ping一样,但是IP层面是透明的,p2p软件嘛,就是这样的。

root@imba:~# go-filecoin ping
ipfs: Reading from /dev/stdin; send Ctrl-d to stop.
QmW4Z8p7FCspLV1FeTRW6uCNApUXqkm8xYYw4yuBnqBGeB
PING 
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 
Pong received: time=410.90 ms
Pong received: time=397.93 ms
Pong received: time=402.41 ms
^C

连接流

命令 go-filecoin swarm
分3个命令

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 
... - Open connection to a given address. go-filecoin swarm findpeer ... - 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 使用Peer ID寻找address。
go-filecoin swarm connect

去连接一个地址。

钱包相关

root@imba:~# go-filecoin wallet
USAGE
  go-filecoin wallet - Manage your filecoin wallets

  go-filecoin wallet

SUBCOMMANDS
  go-filecoin wallet addrs                 - Interact with addresses
  go-filecoin wallet balance 
- go-filecoin wallet export ... - go-filecoin wallet import - Use 'go-filecoin wallet --help' for more information about this command.
root@imba:~# go-filecoin wallet addrs
USAGE
  go-filecoin wallet addrs - Interact with addresses

  go-filecoin wallet addrs

SUBCOMMANDS
  go-filecoin wallet addrs lookup 
- go-filecoin wallet addrs ls - go-filecoin wallet addrs new - Use 'go-filecoin wallet addrs --help' for more information about this command.

go-filecoin wallet addrs ls 显示自己的地址列表。
go-filecoin wallet addrs new 新建一个地址。
//TODO 未知 go-filecoin wallet addrs lookup

go-filecoin wallet balance

查询余额。
go-filecoin wallet export 导出密钥对。
go-filecoin wallet import 导入密钥对文件。

区块链

root@imba:~# go-filecoin chain
USAGE
  go-filecoin chain - Inspect the filecoin blockchain

  go-filecoin chain

SUBCOMMANDS
  go-filecoin chain head - Get heaviest tipset CIDs
  go-filecoin chain ls   - List blocks in the blockchain

Use 'go-filecoin chain --help' for more information about this command.

go-filecoin chain ls 查看所有块
go-filecoin chain head 查看块头

IPLD源数据

root@imba:~# go-filecoin dag
USAGE
  go-filecoin dag - Interact with IPLD DAG objects.

  go-filecoin dag

SUBCOMMANDS
  go-filecoin dag get  - Get a DAG node by its CID

Use 'go-filecoin dag --help' for more information about this command.

查看区块内容

root@imba:~# go-filecoin show
USAGE
  go-filecoin show - Get human-readable representations of filecoin objects

  go-filecoin show

SUBCOMMANDS
  go-filecoin show block  - Show a filecoin block by its CID

Use 'go-filecoin show --help' for more information about this command.

root@imba:~# go-filecoin show block zDPWYqFD7zTH4Ato2vpcVXjKpuHSAZujSLQRBQfZXe5GWsD9thZx
Block Details
Miner:  fcqnmc3x995uxvh2xjjl3h4d8nt3c0w50lgu4f7ts
Weight: 3190.000
Height: 30
Nonce:  0
root@imba:~# go-filecoin show block zDPWYqFCutuHwRZhGXzji9L4eHeoFxxNCxCruGjWje36aAvbK2XV
Block Details
Miner:  fcqqqqqqqqqqqqqqqqqqqqqyptunp
Weight: 0.000
Height: 0
Nonce:  0
root@imba:~# go-filecoin show block zDPWYqFD1R4povAi2A9DZHXVvXc4Cku1NsLEawFCN5yVGjiwnjY8
Block Details
Miner:  fcqnmc3x995uxvh2xjjl3h4d8nt3c0w50lgu4f7ts
Weight: 0.000
Height: 1
Nonce:  0

go-filecoin show block 结合go-filecoin chain使用

你可能感兴趣的:(区块链应用)