一. 2k测试网
mkdir -p /var/log/2k
mkdir /2k
apt install mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
wget https://studygolang.com/dl/golang/go1.16.4.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on
1. 下载源代码
git clone https://github.com/filecoin-project/lotus lotus-local-net
cd lotus-local-net
2. 选择分支
git checkout v1.15.2-rc1
3. 设置环境变量
# lotus 2k
export LOTUS_PATH=/2k/lotus-local-net
export LOTUS_MINER_PATH=/2k/lotus-miner-local-net
export LOTUS_SKIP_GENESIS_CHECK=_yes_
export CGO_CFLAGS_ALLOW="-D__BLST_PORTABLE__"
export CGO_CFLAGS="-D__BLST_PORTABLE__"
export IPFS_GATEWAY=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/
4. 清理环境
rm -rf ~/.lotus/
rm -rf ~/.lotusminer/
rm -rf ~/.genesis-sectors/
rm -rf ~/devgen.car
rm -rf ~/localnet.json
5. 编译2k
# make 2k
rm -f lotus
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus ./cmd/lotus
rm -f lotus-miner
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus-miner ./cmd/lotus-miner
rm -f lotus-worker
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus-worker ./cmd/lotus-worker
rm -f lotus-seed
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus-seed ./cmd/lotus-seed
rm -f lotus-shed
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus-shed ./cmd/lotus-shed
rm -f lotus-wallet
go build -o lotus-wallet ./cmd/lotus-wallet
rm -f lotus-gateway
go build -ldflags="-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.dcf6f6414" -tags=2k -o lotus-gateway ./cmd/lotus-gateway
## make install
6. 下载证明参数
lotus fetch-params 2048
7. 预密封两个 2KiB 大小的扇区
# lotus-seed pre-seal --sector-size 2KiB --num-sectors 2
[flexi_logger][ERRCODE::Time] flexi_logger has to work with UTC rather than with local time, caused by IndeterminateOffset
See https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#time
sector-id: {{1000 0} 5}, piece info: {2048 baga6ea4seaqmfrefe7lz2opiur24pu4eigjntbxzblwrvwtstviy36vf5z5h4ei}
2022-04-25T03:20:32.445Z WARN preseal seed/seed.go:178 PreCommitOutput: {{1000 0} 5} bagboea4b5abcampmod6ppp2tzbrm6mje3owdgqz2kwbbi7t6qp3f6px2jt4iibjy baga6ea4seaqmfrefe7lz2opiur24pu4eigjntbxzblwrvwtstviy36vf5z5h4ei
sector-id: {{1000 1} 5}, piece info: {2048 baga6ea4seaqhmnbwed53xqpml7svo24dbw3l7ettu4rz6hapygrooqabvwlnkfy}
2022-04-25T03:20:32.500Z WARN preseal seed/seed.go:178 PreCommitOutput: {{1000 1} 5} bagboea4b5abcaxb3tizv4nitoz4jq5iwnqphad7zk2254xfczq7ypbedydcdsvzg baga6ea4seaqhmnbwed53xqpml7svo24dbw3l7ettu4rz6hapygrooqabvwlnkfy
2022-04-25T03:20:32.501Z WARN preseal seed/seed.go:103 PeerID not specified, generating dummy
2022-04-25T03:20:32.501Z INFO preseal seed/seed.go:232 Writing preseal manifest to /root/.genesis-sectors/pre-seal-t01000.json
# tree .genesis-sectors/
.genesis-sectors/
├── cache
│ ├── s-t01000-0
│ │ ├── p_aux
│ │ ├── sc-02-data-tree-r-last.dat
│ │ └── t_aux
│ └── s-t01000-1
│ ├── p_aux
│ ├── sc-02-data-tree-r-last.dat
│ └── t_aux
├── pre-seal-t01000.json
├── pre-seal-t01000.key
├── sealed
│ ├── s-t01000-0
│ └── s-t01000-1
├── sectorstore.json
├── unsealed
├── update
└── update-cache
7 directories, 11 files
8. 生成创世块
lotus-seed genesis new localnet.json
9. 创建默认地址
# lotus-seed genesis add-miner localnet.json /root/.genesis-sectors/pre-seal-t01000.json
2022-04-25T03:22:25.652Z INFO lotus-seed lotus-seed/genesis.go:129 Adding miner t01000 to genesis template
2022-04-25T03:22:25.652Z INFO lotus-seed lotus-seed/genesis.go:146 Giving t3wmxcnxmvz3yo2o2cqqkhehfw26opxtubwmdophp3ookx67mxhkluhxyfklmpzw7pinikrg2qzyonnrxsprra some initial balance
二. 启动节点
1. 启动创世节点
nohup lotus daemon --lotus-make-genesis=devgen.car --genesis-template=localnet.json --bootstrap=false >> /var/log/2k/daemon.log 2>&1 &
2. 查看环境变量
- 设置
LOTUS_PATH
和LOTUS_MINER_PATH
# lotus 2k
export LOTUS_PATH=/2k/lotus-local-net
export LOTUS_MINER_PATH=/2k/lotus-miner-local-net
export LOTUS_SKIP_GENESIS_CHECK=_yes_
export CGO_CFLAGS_ALLOW="-D__BLST_PORTABLE__"
export CGO_CFLAGS="-D__BLST_PORTABLE__"
export IPFS_GATEWAY=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/
3. 导入创世节点的钱包
# lotus wallet import --as-default ~/.genesis-sectors/pre-seal-t01000.key
imported key t3wmxcnxmvz3yo2o2cqqkhehfw26opxtubwmdophp3ookx67mxhkluhxyfklmpzw7pinikrg2qzyonnrxsprra successfully!
# lotus wallet list
Address Balance Nonce Default
t3wmxcnxmvz3yo2o2cqqkhehfw26opxtubwmdophp3ookx67mxhkluhxyfklmpzw7pinikrg2qzyonnrxsprra 49999999.999996757993460764 FIL 0 X
4. 初始化创世旷工
lotus-miner init --genesis-miner --actor=t01000 --sector-size=2KiB --pre-sealed-sectors=~/.genesis-sectors --pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json --nosync
2022-04-25T03:26:12.296Z INFO main lotus-miner/init.go:517 Importing pre-sealed sector metadata for t01000
2022-04-25T03:26:12.333Z INFO main lotus-miner/init.go:278 Miner successfully created, you can now start it with 'lotus-miner run'
5. 启动创世旷工
[IndexProvider]
Enable = false
nohup lotus-miner run --nosync >> /var/log/2k/miner.log 2>&1 &
sync behind!
过一段时间之后就会同步上
# lotus-miner info
Enabled subsystems (from miner API): [Mining Sealing SectorStorage Markets]
Enabled subsystems (from markets API): [Mining Sealing SectorStorage Markets]
Chain: [sync behind! (4m1s behind)] [basefee 100 aFIL]
⚠ 1 Active alerts (check lotus-miner log alerts)
Miner: t01000 (2 KiB sectors)
Power: 40 Ki / 40 Ki (100.0000%)
Raw: 4 KiB / 4 KiB (100.0000%)
Committed: 4 KiB
Proving: 4 KiB
Projected average block win rate: 20024.16/week (every 30s)
Projected block win with 99.9% probability every 41s
(projections DO NOT account for future network and miner growth)
Miner Balance: 5323.843 FIL
PreCommit: 0
Pledge: 2 aFIL
Vesting: 3992.882 FIL
Available: 1330.961 FIL
Market Balance: 0
Locked: 0
Available: 0
Worker Balance: 50000000 FIL
Total Spendable: 50001330.961 FIL
Sectors:
Total: 2
Proving: 2
Workers: Seal(1) WdPoSt(0) WinPoSt(0)
Storage Deals: 0, 0 B
Retrieval Deals (complete): 0, 0 B
# lotus-miner info
Enabled subsystems (from miner API): [Mining Sealing SectorStorage Markets]
Enabled subsystems (from markets API): [Mining Sealing SectorStorage Markets]
Chain: [sync ok] [basefee 100 aFIL]
Miner: t01000 (2 KiB sectors)
Power: 40 Ki / 40 Ki (100.0000%)
Raw: 4 KiB / 4 KiB (100.0000%)
Committed: 6 KiB
Proving: 6 KiB (2 KiB Faulty, 33.33%)
Projected average block win rate: 20024.16/week (every 30s)
Projected block win with 99.9% probability every 41s
(projections DO NOT account for future network and miner growth)
Miner Balance: 132540.906 FIL
PreCommit: 0
Pledge: 59.605 nFIL
Vesting: 99297.112 FIL
Available: 33243.793 FIL
Market Balance: 0
Locked: 0
Available: 0
Worker Balance: 50000000 FIL
Total Spendable: 50033243.793 FIL
Sectors:
Total: 3
Proving: 3
Workers: Seal(1) WdPoSt(0) WinPoSt(0)
Storage Deals: 0, 0 B
Retrieval Deals (complete): 0, 0 B
6. 重启创世旷工
- 停止
lotus daemon
和 lotus-miner
lotus daemon stop
lotus-miner stop
nohup lotus daemon --genesis=devgen.car --profile=bootstrapper >> /var/log/2k/daemon.log 2>&1 &
nohup lotus-miner run --nosync >> /var/log/2k/miner.log 2>&1 &
三. 启动其它节点
1. 拷贝同步数据
scp devgen.car root@192.168.2.182:/root
2. 启动节点
mkdir -p /var/log/2k/
lotus fetch-params 2048
nohup lotus daemon --genesis=devgen.car --bootstrap=false >> /var/log/2k/daemon.log 2>&1 &
3. 查看创始节点连接信息
# lotus net listen
/ip4/192.168.2.179/tcp/34597/p2p/12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG
/ip4/127.0.0.1/tcp/34597/p2p/12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG
/ip6/::1/tcp/45173/p2p/12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG
4. 连接到创世节点
# lotus net connect /ip4/192.168.2.179/tcp/34597/p2p/12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG
connect 12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG: success
# lotus net peers
12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG, [/ip4/192.168.2.179/tcp/34597]
# lotus sync wait
Worker: 2; Base: 4706; Target: 4707 (diff: 1))
State: complete; Current Epoch: 4707; Todo: 0
Validated 882 messages (48 per second)
5. 创建钱包
# lotus wallet new bls
t3sg4tcgiw2refeorxnus2irpqqzujx4oqkeeqle3mgmdinv6mpwuei5s6zym3auqhndcxvupz4kg5arh6ry4a
6. 从创世节点发送一些fil
# lotus send t3sg4tcgiw2refeorxnus2irpqqzujx4oqkeeqle3mgmdinv6mpwuei5s6zym3auqhndcxvupz4kg5arh6ry4a 1000000
bafy2bzacectn5iu4bss2reuqn2jtxphka73yubgfhvqn4vpacriiplokrmams
7. 查看钱包
# lotus wallet list
Address Balance Nonce Default
t3sg4tcgiw2refeorxnus2irpqqzujx4oqkeeqle3mgmdinv6mpwuei5s6zym3auqhndcxvupz4kg5arh6ry4a 1000000 FIL 0 X
8. 初始化新节点
# lotus-miner init --sector-size=2KiB
2022-04-25T08:50:40.536Z INFO main lotus-miner/init.go:178 Checking if repo exists
2022-04-25T08:50:40.536Z INFO main lotus-miner/init.go:194 Checking full node version
2022-04-25T08:50:40.536Z INFO main lotus-miner/init.go:205 Initializing repo
2022-04-25T08:50:40.536Z INFO repo repo/fsrepo.go:267 Initializing repo at '/seal/miner'
2022-04-25T08:50:40.537Z INFO main lotus-miner/init.go:420 Initializing libp2p identity
2022-04-25T08:50:40.575Z INFO badger v2@v2.2007.3/levels.go:183 All 0 tables opened in 0s
2022-04-25T08:50:40.613Z INFO badger v2@v2.2007.3/levels.go:183 All 0 tables opened in 0s
2022-04-25T08:50:40.677Z INFO main lotus-miner/init.go:749 Pushed CreateMiner message: bafy2bzacednez3e6enxicjtebhg3j5ciqjop5yxxyjd53da7t7cfen3mhpa6o
2022-04-25T08:50:40.677Z INFO main lotus-miner/init.go:750 Waiting for confirmation
2022-04-25T08:51:10.145Z INFO main lotus-miner/init.go:766 New miners address is: t01002 (t23yvqfkzvkgjo7bi5zikdvpox5tm5bmmk4s7oera)
2022-04-25T08:51:10.145Z INFO main lotus-miner/init.go:554 Created new miner: t01002
2022-04-25T08:51:10.154Z INFO main lotus-miner/init.go:278 Miner successfully created, you can now start it with 'lotus-miner run'
9. 启动新节点
cat $LOTUS_MINER_PATH/config.toml
修改配置 Enable = false
[IndexProvider]
# Enable set whether to enable indexing announcement to the network and expose endpoints that
# allow indexer nodes to process announcements. Disabled by default.
#
# type: bool
# env var: LOTUS_INDEXPROVIDER_ENABLE
#Enable = true
Enable = false
nohup lotus-miner run >> /var/log/2k/miner.log 2>&1 &
10. 查看新节点
# lotus-miner info
Enabled subsystems (from miner API): [Mining Sealing SectorStorage Markets]
Enabled subsystems (from markets API): [Mining Sealing SectorStorage Markets]
Chain: [sync ok] [basefee 100 aFIL]
⚠ 1 Active alerts (check lotus-miner log alerts)
Miner: t01002 (2 KiB sectors)
Power: 0 / 42 Ki (0.0000%)
Raw: 0 B / 6 KiB (0.0000%)
Committed: 0 B
Proving: 0 B
Below minimum power threshold, no blocks will be won
Miner Balance: 0
PreCommit: 0
Pledge: 0
Vesting: 0
Available: 0
Market Balance: 0
Locked: 0
Available: 0
Worker Balance: 1000000 FIL
Total Spendable: 1000000 FIL
Sectors:
Total: 0
Workers: Seal(1) WdPoSt(0) WinPoSt(0)
Storage Deals: 0, 0 B
Retrieval Deals (complete): 0, 0 B
# lotus-miner log alerts
active process:fd-limit
last raised at 2022-04-25 09:11:41.21 +0000 UTC; reason: {"message":"soft FD limit is low","recommended_min":100000,"soft_limit":16384}
ulimit -n 1024000
nohup lotus daemon --genesis=devgen.car --bootstrap=false >> /var/log/2k/daemon.log 2>&1 &
lotus net connect /ip4/192.168.2.179/tcp/34597/p2p/12D3KooWEBTiNWr4wY1DaY4dYSzEzyvnn3DFX4PZuPkm3nzJfapG
nohup lotus-miner run >> /var/log/2k/miner.log 2>&1 &
参考
- Local network
- 本地搭建 2K 测试网入门教程