Hyperledger Fabric 2.X中如何修改区块大小?具体操作步骤是什么?
修改Hyperledger Fabric区块大小AbsoluteMaxBytes的操作流程
不需要重新构建Docker镜像——peer和orderer的配置文件通常是通过Docker卷挂载到容器内的,直接修改宿主机上的configtx.yaml,再重新生成配置并更新通道即可。具体操作流程如下:
1. 修改宿主机上的configtx.yaml
找到对应通道的Profile配置块(比如TwoOrgsChannel),在Orderer节点配置下添加或修改AbsoluteMaxBytes值(单位为字节)。示例:
Profiles: TwoOrgsChannel: Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1 - *Org2 Orderer: <<: *OrdererDefaults Organizations: - *OrdererOrg AbsoluteMaxBytes: 10485760 # 设置为10MB
2. 针对新通道:重新生成通道配置交易文件
如果是要创建新通道,直接用修改后的配置生成通道交易文件:
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
如果需要修改orderer系统通道的配置,还要重新生成创世区块:
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
3. 针对已有通道:更新通道配置
如果是已经存在的通道,需要通过配置更新流程修改:
- 导出当前通道的配置块:
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem - 将配置块转换为JSON格式:
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json - 复制并修改配置文件:
编辑cp config.json modified_config.jsonmodified_config.json,找到channel_group.groups.Orderer.values.BatchSize.value.AbsoluteMaxBytes,设置为目标字节数。 - 计算配置差异并生成更新交易:
configtxlator proto_encode --input config.json --type common.Config > config.pb configtxlator proto_encode --input modified_config.json --type common.Config > modified_config.pb configtxlator compute_update --channel_id mychannel --original config.pb --updated modified_config.pb > config_update.pb configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate | jq . > config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope > config_update_in_envelope.pb - 提交配置更新:
peer channel update -f config_update_in_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
4. 重启容器使配置生效
重启相关的orderer和peer容器,确保新配置加载:
docker restart orderer.example.com peer0.org1.example.com peer0.org2.example.com
注意事项
AbsoluteMaxBytes设置过大可能影响节点同步性能,需根据业务场景合理调整。- 确保所有节点使用的
configtx.yaml配置一致,避免出现配置不兼容问题。
内容的提问来源于stack exchange,提问作者r4sk01
相关产品推荐
相关产品推荐

