hyperledger-fabrichyperledger

Hyperledger Fabric - "bad header" error when creating a channel


I have followed this tutorial to deploy a Hyperledger Fabric platform (one channel, one orderer and three peers, each node from their own organization). However, in the last version of the different fabric components, some of the features used in the tutorial (and in many other tutorials) are deprecated. So I have made some changes in the configtx.yaml and in the commands to fit the new versions. Everything seems to work as expected until the step where the channel genesis block must be created.

I have created the channel transaction file:

configtxgen -profile MyChannel -outputBlock ./fabric/crypto-config/ordererOrganizations/org0/orderer/mychannel.tx -channelID MyChannel

And the next step would be to generate the channel genesis block:

peer channel create -c MyChannel -f /etc/hyperledger/org1/peer1/assets/mychannel.tx -o orderer1.org0.com:7050 --outputBlock /etc/hyperledger/org1/peer1/assets/mychannel.block --tls --cafile /etc/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem

However, when I run the last command, I get the following error:

Error: Invalid channel create transaction : bad header

And the genesis block is not created.

My configtx.yaml file goes as follows:

################################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities which will
#   be referenced later in the configuration.
#
################################################################################
Organizations:
  - &org0
    Name: org0
    SkipAsForeign: false
    ID: org0
    MSPDir: ./fabric/crypto-config/ordererOrganizations/org0.org0.com/msp
    Policies: &org0Policies
      Readers:
        Type: Signature
        Rule: "OR('org0.member')"
      Writers:
        Type: Signature
        Rule: "OR('org0.member')"
      Admins:
        Type: Signature
        Rule: "OR('org0.admin')"
      Endorsement:
        Type: Signature
        Rule: "OR('org0.member')"
    OrdererEndpoints:
      - "orderer1.org0.com:7050"

  - &org1
    Name: org1
    SkipAsForeign: false
    ID: org1
    MSPDir: ./fabric/crypto-config/peerOrganizations/org1.org1.com/msp
    Policies: &Org1Policies
      Readers:
        Type: Signature
        Rule: "OR('org1.member')"
      Writers:
        Type: Signature
        Rule: "OR('org1.member')"
      Admins:
        Type: Signature
        Rule: "OR('org1.admin')"
      Endorsement:
        Type: Signature
        Rule: "OR('org1.member')"
    AnchorPeers:
      - Host: orderer1.org0.com
        Port: 7050

  - &org2
    Name: org2
    SkipAsForeign: false
    ID: org2
    MSPDir: ./fabric/crypto-config/peerOrganizations/org2.org2.com/msp
    Policies: &Org2Policies
      Readers:
        Type: Signature
        Rule: "OR('org2.member')"
      Writers:
        Type: Signature
        Rule: "OR('org2.member')"
      Admins:
        Type: Signature
        Rule: "OR('org2.admin')"
      Endorsement:
        Type: Signature
        Rule: "OR('org2.member')"
    AnchorPeers:
      - Host: orderer1.org0.com
        Port: 7050

  - &org3
    Name: org3
    SkipAsForeign: false
    ID: org3
    MSPDir: ./fabric/crypto-config/peerOrganizations/org3.org0.com/msp
    Policies: &Org3Policies
      Readers:
        Type: Signature
        Rule: "OR('org3.member')"
      Writers:
        Type: Signature
        Rule: "OR('org3.member')"
      Admins:
        Type: Signature
        Rule: "OR('org3.admin')"
      Endorsement:
        Type: Signature
        Rule: "OR('org3.member')"
    AnchorPeers:
      - Host: orderer1.org0.com
        Port: 7050

################################################################################
#
#   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: &ChannelCapabilities
    V3_0: true

  Orderer: &OrdererCapabilities
    V2_0: true

  Application: &ApplicationCapabilities
    V2_5: true

################################################################################
#
#   APPLICATION
#
#   This section defines the values to encode into a config transaction or
#   genesis block for application-related parameters.
#
################################################################################
Application: &ApplicationDefaults
  Organizations:
  Policies: &ApplicationDefaultPolicies
    LifecycleEndorsement:
      Type: ImplicitMeta
      Rule: "MAJORITY Endorsement"
    Endorsement:
      Type: ImplicitMeta
      Rule: "MAJORITY Endorsement"
    Readers:
      Type: ImplicitMeta
      Rule: "ANY Readers"
    Writers:
      Type: ImplicitMeta
      Rule: "ANY Writers"
    Admins:
      Type: ImplicitMeta
      Rule: "MAJORITY Admins"
  Capabilities:
    <<: *ApplicationCapabilities

################################################################################
#
#   ORDERER
#
#   This section defines the values to encode into a config transaction or
#   genesis block for orderer related parameters.
#
################################################################################
Orderer: &OrdererDefaults
  OrdererType: etcdraft
  BatchTimeout: 2s
  BatchSize:
    MaxMessageCount: 500
    AbsoluteMaxBytes: 10 MB
    PreferredMaxBytes: 2 MB
  MaxChannels: 0

  EtcdRaft:
    Consenters:
      - Host: orderer1.org0
        Port: 7050
        ClientTLSCert: fabric/crypto-config/ordererOrganizations/org0.org0.com/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
        ServerTLSCert: fabric/crypto-config/ordererOrganizations/org0.org0.com/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
    Options:
      TickInterval: 500ms
      ElectionTick: 10
      HeartbeatTick: 1
      MaxInflightBlocks: 5
      SnapshotIntervalSize: 16 MB

  Organizations:

  Policies:
    Readers:
      Type: ImplicitMeta
      Rule: "ANY Readers"
    Writers:
      Type: ImplicitMeta
      Rule: "ANY Writers"
    Admins:
      Type: ImplicitMeta
      Rule: "MAJORITY Admins"
    BlockValidation:
      Type: ImplicitMeta
      Rule: "ANY Writers"

  Capabilities:
    <<: *OrdererCapabilities

################################################################################
#
#   CHANNEL
#
#   This section defines the values to encode into a config transaction or
#   genesis block for channel related parameters.
#
################################################################################
Channel: &ChannelDefaults
  Policies:
    Readers:
      Type: ImplicitMeta
      Rule: "ANY Readers"
    Writers:
      Type: ImplicitMeta
      Rule: "ANY Writers"
    Admins:
      Type: ImplicitMeta
      Rule: "MAJORITY Admins"

  Capabilities:
    <<: *ChannelCapabilities

################################################################################
#
#   PROFILES
#
#   Different configuration profiles may be encoded here to be specified as
#   parameters to the configtxgen tool. The profiles which specify consortiums
#   are to be used for generating the orderer genesis block. With the correct
#   consortium members defined in the orderer genesis block, channel creation
#   requests may be generated with only the org member names and a consortium
#   name.
#
################################################################################
Profiles:
  PublicChannel:
    <<: *ChannelDefaults
    Orderer:
      <<: *OrdererDefaults
      OrdererType: etcdraft
      Organizations:
        - <<: *org0
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - <<: *org1
        Policies:
          <<: *Org1Policies
          Admins:
            Type: Signature
            Rule: "OR('org1.member')"
        - <<: *org2
          Policies:
            <<: *Org2Policies
            Admins:
                Type: Signature
                Rule: "OR('org2.member')"
        - <<: *org3
          Policies:
            <<: *Org3Policies
            Admins:
                Type: Signature
                Rule: "OR('org3.member')"

I have inspected the mychannel.tx file and the header looks fine, at least for my non-expert eye.

What could be the issue?


Solution

  • It seems that the second command is no longer necessary in version 2.5: https://hyperledger-fabric.readthedocs.io/en/release-2.5/create_channel/create_channel_participation.html#generate-the-genesis-block

    Therefore, the first command should be updated to this:

    configtxgen -profile MyChannel -outputBlock ./fabric/crypto-config/ordererOrganizations/org0/orderer/mychannel.pb -channelID MyChannel

    Being mychannel.pb the channel genesis block.