日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

fabric使用配置文件configtx.yaml生成创世区块时遇到的坑

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fabric使用配置文件configtx.yaml生成创世区块时遇到的坑 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先我的fabric版本是2.3.0,在參考馮翔老師的《區塊鏈開發實戰》之Hyperledger fabric關鍵技術這本書上的配置文件configtx.yaml生成創世區塊時出現了很多問題。
書上的配置文件configtx.yaml內容為:

Profiles:TestTwoOrgsOrdererGenesis:Orderer:<<: *OrdererDefaultsOrganizations:- *OrdererOrgConsortiums:SampleConsortium:Organizations:- *Org1- *Org2TestTwoOrgsChannel:Consortium: SampleConsortiumApplication:<<: *ApplicationDefaultsOrganizations:- *Org1- *Org2 Organizations:- &OrdererOrgName: OrdererOrgID: OrdererMSPMSPDir: crypto-config/ordererOrganizations/example.com/msp- &Org1Name: Org1MSPID: Org1MSPMSPDir: crypto-config/peerOrganizations/org1.example.com/mspAnchorPeers:- Host: peer0.org1.example.comPort: 7051- &Org2Name: Org2MSPID: Org2MSPMSPDir: crypto-config/peerOrganizations/org2.example.com/mspAnchorPeers:- Host: peer0.org2.example.comPort: 7051 Orderer: &OrdererDefaultsOrdererType: soloAddresses:- orderer.example.com:7050BatchTimeout: 2sBatchSize:MaxMessageCount: 10AbsoluteMaxBytes: 99 MBPreferredMaxBytes: 512 KBKafka:Brokers:- 127.0.0.1:9092Organizations: Application: &ApplicationDefaultsOrganizations:

上述的配置文件在fabric2.3.0中出現了以下問題:

Error 1:Error reading configuration: While parsing config: yaml: unknown anchor 'OrdererDefaults' referenced [recovered]

因為使用的是最新版本,與書本上的版本不同,而最新版本在結構上做了一些改動。在使用‘*’之前,一定要有‘&’定義過了。所以需要把Profiles的內容移到最后。

Error 2:Error reading configuration: yaml: line 50: did not find expected key


這個是空格出了問題,在提示的行號附近檢查空格是否出錯。.yaml文件不能使用tab鍵。

Error 3:Error reading configuration: yaml: map merge requires map or sequence of maps as the value


這個錯誤說的是什么映射的問題。我實在不知道我的configtx.yaml到底是哪里寫錯了,因為我剛開始是手打的,就有很多空格問題啊等等。這個問題在StackOverflow上有解答:
就是本文Error 1里提到的,然而沒有用。
最后是直接復制可以用的configtx.yaml,在上面進行修改,切記不要修改空格。就沒有這些問題了。

Error 4:Error on outputBlock: could not create bootstrapper: could not create channel group: error adding policies to channel group: no policies defined


這個錯誤也是因為新版本!在configtx.yaml中要有相對應的policies才行。

我根據fabric-samples里面的配置文件修改了configtx.yaml。
修正后的configtx.yaml:

Organizations:- &OrdererOrgName: OrdererOrgID: OrdererMSPMSPDir: ../fabricconfig/crypto-config/ordererOrganizations/example.com/mspPolicies:Readers:Type: SignatureRule: "OR('OrdererMSP.member')"Writers:Type: SignatureRule: "OR('OrdererMSP.member')"Admins:Type: SignatureRule: "OR('OrdererMSP.admin')"Endorsement:Type: SignatureRule: "OR('OrdererMSP.member')"- &Org1Name: Org1MSPID: Org1MSPMSPDir: ../fabricconfig/crypto-config/peerOrganizations/org1.example.com/mspPolicies:Readers:Type: SignatureRule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"Writers:Type: SignatureRule: "OR('Org1MSP.admin', 'Org1MSP.client')"Admins:Type: SignatureRule: "OR('Org1MSP.admin')"Endorsement:Type: SignatureRule: "OR('Org1MSP.peer')"AnchorPeers:- Host: peer0.org1.example.comPort: 7051- &Org2Name: Org2MSPID: Org2MSPMSPDir: ../fabricconfig/crypto-config/peerOrganizations/org2.example.com/mspPolicies:Readers:Type: SignatureRule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"Writers:Type: SignatureRule: "OR('Org2MSP.admin', 'Org2MSP.client')"Admins:Type: SignatureRule: "OR('Org2MSP.admin')"Endorsement:Type: SignatureRule: "OR('Org2MSP.peer')"AnchorPeers:- Host: peer0.org2.example.comPort: 7051 Capabilities:# Channel capabilities apply to both the orderers and the peers and must be# supported by both.# Set the value of the capability to true to require it.Channel: &ChannelCapabilities# V2.0 for Channel is a catchall flag for behavior which has been# determined to be desired for all orderers and peers running at the v2.0.0# level, but which would be incompatible with orderers and peers from# prior releases.# Prior to enabling V2.0 channel capabilities, ensure that all# orderers and peers on a channel are at v2.0.0 or later.V2_0: true# Orderer capabilities apply only to the orderers, and may be safely# used with prior release peers.# Set the value of the capability to true to require it.Orderer: &OrdererCapabilities# V1.1 for Orderer is a catchall flag for behavior which has been# determined to be desired for all orderers running at the v1.1.x# level, but which would be incompatible with orderers from prior releases.# Prior to enabling V2.0 orderer capabilities, ensure that all# orderers on a channel are at v2.0.0 or later.V2_0: true# Application capabilities apply only to the peer network, and may be safely# used with prior release orderers.# Set the value of the capability to true to require it.Application: &ApplicationCapabilities# V2.0 for Application enables the new non-backwards compatible# features and fixes of fabric v2.0.# Prior to enabling V2.0 orderer capabilities, ensure that all# orderers on a channel are at v2.0.0 or later.V2_0: trueApplication: &ApplicationDefaultsOrganizations:# Policies defines the set of policies at this level of the config tree# For Application policies, their canonical path is# /Channel/Application/<PolicyName>Policies: &ApplicationDefaultPoliciesLifecycleEndorsement:Type: ImplicitMetaRule: "MAJORITY Endorsement"Endorsement:Type: ImplicitMetaRule: "MAJORITY Endorsement"Readers:Type: ImplicitMetaRule: "ANY Readers"Writers:Type: ImplicitMetaRule: "ANY Writers"Admins:Type: ImplicitMetaRule: "MAJORITY Admins"# Capabilities describes the application level capabilities, see the# dedicated Capabilities section elsewhere in this file for a full# descriptionCapabilities:<<: *ApplicationCapabilitiesOrderer: &OrdererDefaultsOrdererType: soloAddresses:- orderer.example.com:7050BatchTimeout: 2sBatchSize:MaxMessageCount: 10AbsoluteMaxBytes: 99 MBPreferredMaxBytes: 512 KBKafka:Brokers:- 127.0.0.1:9092Organizations:# Policies defines the set of policies at this level of the config tree# For Orderer policies, their canonical path is# /Channel/Orderer/<PolicyName>Policies:Readers:Type: ImplicitMetaRule: "ANY Readers"Writers:Type: ImplicitMetaRule: "ANY Writers"Admins:Type: ImplicitMetaRule: "MAJORITY Admins"# BlockValidation specifies what signatures must be included in the block# from the orderer for the peer to validate it.BlockValidation:Type: ImplicitMetaRule: "ANY Writers"# Capabilities describes the orderer level capabilities, see the# dedicated Capabilities section elsewhere in this file for a full# descriptionCapabilities:<<: *OrdererCapabilities################################################################################ # # CHANNEL # # This section defines the values to encode into a config transaction or # genesis block for channel related parameters. # ################################################################################ Channel: &ChannelDefaults# Policies defines the set of policies at this level of the config tree# For Channel policies, their canonical path is# /Channel/<PolicyName>Policies:# Who may invoke the 'Deliver' APIReaders:Type: ImplicitMetaRule: "ANY Readers"# Who may invoke the 'Broadcast' APIWriters:Type: ImplicitMetaRule: "ANY Writers"# By default, who may modify elements at this config levelAdmins:Type: ImplicitMetaRule: "MAJORITY Admins"# Capabilities describes the channel level capabilities, see the# dedicated Capabilities section elsewhere in this file for a full# descriptionCapabilities:<<: *ChannelCapabilitiesProfiles:TestTwoOrgsOrdererGenesis:<<: *ChannelDefaultsOrderer:<<: *OrdererDefaultsOrganizations:- <<: *OrdererOrgConsortiums:SampleConsortium:Organizations:- <<: *Org1- <<: *Org2TestTwoOrgsChannel:<<: *ChannelDefaultsConsortium: SampleConsortiumApplication:<<: *ApplicationDefaultsOrganizations:- <<: *Org1- <<: *Org2

還有個需要注意的是MSPDir的值是相對路徑。
成功生成創世區塊:

總結

以上是生活随笔為你收集整理的fabric使用配置文件configtx.yaml生成创世区块时遇到的坑的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。