由于出现错误“无认可组合...”,因此无法通过fabric-sdk-go查询BYFN

时间:2018-11-22 12:59:04

标签: hyperledger-fabric hyperledger-fabric-sdk-go

我正在尝试使用fabric-sdk-go访问通过BYFN建立的Fabric网络。 我想尝试执行与cli命令相同的操作: 对等链代码查询-C mychannel -n mycc -c'{“ Args”:[“ query”,“ a”]}'

但仅收到错误: 无法获得认可的同行:从渠道响应中获得认可的错误:无法满足认可组合。

认可政策为:

-P "AND ('Org1MSP.peer','Org2MSP.peer')"

客户端代码如下:

configPath := "config-payment.yaml"
sdk, err := fabsdk.New(config.FromFile(configPath))
defer sdk.Close()

clientChannelContext := sdk.ChannelContext(channelID, fabsdk.WithUser("User1"), fabsdk.WithOrg(orgName))
client, err := channel.New(clientChannelContext)

args := [][]byte{[]byte("a")}
_, err = client.Query(channel.Request{ChaincodeID: ccID, Fcn: "query", Args: args},
    channel.WithRetry(retry.DefaultChannelOpts))
if err != nil {
    log.Fatalf("Failed to query: %s", err)
}

并且config-payment.yaml如下:

    version: 1.0.0
client:
organization: org1
logging:
    level: info
cryptoconfig:
    path: fabric-network/first-network/crypto-config
credentialStore:
    path: "/tmp/state-store"
    cryptoStore:
    path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp
BCCSP:
    security:
    enabled: true
    default:
    provider: "SW"
    hashAlgorithm: "SHA2"
    softVerify: true
    level: 256
tlsCerts:
    client:
    key:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/tls/client.key
    cert:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/tls/client.crt

channels:
_default:
    peers:
    peer1.org1.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
    policies:
    queryChannelConfig:
        minResponses: 1
        maxTargets: 1
        retryOpts:
        attempts: 5
        initialBackoff: 500ms
        maxBackoff: 5s
        backoffFactor: 2.0
    discovery:
        maxTargets: 2
        retryOpts:
        attempts: 4
        initialBackoff: 500ms
        maxBackoff: 5s
        backoffFactor: 2.0
    eventService:
        resolverStrategy: PreferOrg
        balancer: Random
        blockHeightLagThreshold: 5
        reconnectBlockHeightLagThreshold: 8
        peerMonitorPeriod: 6s
mychannel:
    peers:
    peer0.org1.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true

    peer1.org1.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true

    peer0.org2.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true

    peer1.org2.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true

organizations:
org1:
    mspid: Org1MSP
    cryptoPath:  peerOrganizations/org1.example.com/users/{username}@org1.example.com/msp
    users:
    Admin:
        cert:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem
    User1:
        cert:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem
    peers:
    - peer0.org1.example.com
    - peer1.org1.example.com
org2:
    mspid: Org2MSP
    cryptoPath:  peerOrganizations/org2.example.com/users/{username}@org2.example.com/msp
    users:
    Admin:
        cert:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem
    User1:
        cert:
        path: fabric-network/first-network/crypto-config/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem
    peers:
    - peer0.org2.example.com
    - peer1.org2.example.com

Orderer:
    mspID: OrdererMSP
    cryptoPath: ordererOrganizations/example.com/users/{username}@example.com/msp
    peers:
    - orderer.example.com
orderers:
orderer.example.com:
    url: localhost:7050
    grpcOptions:
    ssl-target-name-override: orderer.example.com
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: fabric-network/first-network/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem

peers:
peer0.org1.example.com:
    url: localhost:7051
    eventUrl: localhost:7053
    grpcOptions:
    ssl-target-name-override: peer0.org1.example.com
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

peer1.org1.example.com:
    url: localhost:8051
    eventUrl: localhost:8053
    grpcOptions:
    ssl-target-name-override: peer1.org1.example.com
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: fabric-network/first-network/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

peer0.org2.example.com:
    url: localhost:9051
    eventUrl: localhost:9053
    grpcOptions:
    ssl-target-name-override: peer0.org2.example.com
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: fabric-network/first-network/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem

peer1.org2.example.com:
    url: localhost:10051
    eventUrl: localhost:10053
    grpcOptions:
    ssl-target-name-override: peer1.org2.example.com
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: fabric-network/first-network/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem

entityMatchers:
peer:
    - pattern: peer0.org1.example.com:7051
    urlSubstitutionExp: localhost:7051
    eventUrlSubstitutionExp: localhost:7053
    sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
    mappedHost: peer0.org1.example.com

    - pattern: peer1.org1.example.com:7051
    urlSubstitutionExp: localhost:8051
    eventUrlSubstitutionExp: localhost:8053
    sslTargetOverrideUrlSubstitutionExp: peer1.org1.example.com
    mappedHost: peer1.org1.example.com

    - pattern: peer0.org2.example.com:7051
    urlSubstitutionExp: localhost:9051
    sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
    mappedHost: peer0.org2.example.com

    - pattern: peer1.org2.example.com:7051
    urlSubstitutionExp: localhost:10051
    sslTargetOverrideUrlSubstitutionExp: peer1.org2.example.com
    mappedHost: peer1.org2.example.com

orderer:
    - pattern: orderer.example.com:7050
    urlSubstitutionExp: localhost:7050
    sslTargetOverrideUrlSubstitutionExp: orderer.example.com
    mappedHost: orderer.example.com

1 个答案:

答案 0 :(得分:1)

调试代码后,我发现根本原因是由于“排除”过滤器引起的:

<link ...

我被连接问题阻止,因此我将URL设置为localhost而不是peer0.org1.example.com。因此,peer0.org1被排除在外,因此出现错误:从渠道响应中获得认可:无法满足认可组合。