1 通道配置说明
first-network的通道通过configtx.yaml进行配置。其主要包括Policy
(通道的读写权限策略等)、Capabilities
(确保网络和通道以相同的方式处理交易,使用版本号进行定义)、Channel/Application
、Channel/Orderer
、Batch size
、Channel
。
此部分内容内容后续进行补充
2 更新通道配置
此部分分为三个步骤,包括解析现有配置、修改现有配置和提交修改配置。
2.1 解析现有配置
2.1.1 生成pb文件
以protobuf格式解析现有通道配置,并创建一个名为config_block.pb的文件。
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c channel2 --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
2.1.2 解码生成json文件
configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
2.1.3 简化json文件
解析出的json文件包含大量元数据,我们需要去除后另存为config.json文件。
jq .data.data[0].payload.data.config config_block.json > config.json
2.1.4 备份json文件
为了便于比较,备份config.json文件
cp config.json modified_config.json
2.2 修改现有配置
以修改区块交易数量为例,将一个区块的交易数量提高,max_message_count
从10修改为100
vi modified_config.json
2.3 提交修改配置
2.3.1 切换环境变量
由于batchSize
属于排序节点的配置,所以这里的需要切换环境变量为OrdererMSP
CORE_PEER_LOCALMSPID=OrdererMSP
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp/
2.3.2 编码生成差异pb文件
将config.json还原为config.pb文件
configtxlator proto_encode --input config.json --type common.Config --output config.pb
将modified_config.json还原为modified_config.pb文件
configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
比较通道配置升级前后的差异,创建一个config_update.pb文件
onfigtxlator compute_update --channel_id channel2 --original config.pb --updated modified_config.pb --output config_update.pb
2.3.3 将差异配置pb文件重新编码
将config_update.pb文件解码还原为config_update.json文件。
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
将config_update.json重新编码
echo '{"payload":{"header":{"channel_header":{"channel_id":"channel2", "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 --output config_update_in_envelope.pb
2.3.4 提交差异配置
peer channel update -f config_update_in_envelope.pb -c channel2 -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem