1

我有一个基本的第一个网络,它与两个组织一起运行,并且它们都有两个对等点。事务未提交。当我调用时,链代码在容器中按预期运行并按预期返回提案。但是这些并没有反映在 stateDB 中。收到以下错误。

[fabsdk/fab] 2019/08/15 07:54:14 UTC - connection.(*EventHubConnection).Receive -> ERRO Received error from stream: [rpc error: code = Unimplemented desc = unknown service protos.Events]. Sending disconnected event.
[fabsdk/fab] 2019/08/15 07:54:14 UTC - client.(*Client).monitorConnection -> WARN Event client has disconnected. Details: rpc error: code = Unimplemented desc = unknown service protos.Events
[fabsdk/fab] 2019/08/15 07:54:14 UTC - client.(*Client).monitorConnection -> WARN Reconnect already in progress. Setting state to disconnected
[fabsdk/fab] 2019/08/15 07:54:14 UTC - eventhubclient.(*Client).registerInterests -> ERRO unable to send register interests request: connection terminated
[fabsdk/fab] 2019/08/15 07:54:14 UTC - client.(*Client).t -> WARN Error invoking afterConnect handler: connection terminated. Disconnecting...
[fabsdk/fab] 2019/08/15 07:54:14 UTC - client.(*Client).t -> WARN Received error from disconnect request: connection already closed

代码如下:

 reg, notifier, err := event.RegisterChaincodeEvent(fSetup.ChainCodeID, "saveAsset")

if err != nil {
    log.Println("Error while registering for the chaincode event")
}
defer event.Unregister(reg)

args = append(args, []byte("{payload}"))
result, errorObj := ch.Execute(channel.Request{
    ChaincodeID: fSetup.ChainCodeID,
    Fcn:         "create",
    Args:        args,
}, channel.WithRetry(retry.DefaultChannelOpts))
if errorObj != nil {
    log.Printf("error for the args %v", errorObj)
}

select {
case ccEventNotify := <-notifier:
    fmt.Printf("Received CC event: %v\n", ccEventNotify)
case <-time.After(time.Second * 60):
    log.Println("Timeout during chaincode status awaiting")


}

配置看起来像这样:

name: "byfn"
version: 1.0.0
client:
organization: in
logging:
    level: info
peer:
    timeout:
    connection: 10s
    response: 180s
    discovery:
        greylistExpiry: 10s
eventService:
    type: (deliver)
    timeout:
    connection: 15s
    registrationResponse: 15s
orderer:
    timeout:
    connection: 15s
    response: 15s
global:
    timeout:
    query: 180s
    execute: 180s
    resmgmt: 180s
    cache:
    connectionIdle: 30s
    eventServiceIdle: 2m
    channelConfig: 30m
    channelMembership: 30s
    discovery: 10s
    selection: 10m
cryptoconfig:
    path: ${GOPATH}/src/myorg-network/crypto-config
credentialStore:
    path: /tmp/myorg-service-store
    cryptoStore:
    path: /tmp/myorg-service-msp
BCCSP:
    security:
    enabled: true
    default:
        provider: "SW"
    hashAlgorithm: "SHA2"
    softVerify: true
    level: 256
tlsCerts:
    enabled: true
    systemCertPool: false
    client:
    key:
    cert:
channels:
ttchann:
    peers:
    peer0.in.myorg.io:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
    peer1.in.myorg.io:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
    peer0.se.myorg.io:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
    peer1.se.myorg.io:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
    policies:
    queryChannelConfig:
        minResponses: 1
        maxTargets: 1
        retryOpts:
        attempts: 5
        initialBackoff: 500ms
        maxBackoff: 5s
        backoffFactor: 2.0
organizations:
in:
    mspid: InMSP
    cryptoPath: peerOrganizations/in.myorg.io/users/Admin@in.myorg.io/msp
    peers:
    - peer0.in.myorg.io
    - peer1.in.myorg.io
    certificateAuthorities:
    - ca.in.myorg.io
    adminPrivateKey:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/in.myorg.io/users/Admin@in.myorg.io/msp/keystore/9a6335431b7952af6fbc3cadeb51ab92263819c951c8e23c162e7fea1c406c95_sk
    signedCert:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/in.myorg.io/users/Admin@in.myorg.io/msp/signcerts/Admin@in.myorg.io-cert.pem

se:
    mspid: SeMSP
    cryptoPath: peerOrganizations/se.myorg.io/users/Admin@se.myorg.io/msp
    peers:
    - peer0.se.myorg.io
    - peer1.se.myorg.io
    certificateAuthorities:
    - ca.se.myorg.io
    adminPrivateKey:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/se.myorg.io/users/Admin@se.myorg.io/msp/keystore/9a6335431b7952af6fbc3cadeb51ab92263819c951c8e23c162e7fea1c406c95_sk
    signedCert:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/se.myorg.io/users/Admin@se.myorg.io/msp/signcerts/Admin@se.myorg.io-cert.pem

ordererorg:
    mspID: OrdererMSP
    cryptoPath: ordererOrganizations/myorg.io/users/Admin@myorg.io/msp
orderers:
orderer.myorg.io:
    url: grpcs://orderer.myorg.io:7050
    mspid: OrdererMSP
    grpcOptions:
    ssl-target-name-override: orderer.myorg.io
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/ordererOrganizations/myorg.io/orderers/orderer.myorg.io/tls/ca.crt
peers:
peer0.in.myorg.io:
    url: grpcs://peer0.in.myorg.io:7051
    eventUrl: grpcs://peer0.in.myorg.io:7053
    grpcOptions:
    ssl-target-name-override: peer0.in.myorg.io
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/in.myorg.io/tlsca/tlsca.in.myorg.io-cert.pem
peer1.in.myorg.io:
    url: grpcs://peer1.in.myorg.io:8051
    eventUrl: grpcs://peer1.in.myorg.io:8053
    grpcOptions:
    ssl-target-name-override: peer1.in.myorg.io
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/in.myorg.io/tlsca/tlsca.in.myorg.io-cert.pem
peer0.se.myorg.io:
    url: grpcs://peer0.se.myorg.io:9051
    eventUrl: grpcs://peer0.se.myorg.io:9053
    grpcOptions:
    ssl-target-name-override: peer0.se.myorg.io
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/se.myorg.io/tlsca/tlsca.se.myorg.io-cert.pem
peer1.se.myorg.io:
    url: grpcs://peer1.se.myorg.io:10051
    eventUrl: grpcs://peer1.se.myorg.io:10053
    grpcOptions:
    ssl-target-name-override: peer1.se.myorg.io
    keep-alive-time: 0s
    keep-alive-timeout: 20s
    keep-alive-permit: false
    fail-fast: false
    allow-insecure: false
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/se.myorg.io/tlsca/tlsca.se.myorg.io-cert.pem


certificateAuthorities:
ca.in.myorg.io:
    url: http://ca.in.myorg.io:7054
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/in.myorg.io/ca/ca.in.myorg.io-cert.pem
    registrar:
        enrollId: admin
        enrollSecret: adminpw
    caName: ca.in.myorg.io
ca.se.myorg.io:
    url: http://ca.se.myorg.io:8054
    tlsCACerts:
    path: ${GOPATH}/src/myorg-network/crypto-config/peerOrganizations/se.myorg.io/ca/ca.se.myorg.io-cert.pem
    registrar:
    enrollId: admin
    enrollSecret: adminpw
    caName: ca.se.myorg.io

entityMatchers:
peer:
    - pattern: (\w*)peer0.in.myorg.io(\w*)
    urlSubstitutionExp: grpcs://localhost:7051
    eventUrlSubstitutionExp: grpcs://localhost:7053
    sslTargetOverrideUrlSubstitutionExp: peer0.in.myorg.io
    mappedHost: peer0.in.myorg.io
    - pattern: (\w*)peer1.in.myorg.io(\w*)
    urlSubstitutionExp: grpcs://localhost:8051
    eventUrlSubstitutionExp: grpcs://localhost:8053
    sslTargetOverrideUrlSubstitutionExp: peer1.in.myorg.io
    mappedHost: peer1.in.myorg.io
    - pattern: (\w*)peer0.se.myorg.io(\w*)
    urlSubstitutionExp: grpcs://localhost:7051
    eventUrlSubstitutionExp: grpcs://localhost:7053
    sslTargetOverrideUrlSubstitutionExp: peer0.se.myorg.io
    mappedHost: peer0.se.myorg.io
    - pattern: (\w*)peer1.se.myorg.io(\w*)
    urlSubstitutionExp: grpcs://localhost:8051
    eventUrlSubstitutionExp: grpcs://localhost:8053
    sslTargetOverrideUrlSubstitutionExp: peer1.se.myorg.io
    mappedHost: peer1.se.myorg.io
orderer:
    - pattern: (\w+).myorg.io.(\w+)
    urlSubstitutionExp: grpcs://localhost:7050
    sslTargetOverrideUrlSubstitutionExp: orderer.myorg.io
    mappedHost: orderer.myorg.io
certificateAuthorities:
    - pattern: (\w+).in.myorg.io(\w*)
    urlSubstitutionExp: http://localhost:7054
    sslTargetOverrideUrlSubstitutionExp: ca.in.myorg.io
    mappedHost: ca.in.myorg.io
4

1 回答 1

1

检查我的调用代码

func (setup *FabricSetup) Invoke() (string, error) {
    // Channel client is used to query and execute transactions
    clientContext := setup.sdk.ChannelContext(setup.ChannelID, fabsdk.WithUser(setup.OrgAdmin))
    client, err := channel.New(clientContext)
    setup.client = client
    if err != nil {
        log.Error("failed to create new channel client")
    }
    log.Info("Channel client created")

    // Creation of the client which will enables access to our channel events
    setup.event, err = event.New(clientContext)
    if err != nil {
        fmt.Printf("failed to create new channel client")
    }
    log.Info("Event client created")
    // Prepare arguments
    var args []string
    args = append(args, "createRate")
    args = append(args, "001")
    args = append(args, "CAR BUSINESS")
    args = append(args, "7Lakhs")

    eventID := "rate_created"

    reg, notifier, err := setup.event.RegisterChaincodeEvent(setup.ChainCodeID, eventID)
    if err != nil {
        return "", err
    }
    defer setup.event.Unregister(reg)

    // Create a request (proposal) and send it
    response, err := setup.client.Execute(
        channel.Request{
            ChaincodeID: setup.ChainCodeID,
            Fcn:         args[0],
            Args: [][]byte{[]byte(args[1]),
                []byte(args[2]),
                []byte(args[3])},
        },
    )
    if err != nil {
        return "", fmt.Errorf("failed to Invoke: %v", err)
    }

    // Wait for the result of the submission
    select {
    case ccEvent := <-notifier:
        fmt.Printf("Received CC event: %v\n", ccEvent)
    case <-time.After(time.Second * 20):
        return "", fmt.Errorf("did NOT receive CC event for eventId(%s)", eventID)
    }

    return string(response.TransactionID), nil
}
于 2019-08-15T15:04:08.393 回答