dourong6054 2018-09-01 15:51
浏览 51

在选择语句中转到频道-不返回

I'm new to golang channels in select statements, so I might be missing something obvious here.

I'm using the hyperledger fabric-sdk-go library [1] which uses select statements to wait for responses to executions on the blockchain.

Here is where, in my own code, I call the execution and wait for the response on a channel:

func (mgr *Manager) InvokeTest(value string) (string, error) {

    . . .{code excluded here}. . .
    fmt.Println("InvokeTest - CHECK 01")

    reg, notifier, err := mgr.client.RegisterChaincodeEvent(mgr.ChaincodeID, eventID)
    if err != nil {
        return "", err
    }
    defer mgr.client.UnregisterChaincodeEvent(reg)

    . . .{code excluded here}. . .
    fmt.Println("InvokeTest - CHECK 02")

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

    return string(response.TransactionID), nil
}

Here is the RegisterChaincodeEvent function in the library (I added the WriteString for logging:

func (cc *Client) RegisterChaincodeEvent(chainCodeID string, eventFilter string) (fab.Registration, <-chan *fab.CCEvent, error) {

    //-------------------------------
    . . .WriteString("----- chclient-RegisterChaincodeEvent - BEGIN -----") . . .
    //-------------------------------

    // Register callback for CE
    return cc.eventService.RegisterChaincodeEvent(chainCodeID, eventFilter)
}

...and here is the eventService.RegisterChaincodeEvent function (again, WriteString added for logging:

func (s *Service) RegisterChaincodeEvent(ccID, eventFilter string) (fab.Registration, <-chan *fab.CCEvent, error) {

    //-------------------------------
    . . .WriteString("----- service-RegisterChaincodeEvent - BEGIN -----") . . .
    //-------------------------------

    . . .{code excluded here}. . .

    eventch := make(chan *fab.CCEvent, s.eventConsumerBufferSize)
    regch := make(chan fab.Registration)
    errch := make(chan error)

    if err := s.Submit(dispatcher.NewRegisterChaincodeEvent(ccID, eventFilter, eventch, regch, errch)); err != nil {

        //-------------------------------
        . . .WriteString("service-RegisterChaincodeEvent - CHECK DISP ERR") . . .
        //-------------------------------

        return nil, nil, errors.WithMessage(err, "error registering for chaincode events")
    }

    select {
    case response := <-regch:

        //-------------------------------
        . . .WriteString("service-RegisterChaincodeEvent - CHECK 01") . . .
        //-------------------------------

        return response, eventch, nil
    case err := <-errch:
        return nil, nil, err
    }
}

...and here is the terminal log:

InvokeTest - CHECK 01
InvokeTest - CHECK 02
did NOT receive CC event for eventId(eventInvoke)

...and the relevant log lines from the library functions:

----- chclient-RegisterChaincodeEvent - BEGIN -----
----- service-RegisterChaincodeEvent - BEGIN -----
service-RegisterChaincodeEvent - CHECK 01

So it appears that the library is functioning properly and the RegisterChaincodeEvent functions are returning a response on the channel. Why would my own select statement not be picking up the channel response? How can I debug the select/channel blocking process to see why it is timing out?

[1] https://github.com/hyperledger/fabric-sdk-go

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。