BSC(币安智能链)主网链部署
Posted 看见月亮的人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BSC(币安智能链)主网链部署相关的知识,希望对你有一定的参考价值。
文章目录
- BSC链github地址:https://github.com/binance-chain/bsc
- 主网浏览器:https://bscscan.com/
- 主网链官方部署文档:https://docs.binance.org/smart-chain/developer/fullnode.html
- 私有链官方部署文档:https://docs.binance.org/smart-chain/developer/deploy/local.html
一. BSC主链镜像生成
- 下载BSC私链基础镜像
docker pull buildpack-deps:jessie-curl
- 编写Dockerfile
# vim Dockerfile
FROM buildpack-deps:jessie-curl
RUN mkdir /data
RUN wget -P /usr/local/bin/ https://github.com/binance-chain/bsc/releases/download/v1.0.7/geth_linux && mv /usr/local/bin/geth_linux /usr/local/bin/geth && chmod +x /usr/local/bin/geth
EXPOSE 8545 30303
WORKDIR /data
ENTRYPOINT ["geth"]
- 生成BSC主链镜像
# docker build . -t public_bsc:v1.0.7
注:需要在与Dockerfile同一级目录下执行此命令
二.BSC主链容器生成
2.1 下载BSC主网配置文件
下载BSC主网的genesis.json(创始区块文件)及config.toml(配置文件)
# cd /opt/docker/public_bsc/data/
# wget $(curl -s https://api.github.com/repos/binance-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\\" -f4)
# unzip mainnet.zip
注: 配置文件参数讲解
- TrieTimeout
由于TrieTimeout在config.toml中的默认值很大,这意味着geth直到达到此时间阈值之前,状态都不会持久保存到数据库中,如果该节点已被强制关闭,则它将从最后一个状态开始进行同步,这可能需要很长时间。推荐人的推荐设置是TrieTimeout = 100000000000
该值越大,则更频繁地将内存中状态写入磁盘。 该值越低,在节点崩溃的罕见情况下就可以更快地恢复节点。
- HTTPHost
HTTP-RPC服务连接白名单,此参数的值默认为 “localhost”,仅允许本地可访问,可设置为:“0.0.0.0”
- HTTPVirtualHosts
HTTP-RPC服务监听接口,此参数的值默认为 [“localhost”],可设置为:HTTPVirtualHosts = ["*"]
2.2 新建初始化创始区块文件脚本
# vim genesis.sh
#!/bin/bash
docker run --rm -v $(pwd):/data public_bsc:v1.0.7 init /data/genesis.json --datadir /data/node
2.3 本地写入创世状态
初始化创世区块文件
# sh genesis.sh
将得到以下输出
INFO [04-25|09:20:12.105] Maximum peer count ETH=50 LES=0 total=50
INFO [04-25|09:20:12.106] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=ledger vendor=11415 failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=trezor vendor=21324 failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=trezor vendor=4617 failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=ledger vendor=11415 failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=trezor vendor=21324 failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[04-25|09:20:12.106] Failed to enumerate USB devices hub=trezor vendor=4617 failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
INFO [04-25|09:20:12.106] Allocated cache and file handles database=/data/node/geth/chaindata cache=16.00MiB handles=16
INFO [04-25|09:20:12.121] Writing custom genesis block
INFO [04-25|09:20:12.122] Persisted trie from memory database nodes=25 size=98.51KiB time=302.595µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=-820.00B
INFO [04-25|09:20:12.122] Successfully wrote genesis state database=chaindata hash=0d2184…d57b5b
INFO [04-25|09:20:12.122] Allocated cache and file handles database=/data/node/geth/lightchaindata cache=16.00MiB handles=16
INFO [04-25|09:20:12.134] Writing custom genesis block
INFO [04-25|09:20:12.135] Persisted trie from memory database nodes=25 size=98.51KiB time=281.141µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=-820.00B
INFO [04-25|09:20:12.136] Successfully wrote genesis state database=lightchaindata hash=0d2184…d57b5b
2.4 新建BSC链启动脚本
# vim run.sh
#!/bin/bash
docker run -itd --restart=unless-stopped -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone --name public_bsc -v $(pwd):/data -p 30303:30303 -p 8545:8545 public_bsc:v1.0.7 --config ./config.toml --datadir ./node --pprofaddr 0.0.0.0 --metrics --pprof
2.5 启动BSC主网链
# sh run.sh
a7922c0c1ca883a3eccdbcf54a6c29eab0f7b72b1f647fea7611e41efc951252
三.查看BSC服务是否部署成功
- 查看BSC容器是否成功启动
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7922c0c1ca8 public_bsc:v1.0.7 "geth --config ./con…" 5 minutes ago Up 5 minutes 0.0.0.0:8545->8545/tcp, 0.0.0.0:30303->30303/tcp public_bsc
- 查看BSC服务启动日志是否正常
# docker logs -f public_bsc
INFO [04-25|17:24:50.148] Starting pprof server addr=http://0.0.0.0:6060/debug/pprof
INFO [04-25|17:24:50.148] Starting Geth on Ethereum mainnet...
INFO [04-25|17:24:50.148] Bumping default cache on mainnet provided=1024 updated=4096
INFO [04-25|17:24:50.148] Enabling metrics collection
INFO [04-25|17:24:50.153] Maximum peer count ETH=30 LES=0 total=30
INFO [04-25|17:24:50.154] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
- 查看BSC主网节点区块同步日志是否正常
日志文件在/node/bsc.log中
[root@192-168-21-13 data]# tail /opt/docker/public_bsc/data/node/bsc.log.2021-04-25_17
t=2021-04-25T17:24:50+0800 lvl=info msg="Starting peer-to-peer node" instance=Geth/v1.0.7-f1d92bef/linux-amd64/go1.15.5
t=2021-04-25T17:24:50+0800 lvl=info msg="Allocated trie memory caches" clean="614.00 MiB" dirty="1024.00 MiB"
t=2021-04-25T17:24:50+0800 lvl=info msg="Allocated cache and file handles" database=/data/node/geth/chaindata cache="2.00 GiB" handles=524288
t=2021-04-25T17:24:50+0800 lvl=info msg="Opened ancient database" database=/data/node/geth/chaindata/ancient
t=2021-04-25T17:24:50+0800 lvl=info msg="Initialised chain configuration" config="{ChainID: 56 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: 0, Ramanujan: 0, Niels: 0, MirrorSync: 5184000, Engine: parlia}"
t=2021-04-25T17:24:50+0800 lvl=info msg="Initialising Ethereum protocol" versions="[65 64 63]" network=56 dbversion=<nil>
t=2021-04-25T17:24:50+0800 lvl=warn msg="Upgrade blockchain database version" from=<nil> to=7
t=2021-04-25T17:24:50+0800 lvl=info msg="Loaded most recent local header" number=0 hash=0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b td=1 age=1y1w2d
t=2021-04-25T17:24:50+0800 lvl=info msg="Loaded most recent local full block" number=0 hash=0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b td=1 age=1y1w2d
t=2021-04-25T17:24:50+0800 lvl=info msg="Loaded most recent local fast block" number=0 hash=0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b td=1 age=1y1w2d
t=2021-04-25T17:24:50+0800 lvl=info msg="Allocated fast sync bloom" size="1.60 GiB"
t=2021-04-25T17:24:50+0800 lvl=info msg="New local node record" seq=1 id=b2c62dee2e6c96ad5bc747c0080510cd25d4c5bf565eaab66dfa3de50c5d90ce ip=127.0.0.1 udp=30311 tcp=30311
t=2021-04-25T17:24:50+0800 lvl=info msg="Started P2P networking" self=enode://0dc47bc6298538e8807400d98897721136ed21e99f562ad78b3b73bb62bae6110a7265c65f7d1c6f5ca590e2a5a0ff950ff90cc95195ea0b129b4069628e16b0@127.0.0.1:30311
t=2021-04-25T17:24:50+0800 lvl=info msg="IPC endpoint opened" url=/data/node/geth.ipc
t=2021-04-25T17:24:50+0800 lvl=info msg="HTTP endpoint opened" url=http://127.0.0.1:8545/ cors= vhosts=localhost
t=2021-04-25T17:24:50+0800 lvl=info msg="Initialized fast sync bloom" items=25 errorrate=0.000 elapsed=39.852ms
t=2021-04-25T17:24:50+0800 lvl=info msg="Block synchronisation started"
t=2021-04-25T17:24:53+0800 lvl=info msg="Stored checkpoint snapshot to disk" number=0 hash=0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b
t=2021-04-25T17:24:53+0800 lvl=info msg="Imported new block headers" count=192 elapsed=71.795ms number=192 hash=0x0f1eb695329ea416cdc0a1611b0e5ef915727907932810ffcb8587884b399023 age=7mo4w1d
t=2021-04-25T17:24:53+0800 lvl=info msg="Imported new state entries" count=424 elapsed=2.583µs processed=424 pending=6785 retry=2 duplicate=0 unexpected=0
t=2021-04-25T17:24:53+0800 lvl=info msg="Imported new block headers" count=384 elapsed=138.146ms number=576 hash=0x39dd3735adafc3f0b482caf4bee8d3225d1a7a8ad98e5cc002cf2466ce881bdd age=7mo4w1d
t=2021-04-25T17:24:53+0800 lvl=info msg="Migrated ancient blocks" count=1 elapsed=305.073µs
t=2021-04-25T17:24:53+0800 lvl=info msg="Imported new block headers" count=384 elapsed=139.977ms number=960 hash=0xc6fceb346e2b05440f07b9ce83f7a8df352e30362b36f982b51f488ee5e5150c age=7mo4w1d
四.查看BSC主网节点是否同步完成
- 查看节点区块数据同步进度
查看节点当前同步的同步进度,返回为false,则BSC区块数据同步完成
# curl -s -H Content-Type:application/json -X POST --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","id":1,"result":false}
- 查看节点最新区块号
查看节点当前同步的最新区块号,与etc官方区块链浏览器进行对比,查看是否一致,是否已与公网节点的区块一致
BSC官方主网浏览器:https://bscscan.com/
# curl -s -H Content-Type:application/json -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8545
- 查询链上最新的交易哈希
查询BSC链上最新的交易哈希,确认是否可获取交易信息,如果可获取,说明已同步区块信息
# curl -H Content-Type:application/json -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0xb9eeb787885d0ec3cb0e01c7a56843e335532b5683ab12ddaab4b92b71c524d7"],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x58e2dd9b0e6803e24ce96732cacfbc2716a7cbfc48de57470f5a4c00a141f4bd","blockNumber":"0x4de1fe","from":"0xadb83abbf7a8987afb76db33ed2855a07f5497c7","gas":"0x7a120","gasPrice":"0x3b9aca00","hash":"0xb9eeb787885d0ec3cb0e01c7a56843e335532b5683ab12ddaab4b92b71c524d7","input":"0x202ee0ed000000000000000000000000000000000000000000000000000000000000646b0000000000000000000000000000000000000000000000000000000639e34740","nonce":"0x11094","to":"0x944b319cb0326887c39a851813186273846dae7b","transactionIndex":"0x67","value":"0x0","v":"0x94","r":"0x87ab8fe5ef842ab012d2ddcd68d1f0851924cb99420b7a8b67f108c1d6584a46","s":"0x6d474cf6657f7a85b0cfbdc2f398bc308282fade1be7de44922e533ab56905e4"}}
以上是关于BSC(币安智能链)主网链部署的主要内容,如果未能解决你的问题,请参考以下文章