328-fabric之创始区块和通道








fabric之创始区块和通道









我们现在来生成创始区块和通道文件
生成创始区块和通道文件
也是需要先编写配置文件

之前生成用户账号的时候
我们是用了showtemplate命令

但是生成创始区块和通道是没有模板的命令的
所以我们需要通过其他方法获取一个模板







获取模板
我们需要在first-network目录下找到配置文件
我们打开
/hyperledger-fabric/fabric-samples/first-network
然后ls一下
base                docker-compose-cli.yaml           eyfn.sh
byfn.sh             docker-compose-couch-org3.yaml    org3-artifacts
channel-artifacts   docker-compose-couch.yaml         README.md
configtx.yaml       docker-compose-e2e-template.yaml  scripts
crypto-config       docker-compose-e2e.yaml
crypto-config.yaml  docker-compose-org3.yaml

然后我们需要的配置文件就是 configtx.yaml
我们把这个配置文件作为我们的模板
我们把configtx.yaml复制到其他目录








我们需要修改configtx.yaml的三部分内容
1.配置组织信息
	1.orderer组织	
	2.peer组织
2.配置orderer节点的属性
	1.如何生成一个区块
		1.时间频率
		2.块大小
		3.消息条数
3.对网络的总结	
	1.如何生成创始区块文件
	2.如何生成通道文件









我们来看一下configtx.yaml文件

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

---
################################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities which will
#   be referenced later in the configuration.
#
################################################################################
Organizations:

    # SampleOrg defines an MSP using the sampleconfig.  It should never be used
    # in production but may be used as a template for other definitions
    - &OrdererOrg
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: OrdererOrg

        # ID to load the MSP definition as
        ID: OrdererMSP

        # MSPDir is the filesystem path which contains the MSP configuration
        MSPDir: crypto-config/ordererOrganizations/example.com/msp

    - &Org1
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org1MSP

        # ID to load the MSP definition as
        ID: Org1MSP

        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org2MSP

        # ID to load the MSP definition as
        ID: Org2MSP

        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org2.example.com
              Port: 7051

################################################################################
#
#   SECTION: Capabilities
#
#   - This section defines the capabilities of fabric network. This is a new
#   concept as of v1.1.0 and should not be utilized in mixed networks with
#   v1.0.x peers and orderers.  Capabilities define features which must be
#   present in a fabric binary for that binary to safely participate in the
#   fabric network.  For instance, if a new MSP type is added, newer binaries
#   might recognize and validate the signatures from this type, while older
#   binaries without this support would be unable to validate those
#   transactions.  This could lead to different versions of the fabric binaries
#   having different world states.  Instead, defining a capability for a channel
#   informs those binaries without this capability that they must cease
#   processing transactions until they have been upgraded.  For v1.0.x if any
#   capabilities are defined (including a map with all capabilities turned off)
#   then the v1.0.x peer will deliberately crash.
#
################################################################################
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.
    Global: &ChannelCapabilities
        # V1.1 for Global is a catchall flag for behavior which has been
        # determined to be desired for all orderers and peers running v1.0.x,
        # but the modification of which would cause incompatibilities.  Users
        # should leave this flag set to true.
        V1_1: true

    # Orderer capabilities apply only to the orderers, and may be safely
    # manipulated without concern for upgrading peers.  Set the value of the
    # capability to true to require it.
    Orderer: &OrdererCapabilities
        # V1.1 for Order is a catchall flag for behavior which has been
        # determined to be desired for all orderers running v1.0.x, but the
        # modification of which  would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_1: true

    # Application capabilities apply only to the peer network, and may be safely
    # manipulated without concern for upgrading orderers.  Set the value of the
    # capability to true to require it.
    Application: &ApplicationCapabilities
        # V1.2 for Application is a catchall flag for behavior which has been
        # determined to be desired for all peers running v1.0.x, but the
        # modification of which would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_2: true

################################################################################
#
#   SECTION: Application
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults

    # Organizations is the list of orgs which are defined as participants on
    # the application side of the network
    Organizations:

################################################################################
#
#   SECTION: Orderer
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    # Available types are "solo" and "kafka"
    OrdererType: solo

    Addresses:
        - orderer.example.com:7050

    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s

    # Batch Size: Controls the number of messages batched into a block
    BatchSize:

        # Max Message Count: The maximum number of messages to permit in a batch
        MaxMessageCount: 10

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 99 MB

        # Preferred Max Bytes: The preferred maximum number of bytes allowed for
        # the serialized messages in a batch. A message larger than the preferred
        # max bytes will result in a batch larger than preferred max bytes.
        PreferredMaxBytes: 512 KB

    Kafka:
        # Brokers: A list of Kafka brokers to which the orderer connects
        # NOTE: Use IP:port notation
        Brokers:
            - 127.0.0.1:9092

    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:

################################################################################
#
#   Profile
#
#   - Different configuration profiles may be encoded here to be specified
#   as parameters to the configtxgen tool
#
################################################################################
Profiles:

    TwoOrgsOrdererGenesis:
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
    TwoOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities








然后我们看一下configtx.yaml配置文件里面的信息

Organizations:
    - &OrdererOrg	#OrdererOrg变量名
	Name: OrdererOrg	#orderer组织的名字
	Id: OrdererMSP		#orderer组织的id
	#orderer组织的组织账号目录
	MSPDir: crypto-config/ordererOrganizations/abc.com/msp
   
    - &Org1
	Name: Org1MSP
	ID: Org1MSP
	MSPDir: crypto-config/peerOrganizations/org1.abc.com/msp
	AnchorPeers:
	      - Host: peer0.org1.abc.com
		Port: 7051





然后来看orderer属性设置
Orderer: &OrdererDefaults
	OrdererType: solo		#使用的共识机制,solo(测试),kafka(工作场景)
	Addresses:			#orderer排序节点地址
		- orderer.abc.com:7050		#7050是orderer容器开放的端口
	BatchTime: 2s		#每隔多少时间生成一个区块
	BatchSize:
		MaxMessageCount: 100		#消息>=100条,生成一个区块
		AbsoluteMaxBytes: 99MB		#消息总大小>=99MB,生成一个区块,推荐32MB-64MB
		PreferredMaxBytes: 512KB	#建议的区块大小
	Kafka:
		Brokers:
			- 127.0.0.1:9092
	








前面设置的东西都通过&符号放到了变量里面
就是为了在最后的Profiles里面
通过*符号来取出变量的值

我们看一下Profiles

Profiles:

    TwoOrgsOrdererGenesis:		#创始区块信息
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:			#联盟
            SampleConsortium:
                Organizations:		#peer组织
                    - *Org1
                    - *Org2
    TwoOrgsChannel:			#关于通道的信息
        Consortium: SampleConsortium	#加入到哪个联盟中
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities









然后我们来改写configtx.yaml文件

我们来看一下改完之后的configtx.yaml


Organizations:

    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: crypto-config/ordererOrganizations/abc.com/msp

    - &aaa
        Name: aaa
        ID: aaa
        MSPDir: crypto-config/peerOrganizations/aaa.abc.com/msp
        AnchorPeers:
            - Host: peer0.aaa.abc.com
              Port: 7050

    - &bbb
        Name: bbb
        ID: bbb
        MSPDir: crypto-config/peerOrganizations/bbb.abc.com/msp
        AnchorPeers:
            - Host: peer0.bbb.abc.com
              Port: 7050


Capabilities:
    Global: &ChannelCapabilities
        V1_1: true
    Orderer: &OrdererCapabilities
        V1_1: true
    Application: &ApplicationCapabilities
        V1_2: true


Application: &ApplicationDefaults
    Organizations:


Orderer: &OrdererDefaults
    OrdererType: solo
    Addresses:
        - orderer.abc.com:7050
    BatchTimeout: 2s
    BatchSize:
        MaxMessageCount: 10
        AbsoluteMaxBytes: 99 MB
        PreferredMaxBytes: 512 KB
    Kafka:
        Brokers:
            - 127.0.0.1:9092
    Organizations:


Profiles:

    Genesis:
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *aaa
                    - *bbb
    Channel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *aaa
                - *bbb
            Capabilities:
                <<: *ApplicationCapabilities









然后我们用命令来生成创始区块和通道文件
configtxgen -profile Genesis -outputBlock genesis.block

/test$ configtxgen -profile Genesis -outputBlock genesis.block
2019-03-23 15:46:45.859 CST [common/tools/configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen is deprecated.  Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
2019-03-23 15:46:45.859 CST [common/tools/configtxgen] main -> INFO 002 Loading configuration
2019-03-23 15:46:45.867 CST [common/tools/configtxgen/encoder] NewChannelGroup -> WARN 003 Default policy emission is deprecated, please include policy specificiations for the channel group in configtx.yaml
2019-03-23 15:46:45.867 CST [common/tools/configtxgen/encoder] NewOrdererGroup -> WARN 004 Default policy emission is deprecated, please include policy specificiations for the orderer group in configtx.yaml
2019-03-23 15:46:45.868 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specificiations for the orderer org group OrdererOrg in configtx.yaml
2019-03-23 15:46:45.906 CST [msp] getMspConfig -> INFO 006 Loading NodeOUs
2019-03-23 15:46:45.906 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 007 Default policy emission is deprecated, please include policy specificiations for the orderer org group aaa in configtx.yaml
2019-03-23 15:46:45.907 CST [msp] getMspConfig -> INFO 008 Loading NodeOUs
2019-03-23 15:46:45.907 CST [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 009 Default policy emission is deprecated, please include policy specificiations for the orderer org group bbb in configtx.yaml
2019-03-23 15:46:45.907 CST [common/tools/configtxgen] doOutputBlock -> INFO 00a Generating genesis block
2019-03-23 15:46:45.907 CST [common/tools/configtxgen] doOutputBlock -> INFO 00b Writing genesis block

然后ls一下,
configtx.yaml  crypto-config  crypto-config.yaml  genesis.block

我们发现
成功生成了
genesis.block创始区块文件









然后我们来生成通道文件
configtxgen -profile Channel -outputCreateChannelTx channel.tx

/test$ configtxgen -profile Channel -outputCreateChannelTx channel.tx
2019-03-23 15:53:54.136 CST [common/tools/configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen is deprecated.  Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
2019-03-23 15:53:54.136 CST [common/tools/configtxgen] main -> INFO 002 Loading configuration
2019-03-23 15:53:54.144 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2019-03-23 15:53:54.144 CST [common/tools/configtxgen/encoder] NewApplicationGroup -> WARN 004 Default policy emission is deprecated, please include policy specificiations for the application group in configtx.yaml
2019-03-23 15:53:54.145 CST [msp] getMspConfig -> INFO 005 Loading NodeOUs
2019-03-23 15:53:54.145 CST [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 006 Default policy emission is deprecated, please include policy specificiations for the application org group aaa in configtx.yaml
2019-03-23 15:53:54.145 CST [msp] getMspConfig -> INFO 007 Loading NodeOUs
2019-03-23 15:53:54.145 CST [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 008 Default policy emission is deprecated, please include policy specificiations for the application org group bbb in configtx.yaml
2019-03-23 15:53:54.147 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 009 Writing new channel tx

然后ls一下看一下
channel.tx configtx.yaml  crypto-config  crypto-config.yaml  genesis.block

成功生成了channel.tx通道文件




 

你可能感兴趣的:(fabric)