configtx.yaml是Hyperledger Fabric區塊鏈網絡運維工具configtxgen用於生成通道創世塊或通道交易的配置文件,configtx.yaml的內容直接決定了所生成的創世區塊的內容。本文將給出configtx.yaml的詳細中文說明。算法
若是須要快速掌握Fabric區塊鏈的鏈碼與應用開發,推薦訪問匯智網的在線互動教程:網絡
Capabilities段用來定義fabric網絡的能力。這是版本v1.0.0引入的一個新的配置段,當與版本v1.0.x的對等節點與排序節點混合組網時不可以使用。app
Capabilities段定義了fabric程序要加入網絡所必須支持的特性。例如,若是添加了一個新的MSP類型,那麼更新的程序可能會根據該類型識別並驗證簽名,可是老版本的程序就沒有辦法驗證這些交易。這可能致使不一樣版本的fabric程序中維護的世界狀態不一致。運維
所以,經過定義通道的能力,就明確了不知足該能力要求的fabric程序,將沒法處理交易,除非升級到新的版本。對於v1.0.x的程序而言,若是在Capabilities段定義了任何能力,即便聲明不須要支持這些能力,都會致使其有意崩潰。函數
Capabilities: # Global配置同時應用於排序節點和對等節點,而且必須被兩種節點同時支持。 # 將該配置項設置爲ture代表要求節點具有該能力 Global: &ChannelCapabilities V1_3: true # Orderer配置僅應用於排序節點,不需考慮對等節點的升級。將該配置項 # 設置爲true代表要求排序節點具有該能力 Orderer: &OrdererCapabilities V1_1: true # Application配置僅應用於對等網絡,不需考慮排序節點的升級。將該配置項 # 設置爲true代表要求對等節點具有該能力 Application: &ApplicationCapabilities V1_3: true
Organizations配置段用來定義組織機構實體,以便在後續配置中引用。例如,下面的配置文件中,定義了三個機構,能夠分別使用ExampleCom、Org1ExampleCom和Org2ExampleCom引用其配置:工具
Organizations: - &ExampleCom Name: ExampleCom ID: example.com AdminPrincipal: Role.ADMIN MSPDir: ./ordererOrganizations/example.com/msp Policies: Readers: Type: Signature Rule: OR('example.com.member') Writers: Type: Signature Rule: OR('example.com.member') Admins: Type: Signature Rule: OR('example.com.admin') Endorsement: Type: Signature Rule: OR('example.com.member') - &Org1ExampleCom Name: Org1ExampleCom ID: org1.example.com MSPDir: ./peerOrganizations/org1.example.com/msp AdminPrincipal: Role.ADMIN AnchorPeers: - Host: peer0.org1.example.com Port: 7051 Policies: Readers: Type: Signature Rule: OR('org1.example.com.member') Writers: Type: Signature Rule: OR('org1.example.com.member') Admins: Type: Signature Rule: OR('org1.example.com.admin') Endorsement: Type: Signature Rule: OR('org1.example.com.member') - &Org2ExampleCom Name: Org2ExampleCom ID: org2.example.com MSPDir: ./peerOrganizations/org2.example.com/msp AdminPrincipal: Role.ADMIN AnchorPeers: - Host: peer0.org2.example.com Port: 7051 Policies: Readers: Type: Signature Rule: OR('org2.example.com.member') Writers: Type: Signature Rule: OR('org2.example.com.member') Admins: Type: Signature Rule: OR('org2.example.com.admin') Endorsement: Type: Signature Rule: OR('org2.example.com.member')
Orderer配置段用來定義要編碼寫入創世區塊或通道交易的排序節點參數。區塊鏈
Orderer: &OrdererDefaults # 排序節點類型用來指定要啓用的排序節點實現,不一樣的實現對應不一樣的共識算法。 # 目前可用的類型爲:solo和kafka OrdererType: solo Addresses: - orderer0.example.com:7050 BatchTimeout: 2s BatchSize: MaxMessageCount: 10 AbsoluteMaxBytes: 98 MB PreferredMaxBytes: 512 KB MaxChannels: 0 Kafka: Brokers: - kafka0:9092 - kafka1:9092 - kafka2:9092 - kafka3:9092 Organizations: # 定義本層級的排序節點策略,其權威路徑爲 /Channel/Orderer/<PolicyName> Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins # BlockValidation配置項指定了哪些簽名必須包含在區塊中,以便對等節點進行驗證 BlockValidation: Type: ImplicitMeta Rule: ANY Writers # Capabilities配置描述排序節點層級的能力需求,這裏直接引用 # 前面Capabilities配置段中的OrdererCapabilities配置項 Capabilities: <<: *OrdererCapabilities
Channel配置段用來定義要寫入創世區塊或配置交易的通道參數。測試
Channel: &ChannelDefaults # 定義本層級的通道訪問策略,其權威路徑爲 /Channel/<PolicyName> Policies: Readers: Type: ImplicitMeta Rule: ANY Readers # Writes策略定義了調用Broadcast API提交交易的許可規則 Writers: Type: ImplicitMeta Rule: ANY Writers # Admin策略定義了修改本層級配置的許可規則 Admins: Type: ImplicitMeta Rule: MAJORITY Admins # Capabilities配置描通道層級的能力需求,這裏直接引用 # 前面Capabilities配置段中的ChannelCapabilities配置項 Capabilities: <<: *ChannelCapabilities
Application配置段用來定義要寫入創世區塊或配置交易的應用參數。編碼
Application: &ApplicationDefaults ACLs: &ACLsDefault # ACLs配置段爲系統中各類資源提供默認的策略。 # 這裏所說的「資源」,能夠是系統鏈碼的函數,例如qscc系統鏈碼的GetBlockByNumber方法 # 也能夠是其餘資源,例如誰能夠接收區塊事件。 # 這個配置段不是用來定義資源或API,而僅僅是定義資源的訪問控制策略 # # 用戶能夠在通道定義中重寫這些默認策略 #---New Lifecycle System Chaincode (_lifecycle) function to policy mapping for access control--# # _lifecycle系統鏈碼CommitChaincodeDefinition函數的ACL定義 _lifecycle/CommitChaincodeDefinition: /Channel/Application/Writers # _lifecycle系統鏈碼的QueryChaincodeDefinition函數的ACL定義 _lifecycle/QueryChaincodeDefinition: /Channel/Application/Readers # _lifecycle系統鏈碼的QueryNamespaceDefinitions函數的ACL定義 _lifecycle/QueryNamespaceDefinitions: /Channel/Application/Readers #---Lifecycle System Chaincode (lscc) function to policy mapping for access control---# # lscc系統鏈碼的getid函數的ACL定義 lscc/ChaincodeExists: /Channel/Application/Readers # lscc系統鏈碼的getdepspec函數的ACL定義 lscc/GetDeploymentSpec: /Channel/Application/Readers # lscc系統鏈碼的getccdata函數的ACL定義 lscc/GetChaincodeData: /Channel/Application/Readers # lscc系統鏈碼的getchaincodes函數的ACL定義 lscc/GetInstantiatedChaincodes: /Channel/Application/Readers #---Query System Chaincode (qscc) function to policy mapping for access control---# # qscc系統鏈碼的GetChainInfo函數的ACL定義 qscc/GetChainInfo: /Channel/Application/Readers # qscc系統鏈碼的GetBlockByNumber函數的ACL定義 qscc/GetBlockByNumber: /Channel/Application/Readers # qscc系統 鏈碼的GetBlockByHash函數的ACL定義 qscc/GetBlockByHash: /Channel/Application/Readers # qscc系統鏈碼的GetTransactionByID函數的ACL定義 qscc/GetTransactionByID: /Channel/Application/Readers # qscc系統鏈碼GetBlockByTxID函數的ACL定義 qscc/GetBlockByTxID: /Channel/Application/Readers #---Configuration System Chaincode (cscc) function to policy mapping for access control---# # cscc系統鏈碼的GetConfigBlock函數的ACl定義 cscc/GetConfigBlock: /Channel/Application/Readers # cscc系統鏈碼的GetConfigTree函數的ACL定義 cscc/GetConfigTree: /Channel/Application/Readers # cscc系統鏈碼的SimulateConfigTreeUpdate函數的ACL定義 cscc/SimulateConfigTreeUpdate: /Channel/Application/Readers #---Miscellanesous peer function to policy mapping for access control---# # 訪問對等節點上的鏈碼的ACL策略定義 peer/Propose: /Channel/Application/Writers # 從鏈碼中訪問其餘鏈碼的ACL策略定義 peer/ChaincodeToChaincode: /Channel/Application/Readers #---Events resource to policy mapping for access control###---# # 發送區塊事件的ACL策略定義 event/Block: /Channel/Application/Readers # 發送過濾的區塊事件的ACL策略定義 event/FilteredBlock: /Channel/Application/Readers # Organizations配置列出參與到網絡中的機構清單 Organizations: # 定義本層級的應用控制策略,其權威路徑爲 /Channel/Application/<PolicyName> Policies: &ApplicationDefaultPolicies Readers: Type: ImplicitMeta Rule: "ANY Readers" Writers: Type: ImplicitMeta Rule: "ANY Writers" Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" LifecycleEndorsement: Type: ImplicitMeta Rule: "ANY Endorsement" Endorsement: Type: ImplicitMeta Rule: "ANY Endorsement" # Capabilities配置描述應用層級的能力需求,這裏直接引用 # 前面Capabilities配置段中的ApplicationCapabilities配置項 Capabilities: <<: *ApplicationCapabilities
Profiles配置段用來定義用於configtxgen工具的配置入口。包含委員會(consortium)的配置入口能夠用來生成排序節點的創世區塊。若是在排序節點的創世區塊中正肯定義了consortium的成員,那麼能夠僅使用機構成員名稱和委員會的名稱來生成通道建立請求。spa
Profiles: # SampleInsecureSolo定義了一個使用Solo排序節點的簡單配置 SampleInsecureSolo: <<: *ChannelDefaults Orderer: <<: *OrdererDefaults Organizations: - *ExampleCom Capabilities: <<: *OrdererCapabilities Application: <<: *ApplicationDefaults Organizations: - *ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement Consortiums: SampleConsortium: Organizations: - *Org1ExampleCom - *Org2ExampleCom # SampleInsecureKafka定義了一個使用Kfaka排序節點的配置 SampleInsecureKafka: <<: *ChannelDefaults Orderer: <<: *OrdererDefaults OrdererType: kafka Addresses: - orderer0.example.com:7050 - orderer1.example.com:7050 - orderer2.example.com:7050 Organizations: - *ExampleCom Capabilities: <<: *OrdererCapabilities Application: <<: *ApplicationDefaults Organizations: - *ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement Consortiums: SampleConsortium: Organizations: - *ExampleCom - *Org1ExampleCom - *Org2ExampleCom # SampleSingleMSPSolo定義了一個使用Solo排序節點、包含單一MSP的配置 SampleSingleMSPSolo: Orderer: <<: *OrdererDefaults Organizations: - *ExampleCom Capabilities: <<: *OrdererCapabilities Application: <<: *ApplicationDefaults Organizations: - *ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement Consortiums: SampleConsortium: Organizations: - *ExampleCom - *Org1ExampleCom - *Org2ExampleCom # SampleEmptyInsecureChannel定義了一個不包含成員與訪問控制策略的通道 SampleEmptyInsecureChannel: Capabilities: <<: *ChannelCapabilities Consortium: SampleConsortium Application: Organizations: - *ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement # SysTestChannel定義了一個用於測試的通道 SysTestChannel: <<: *ChannelDefaults Capabilities: <<: *ChannelCapabilities Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1ExampleCom - *Org2ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement # SampleSingleMSPChannel定義了一個僅包含單一成員機構的通道。 # 該配置一般與SampleSingleMSPSolo或SampleSingleMSPKafka同時使用 SampleSingleMSPChannel: <<: *ChannelDefaults Capabilities: <<: *ChannelCapabilities Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1ExampleCom - *Org2ExampleCom Capabilities: <<: *ApplicationCapabilities Policies: Readers: Type: ImplicitMeta Rule: ANY Readers Writers: Type: ImplicitMeta Rule: ANY Writers Admins: Type: ImplicitMeta Rule: MAJORITY Admins LifecycleEndorsement: Type: ImplicitMeta Rule: ANY Endorsement Endorsement: Type: ImplicitMeta Rule: ANY Endorsement