ENDORSEMENT_POLICY_FAILURE。说明:收到无效交易

时间:2019-07-04 18:16:51

标签: hyperledger-fabric blockchain

我正在使用Hyperledger Fabric Go SDK调用链式代码事务,但是出现错误提示:

ENDORSEMENT_POLICY_FAILURE. Description: received invalid transaction

在将链码实例化为两个 Org 时,我已经设置了背书策略。

configtx.yaml

Organizations:

- &OrdererOrg
    Name: OrdererOrg
    ID: OrdererMSP
    MSPDir: crypto-config/ordererOrganizations/company.ledger.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('OrdererMSP.member')"
        Writers:
            Type: Signature
            Rule: "OR('OrdererMSP.member')"
        Admins:
            Type: Signature
            Rule: "OR('OrdererMSP.admin')"

- &Org1
    Name: Org1MSP
    ID: Org1MSP
    MSPDir: crypto-config/peerOrganizations/org1.company.ledger.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
        Writers:
            Type: Signature
            Rule: "OR('Org1MSP.admin', 'Org1MSP.peer')"
        Admins:
            Type: Signature
            Rule: "OR('Org1MSP.admin')"
        Endorsement:
            Type: Signature
            Rule: "OR('Org1MSP.peer', 'Org1MSP.member')" 
    AnchorPeers:
        - Host: peer0.org1.company.ledger.com
          Port: 7051

- &Org2
    Name: Org2MSP
    ID: Org2MSP
    MSPDir: crypto-config/peerOrganizations/org2.company.ledger.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
        Writers:
            Type: Signature
            Rule: "OR('Org2MSP.admin', 'Org2MSP.peer')"
        Admins:
            Type: Signature
            Rule: "OR('Org2MSP.admin')"
        Endorsement:
            Type: Signature
            Rule: "OR('Org2MSP.peer', 'Org2MSP.member')"    

    AnchorPeers:
        - Host: peer0.org2.company.ledger.com
          Port: 9051

Capabilities:
   Channel: &ChannelCapabilities
      V1_3: true

   Orderer: &OrdererCapabilities
      V1_1: true

   Application: &ApplicationCapabilities
      V1_3: true
      V1_2: false
      V1_1: false

Application: &ApplicationDefaults

   Organizations:

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

  Capabilities:
      <<: *ApplicationCapabilities

Orderer: &OrdererDefaults

    OrdererType: solo
       Addresses:
         - orderer.company.ledger.com:7050

       BatchTimeout: 2s

       BatchSize:

       MaxMessageCount: 10

       AbsoluteMaxBytes: 99 MB

       PreferredMaxBytes: 512 KB

   Kafka:
      Brokers:
         - 127.0.0.1:9092

 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"


Channel: &ChannelDefaults

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

  Capabilities:
    <<: *ChannelCapabilities


Profiles:

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

链码声明

ccPolicy := cauthdsl.SignedByAnyPeer([]string{"AND ('Org1MSP.peer', 'Org2MSP.peer')"})

resp, err := resMgmt.InstantiateCC(
    setup.Org.ChannelID,
    resmgmt.InstantiateCCRequest{
        Name:    chaincodeId,
        Path:    setup.Org.ChaincodeGoPath,
        Version: setup.Org.OrgChaincodeVersion,
        Args:    [][]byte{[]byte("init")},
        Policy:  ccPolicy,
    },resmgmt.WithRetry(retry.DefaultChannelOpts),resmgmt.WithTargets(setup.Org.OrgPeers[0]))

链式代码调用

response, err := channelClient.Execute(channel.Request{

        ChaincodeID: chaincodeId, 
        Fcn: fcnName, 
        Args: args, 
        TransientMap: transientDataMap,
},channel.WithRetry(retry.DefaultChannelOpts),channel.WithTargetEndpoints("grpcs://localhost:7051", "grpcs://localhost:9051"))

Chaincode实例化成功,并且我可以在两个对等Docker容器中看到链码,但是在将数据调用到链码中时,我遇到了 ENDORSEMENT_POLICY_FAILURE 错误。

我还需要制定其他政策吗?请给我建议一些解决方案,我做错了什么?。

0 个答案:

没有答案