BESU IBFT2.0 docker 部署

BESU IBFT2.0 docker+静态引导部署文档

1、准备环境

OS
ubuntu22.04 lts
docker 24.0.5
docker-compose v2.15.0
besu besu/v21.10.1/linux-x86_64/oracle-java-12

2、相关文档

1、besu官方文档
https://besu.hyperledger.org/private-networks/tutorials/ibft
2、besu二进制下载地址
https://hyperledger.jfrog.io/ui/native/besu-binaries/besu

3、创建网络配置文件ibftConfigFile.json

{
 "genesis": {
   "config": {
      "chainId": 1337,
      "muirglacierblock": 0,
      "contractSizeLimit": 2147483647,
      "ibft2": {
        "blockperiodseconds": 2,
        "epochlength": 30000,
        "requesttimeoutseconds": 4
      }
    },
    "nonce": "0x0",
    "timestamp": "0x58ee40ba",
    "gasLimit": "0x1fffffffffffff"
    "difficulty": "0x1",
    "mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "alloc": {
       "fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
          "privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
          "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
          "balance": "0xad78ebc5ac6200000"
       },
       "627306090abaB3A6e1400e9345bC60c78a8BEf57": {
         "privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       },
       "f17f52151EbEF6C7334FAD080c5704D77216b732": {
         "privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       }
      }
 },
 "blockchain": {
   "nodes": {
     "generate": true,
       "count": 4
   }
 }
}

配置解释

genesis 创世块区
ibft2 共识机制
gasLimit 配置可以和开发商量目前设置为最大
contractSizeLimit 合约大小限制
固定配置
nonce
difficulty 
mixHash 用于伊斯坦布尔区块识别

alloc 初始化钱包及金额
blockchain 初始化共识节点个数及key key.pub

4、创建创世块文件及节点key key.pub

# 二进制执行命令
besu operator generate-blockchain-config --config-file=ibftConfigFile.json --to=network --private-key-file-name=key

# docker方式执行 ibftConfigFile.json需要在当前目录下
docker run --rm -it --privileged --user root -v $PWD:/abc hyperledger/besu:21.10.1 operator generate-blockchain-config --config-file=/abc/ibftConfigFile.json --to=/abc/network --private-key-file-name=key

# network目录结构 
network
├── genesis.json # 创世块文件
└── keys
    ├── 0xc003bf00eea7331fa961b65cd4cf873c9ba42b3c #账户地址
    │   ├── key # 账户私钥
    │   └── key.pub # 账户公钥 去掉0x 后面的就为enode
    ├── 0xd4390c18acfc2dc6145a2e929bc4dc42a89e3f76
    │   ├── key
    │   └── key.pub
    ├── 0xe4b2d18d8deb825ddc9f17f030f496718e592197
    │   ├── key
    │   └── key.pub
    └── 0xfa1c09fe2f7ecdc50245ade6a80154bb97bb2b4c
        ├── key
        └── key.pub

5、创建对等节点文件static-nodes.json

[
  "enode://f3d968bbd2a0f93f2b4eb82ab37e3b4a99aa187b32ce4984b157c1a996a107cfc3171ddd2615f3de3a8a75486d96f55390f410a77293ca812254d095c449a493@10.0.7.189:30303",
  "enode://0e9dcf6c0c59f333ddb9f2c6a727f2931939e478a9405e14325574ff6fc02f68d66408d366f2bf47f1ac97c82008720ee3c9a2256a0fb6098e5677cdf555277f@10.0.7.189:30305",
  "enode://de4c0184b737cf882815eed85125add734695a6d35d40838f6fcfa158c3e11e5568daa84a0923392a5f2a58e09d815dc7fcc0a98739c849305155caab3e4d2d6@10.0.7.189:30304",
  "enode://d6fba24ee98ef34c4f83b7f2940ba1ee65672222287a1713e53cc7cd4c35be64f4ccca9c3dbbb02b3dde1d84b7afbe05474be66ca25814d7a4aadd11839a2abb@10.0.7.189:30306"
]

配置解释

f3d968bbd2a0f93f2b4eb82ab37e3b4a99aa187b32ce4984b157c1a996a107cfc3171ddd2615f3de3a8a75486d96f55390f410a77293ca812254d095c449a493 节点地址标识 从key.pub中获取 将0x 去掉即可
10.0.7.189 节点IP
30303 p2p端口

6、创建节点启动目录

# 创建目录
mkdir  node{1..4}/data -p

# 将账户地址下的key key.pub 分别拷贝到node1-node4 data目录中
cp network/0xc003bf00eea7331fa961b65cd4cf873c9ba42b3c/* node1/data/
cp network/0xd4390c18acfc2dc6145a2e929bc4dc42a89e3f76/* node2/data/
cp network/0xe4b2d18d8deb825ddc9f17f030f496718e592197/* node3/data/
cp network/0xfa1c09fe2f7ecdc50245ade6a80154bb97bb2b4c/* node4/data/

# 将创世块文件拷贝到node1-node4下
cp network/genesis.json node1/
cp network/genesis.json node2/
cp network/genesis.json node3/
cp network/genesis.json node4/

7、创建节点配置文件config.json

# Valid TOML config file 数据目录
data-path="/bs/data" # Path

# Chain 创世文件
genesis-file="/bs/genesis.json" # Path to the custom genesis file

# Mining 开启挖矿
miner-enabled=true
# miner-coinbase="0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"
# 发放奖励指定账户
miner-coinbase="0x0000000000000000000000000000000000000000"

min-gas-price="0"

# 以下3块(p2p\rpc\ws)的host注意设置本机可访问的内外网IP
p2p-host="0.0.0.0"
p2p-port=30303
#max-peers=42
# 第一次启动先注释掉,启动之后复制enodeURL配置好在打开注释,引导节点也是需要这样做,配置自己的enodeURL即可
#bootnodes=["enode://f3d968bbd2a0f93f2b4eb82ab37e3b4a99aa187b32ce4984b157c1a996a107cfc3171ddd2615f3de3a8a75486d96f55390f410a77293ca812254d095c449a493@10.0.10.73:30303"]

# RPC 接口配置
rpc-http-enabled=true
rpc-http-host="0.0.0.0"
rpc-http-port=8545
rpc-http-cors-origins=["all"]

# WS请求配置
rpc-ws-enabled=true
rpc-ws-host="0.0.0.0"
rpc-ws-port=2829

host-allowlist=["*"]

# 用于远程管理 管理方法需要添加ADMIN支持
#rpc-http-api=["ADMIN","ETH","NET","IBFT","WEB3"]
rpc-http-api=["ADMIN","EEA","WEB3","ETH","NET","PRIV","PERM","IBFT"]
rpc-ws-api=["ADMIN","EEA","WEB3","ETH","NET","PRIV","PERM","IBFT"]

revert-reason-enabled=true

# 用于调试
#logging="DEBUG"

# 将配置文件拷贝到node1-node4 下
cp config.json node1
cp config.json node2
cp config.json node3
cp config.json node4
注: 其他节点修改p2p-port 、rpc-http-port 、rpc-ws-port

8、创建docker-compose启动

创建启动脚本

#!/bin/sh
besu --config-file=/bs/config.json

创建docker-compose.yaml

version: '3'
services:
  besu:
    container_name: besu1
    image: hyperledger/besu:21.10.1
    restart: always
    user: root
    working_dir: /bs
    entrypoint: ./start.sh
    volumes:
      - ./:/bs
    ports:
      - "30303:30303"
      - "8545:8545"
      - "2829:2829"
    
注 其他节点修改对应端口号

9、创世块文件genesis.json解读

{
  "config" : {
    "chainId" : 1337,
    "muirglacierblock" : 0,
    "ibft2" : {
      "blockperiodseconds" : 2,
      "epochlength" : 30000,
      "requesttimeoutseconds" : 4
    }
  },
  "nonce" : "0x0",
  "timestamp" : "0x58ee40ba",
  "gasLimit" : "0x1fffffffffffff",
  "difficulty" : "0x1",
  "mixHash" : "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
  "coinbase" : "0x0000000000000000000000000000000000000000",
  "alloc" : {
    "fe3b557e8fb62b89f4916b721be55ceb828dbd73" : {
      "privateKey" : "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
      "comment" : "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance" : "0xad78ebc5ac6200000"
    },
    "627306090abaB3A6e1400e9345bC60c78a8BEf57" : {
      "privateKey" : "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
      "comment" : "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance" : "90000000000000000000000"
    },
    "f17f52151EbEF6C7334FAD080c5704D77216b732" : {
      "privateKey" : "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
      "comment" : "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance" : "90000000000000000000000"
    }
  },
  "extraData" : "0xf87ea00000000000000000000000000000000000000000000000000000000000000000f85494aea9a4e1787587a091c2338d3d54e176a449230694f967d7e6ff24e610f6da5fe5153c7c42525cf3cb942d70b42854f074528ff203a051912755a4a3ada494d3ef04426c0ea78c7ae9c9a1f5074210ff926424808400000000c0"
}
extraData 来源是由初始化节点账户rlp编码后得到
生成命令 extraData在创建创世块文件是自动添加的 这里只是演示如何手动生成
besu rlp encode --from=toEncode.json
toEncode.json 内容是去掉0x后的账户地址
["c003bf00eea7331fa961b65cd4cf873c9ba42b3c","d4390c18acfc2dc6145a2e929bc4dc42a89e3f76","e4b2d18d8deb825ddc9f17f030f496718e592197","fa1c09fe2f7ecdc50245ade6a80154bb97bb2b4c"]

10、日志检查节点出块

2023-09-01 09:08:04.310+00:00 | nioEventLoopGroup-3-7 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:09.311+00:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:14.311+00:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:19.312+00:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:24.312+00:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:29.313+00:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, waiting for peers: 4
2023-09-01 09:08:30.210+00:00 | pool-8-thread-1 | INFO  | IbftRound | Importing block to chain. round=ConsensusRoundIdentifier{Sequence=1, Round=3}, hash=0x9caa1f5e9c024904218937a20cbd46439bae7689582ad8957bccd61caef9279c
2023-09-01 09:08:30.233+00:00 | pool-8-thread-1 | INFO  | IbftBesuControllerBuilder | Imported #1 / 0 tx / 0 pending / 0 (0.0%) gas / (0x9caa1f5e9c024904218937a20cbd46439bae7689582ad8957bccd61caef9279c)
2023-09-01 09:08:32.058+00:00 | pool-8-thread-1 | INFO  | IbftBesuControllerBuilder | Imported #2 / 0 tx / 0 pending / 0 (0.0%) gas / (0xf146d547483c2ff0ddc7543e16e4549905ae350d72db8e8ec17b70cdffbe90ed)
2023-09-01 09:08:32.058+00:00 | EthScheduler-Workers-0 | INFO  | PersistBlockTask | Imported #2 / 0 tx / 0 om / 0 (0.0%) gas / (0xf146d547483c2ff0ddc7543e16e4549905ae350d72db8e8ec17b70cdffbe90ed) in 0.012s. Peers: 4
2023-09-01 09:08:34.045+00:00 | pool-8-thread-1 | INFO  | IbftBesuControllerBuilder | Produced #3 / 0 tx / 0 pending / 0 (0.0%) gas / (0x336cc0da8bbdf3fdbd8146e7b83acd7c694a27374758b095fc542e2b03c3ddea)
2023-09-01 09:08:36.034+00:00 | pool-8-thread-1 | INFO  | IbftBesuControllerBuilder | Imported #4 / 0 tx / 0 pending / 0 (0.0%) gas / (0xd730f2f86b0f8873db17d2b985fa55c11a054533b6a232764039b9ba0143b9d8)

11、添加共识节点

方法一

# 复制一个新的ibftConfigFile.json
# 新的ibftConfigFile.json 文件只是为了生成新曾共识节点的key 和key.pub,需要几个节点在"count"字段自行修改 这里新增一个共识 修改为1,命令生成的genesis.json 需要删除,并且命令--to不能覆盖之前的目录
besu operator generate-blockchain-config --config-file=ibftConfigFile.json --to=newnetwork --private-key-file-name=key
{
 "genesis": {
   "config": {
      "chainId": 1337,
      "muirglacierblock": 0,
      "ibft2": {
        "blockperiodseconds": 2,
        "epochlength": 30000,
        "requesttimeoutseconds": 4
      }
    },
    "nonce": "0x0",
    "timestamp": "0x58ee40ba",
    "gasLimit": "0x1fffffffffffff"
    "difficulty": "0x1",
    "mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "alloc": {
       "fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
          "privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
          "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
          "balance": "0xad78ebc5ac6200000"
       },
       "627306090abaB3A6e1400e9345bC60c78a8BEf57": {
         "privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       },
       "f17f52151EbEF6C7334FAD080c5704D77216b732": {
         "privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       }
      }
 },
 "blockchain": {
   "nodes": {
     "generate": true,
       "count": 1
   }
 }
}

方法二

# besu --data-path=newnode public-key export-address 输出结果
[root@ip-172-31-40-249 test]# besu --data-path=besu public-key export-address
2023-09-01 17:43:55.869+08:00 | main | INFO  | KeyPairUtil | Generated new public key 0xa226ec5acd80dda04332c12cdb318b75e833f782932dc249513950277ecd614619f29137673ebe4fe685b3102cb66f664b375c03242bf131203263a47d4742f2 and stored it to /bs/test/newnode/key
0xa3ae963858a88d04f451dc215103905884c73c6f
[root@ip-172-31-40-249 test]# 
[root@ip-172-31-40-249 test]# ll newnode/
total 4
-rw------- 1 root root 66 Sep  1 17:43 key

0xa3ae963858a88d04f451dc215103905884c73c6f 为钱包地址
0xa226ec5acd80dda04332c12cdb318b75e833f782932dc249513950277ecd614619f29137673ebe4fe685b3102cb66f664b375c03242bf131203263a47d4742f2 及为key.pub

整理node5 启动文件

cp genesis.json node5
创建 config.json node5
创建 start.sh node5
创建 docker-compose.yaml node5
cp newnode/key node5/data
cp newnode/key.pub node5/data

共识提权

# 执行需要超过半数节点进行投票

curl -X POST --data '{"jsonrpc":"2.0","method":"ibft_proposeValidatorVote","params":["0xa3ae963858a88d04f451dc215103905884c73c6f", true], "id":1}' http://127.0.0.1:8545


12、共识查询

curl -X POST --data '{"jsonrpc":"2.0","method":"ibft_getValidatorsByBlockNumber","params":["latest"], "id":1}' http://127.0.0.1:8545

13、添加对等节点操作

# 添加节点
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}' http://127.0.0.1:8545


# 查询快高
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":51}' http://127.0.0.1:8545

curl -X POST -H "Content-Type: application/json" --data '{ "query": "{block{number}}"}' http://localhost:8547/graphql


# 查询块hash
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x68B3", true],"id":1}' http://127.0.0.1:8545


# 查询块交易数
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByNumber","params":["0xe8"],"id":51}' http://127.0.0.1:8545

curl -X POST -H "Content-Type: application/json" --data '{ "query": "{block(number:232){transactionCount}}"}' http://localhost:8547/graphql


# 其他命令详见
https://besu.hyperledger.org/public-networks/reference/api


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,928评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,192评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,468评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,186评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,295评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,374评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,403评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,186评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,610评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,906评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,075评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,755评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,393评论 3 320
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,079评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,313评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,934评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,963评论 2 351

推荐阅读更多精彩内容