搭建filecoin lotus私有网络及vscode下调试源码

软硬件配置

  • 6核/16G内存/Radeon Pro 555X 4 GB
  • macOS catalina 10.15.3
  • vscode 1.42.0
  • golang 1.14
  • Homebrew 2.2.10-42-gf5ba503

环境准备

每个矿工都需要

1.依赖安装

brew install go bzr jq pkg-config rustup

2. 调试工具更新

xcode-select --install
go get -u github.com/go-delve/delve/cmd/dlv
sudo /usr/sbin/DevToolsSecurity -enable

3.下载源码、编译

git clone https://github.com/filecoin-project/lotus.git
cd lotus/
export GO111MODULE=on
export GOPROXY=https://goproxy.io
make debug

如若编译时出错,请更换rust Crates源

+ cargo +nightly-2019-11-06 build --release
+ tee /var/folders/cq/vv_zdwd902d2y1j36zgsxk_w0000gn/T/tmp.u4LT35gu
    Updating crates.io index
warning: spurious network error (2 tries remaining): early EOF; class=Net (12); code=Eof (-20

在 $HOME/.cargo/config 中添加如下内容,再重新make

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index

创世矿工

1. 预密封扇区

这里设置为1k,扇区越大,时间越久

./lotus-seed pre-seal --sector-size 1024 --num-sectors 2

2. 启动lotus deamon

设置一下环境变量IPFS_GATEWAY,从国内下载证明参数文件

nohup ./lotus daemon --lotus-make-random-genesis=genesis.car  \
--genesis-presealed-sectors=~/.genesis-sectors/pre-seal-t0101.json  \
--bootstrap=false \
> lotus.log 2>&1 &

3. 创世矿工初始化设置

设置一下环境变量IPFS_GATEWAY,从国内下载

./lotus-storage-miner init --genesis-miner --actor=t0101 --sector-size=1024  \
--pre-sealed-sectors=~/.genesis-sectors --nosync

4. 启动矿工

 nohup  ./lotus-storage-miner run --nosync > miner.log 2>&1 &

5. 启动远程矿工 (可选)

./lotus-seal-worker run

6. 创建一个新的扇区 存储随机数据

./lotus-storage-miner pledge-sector

启动一个新矿工

在另外一个机器上操作

1.拷贝genesis.car

从创世矿工拷贝genesis.car文件到新的矿工节点,genesis.car不一致会导致无法组建私有网络

2.启动deamon

注意genesis.car文件位置,bootstrap必须设置false否则将连接到测试网络,并同步测试网络数据

lotus daemon --genesis=genesis.car --bootstrap=false

3.创建钱包

记录下钱包地址

lotus wallet new bls
t3qce3xob7v6jw3tvjlmvjkox5gytdtbueb7chnepgtk2sfukjqd4cd4eo2p6r5seb3zhbfd3qfh4qskidnsba

4. 转账(登录创世矿工节点)

创建矿工需要抵押代币

lotus send t3qce3xob7v6jw3tvjlmvjkox5gytdtbueb7chnepgtk2sfukjqd4cd4eo2p6r5seb3zhbfd3qfh4qskidnsba 1000

5. 初始化矿工

owner和worker参数为上一步创建的钱包地址

lotus daemon init --owner t3qce3xob7v6jw3tvjlmvjkox5gytdtbueb7chnepgtk2sfukjqd4cd4eo2p6r5seb3zhbfd3qfh4qskidnsba --worker t3qce3xob7v6jw3tvjlmvjkox5gytdtbueb7chnepgtk2sfukjqd4cd4eo2p6r5seb3zhbfd3qfh4qskidnsba

初始化后查看日志,会返回矿工id 如t01002

6. 运行矿工

lotus-storage-miner run

7. 查看创世矿工监听地址(登录创世矿工节点)

lotus net listen
lotus-storage-miner  net listen

默认只会监听到本地网卡地址,需要4个以上的外部网络连接,才会显外网ip

8. 连接到创世矿工网络

每个矿工有两个进程lotus和lotus-storage-miner,都会对外暴露一个端口,需交叉连接,否则路由会出问题

lotus net connect /ip4/xx.xx.xxx.xx/tcp/1347/p2p/12D3KooWFTAWbqatfszrSn2EccQSeyrpLnb852r7RoXvjaFc8n6t
lotus net connect /ip4/xx.xx.xx.xx/tcp/1348/p2p/12D3KooWHS1dRz1a6qj7VBCZ5j5LsGvE1ir3q8dxRVPHr5C4iSwP

lotus-storage-miner  net connect /ip4/xx.xx.xx.xx/tcp/1347/p2p/12D3KooWFTAWbqatfszrSn2EccQSeyrpLnb852r7RoXvjaFc8n6t
lotus-storage-miner net connect /ip4/xx.xx.xx.xx/tcp/1348/p2p/12D3KooWHS1dRz1a6qj7VBCZ5j5LsGvE1ir3q8dxRVPHr5C4iSwP

连接可能会断开,通过lotus net peerslotus-storage-miner net peers检查是否掉线

源码调试

vscode调试配置

buildFlags参数根据Makefile编写,必须设置-tags=debug,否则将载入测试网络配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "pre-seal",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "port": 2344,
                "host": "127.0.0.1",
                "program": "${workspaceRoot}/cmd/lotus-seed",
                "env": {},
                "buildFlags":"-ldflags=-X='github.com/filecoin-project/lotus/build'.CurrentCommit=954085d3 -tags=debug",
                "args": ["pre-seal", "--sector-size", "1024", "--num-sectors", "2"]
            },
        {
        "name": "lotus daemon",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceRoot}/cmd/lotus",
            "env": {
                "IPFS_GATEWAY":"https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/"
            },
            "showLog": true,
            "buildFlags":"-ldflags=-X='github.com/filecoin-project/lotus/build'.CurrentCommit=954085d3 -tags=debug",
            "args": ["daemon","--lotus-make-random-genesis=genesis.car", "--genesis-presealed-sectors=~/.genesis-sectors/pre-seal-t0101.json", "--bootstrap=false"]
        },
        {
            "name": "lotus-storage-miner init",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "port": 2346,
                "host": "127.0.0.1",
                "program": "${workspaceRoot}/cmd/lotus-storage-miner",
                "env": {
                    "IPFS_GATEWAY":"https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/"
                },
                "showLog": true,
                "buildFlags":"-ldflags=-X='github.com/filecoin-project/lotus/build'.CurrentCommit=954085d3 -tags=debug",
                "args": ["init", "--genesis-miner", "--actor=t0101", "--sector-size=1024", "--pre-sealed-sectors=~/.genesis-sectors", "--nosync"]
            },
            {
                "name": "lotus-storage-miner run",
                    "type": "go",
                    "request": "launch",
                    "mode": "debug",
                    "port": 2347,
                    "host": "127.0.0.1",
                    "program": "${workspaceRoot}/cmd/lotus-storage-miner",
                    "env": {
                        "IPFS_GATEWAY":"https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/"
                    },
                    "showLog": true,
                    "buildFlags":"-ldflags=-X='github.com/filecoin-project/lotus/build'.CurrentCommit=954085d3 -tags=debug",
                    "args": ["run","--nosync"]
                },
              {
            "name": "lotus-seal-worker run",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "port": 2348,
                "host": "127.0.0.1",
                "program": "${workspaceRoot}/cmd/lotus-seal-worker",
                "env": {
                    "IPFS_GATEWAY":"https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/"
                },
                "showLog": true,
                "buildFlags":"-ldflags=-X='github.com/filecoin-project/lotus/build'.CurrentCommit=954085d3 -tags=debug",
                "args": ["run"]
            }
    ]
}

删除数据

rm -rf ~/.genesis-sectors
rm -rf ~/.lotus/    
rm -rf ~/.lotusstorage/ 
rm -rf ~/.lotusworker/

你可能感兴趣的:(ipfs&filecoin)