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?