@@ -30,9 +30,9 @@ import (
30
30
type state string
31
31
32
32
const (
33
- created state = "created" //start state
34
- established state = "established" //in: CREATED, rcv: REGISTER, send: REGISTERED
35
- ready state = "ready" //in:ESTABLISHED, rcv:COMPLETED
33
+ created state = "created" // start state
34
+ established state = "established" // in:CREATED, rcv: REGISTER, send: REGISTERED
35
+ ready state = "ready" // in:ESTABLISHED, rcv:COMPLETED
36
36
37
37
)
38
38
@@ -58,7 +58,7 @@ type handlerSupport interface {
58
58
59
59
// Handler responsible for management of Peer's side of chaincode stream
60
60
type Handler struct {
61
- //peer to shim grpc serializer. User only in serialSend
61
+ // peer to shim grpc serializer. User only in serialSend
62
62
serialLock sync.Mutex
63
63
ChatStream ccintf.ChaincodeStream
64
64
state state
@@ -70,7 +70,7 @@ type Handler struct {
70
70
71
71
sccp sysccprovider.SystemChaincodeProvider
72
72
73
- //chan to pass error in sync and nonsync mode
73
+ // chan to pass error in sync and nonsync mode
74
74
errChan chan error
75
75
76
76
// Map of tx txid to either invoke tx. Each tx will be
@@ -165,13 +165,13 @@ func shorttxid(txid string) string {
165
165
return txid [0 :8 ]
166
166
}
167
167
168
- //gets chaincode instance from the canonical name of the chaincode.
169
- //Called exactly once per chaincode when registering chaincode.
170
- //This is needed for the "one-instance-per-chain" model when
171
- //starting up the chaincode for each chain. It will still
172
- //work for the "one-instance-for-all-chains" as the version
173
- //and suffix will just be absent (also note that LSCC reserves
174
- //"/:[]${}" as special chars mainly for such namespace uses)
168
+ // gets chaincode instance from the canonical name of the chaincode.
169
+ // Called exactly once per chaincode when registering chaincode.
170
+ // This is needed for the "one-instance-per-chain" model when
171
+ // starting up the chaincode for each chain. It will still
172
+ // work for the "one-instance-for-all-chains" as the version
173
+ // and suffix will just be absent (also note that LSCC reserves
174
+ // "/:[]${}" as special chars mainly for such namespace uses)
175
175
func (h * Handler ) decomposeRegisteredName (cid * pb.ChaincodeID ) {
176
176
h .ccInstance = getChaincodeInstance (cid .Name )
177
177
}
@@ -180,7 +180,7 @@ func getChaincodeInstance(ccName string) *sysccprovider.ChaincodeInstance {
180
180
b := []byte (ccName )
181
181
ci := & sysccprovider.ChaincodeInstance {}
182
182
183
- //compute suffix (ie, chain name)
183
+ // compute suffix (ie, chain name)
184
184
i := bytes .IndexByte (b , '/' )
185
185
if i >= 0 {
186
186
if i < len (b )- 1 {
@@ -189,7 +189,7 @@ func getChaincodeInstance(ccName string) *sysccprovider.ChaincodeInstance {
189
189
b = b [:i ]
190
190
}
191
191
192
- //compute version
192
+ // compute version
193
193
i = bytes .IndexByte (b , ':' )
194
194
if i >= 0 {
195
195
if i < len (b )- 1 {
@@ -207,7 +207,7 @@ func (h *Handler) getCCRootName() string {
207
207
return h .ccInstance .ChaincodeName
208
208
}
209
209
210
- //serialSend serializes msgs so gRPC will be happy
210
+ // serialSend serializes msgs so gRPC will be happy
211
211
func (h * Handler ) serialSend (msg * pb.ChaincodeMessage ) error {
212
212
h .serialLock .Lock ()
213
213
defer h .serialLock .Unlock ()
@@ -220,11 +220,11 @@ func (h *Handler) serialSend(msg *pb.ChaincodeMessage) error {
220
220
return err
221
221
}
222
222
223
- //serialSendAsync serves the same purpose as serialSend (serialize msgs so gRPC will
224
- //be happy). In addition, it is also asynchronous so send-remoterecv--localrecv loop
225
- //can be nonblocking. Only errors need to be handled and these are handled by
226
- //communication on supplied error channel. A typical use will be a non-blocking or
227
- //nil channel
223
+ // serialSendAsync serves the same purpose as serialSend (serialize msgs so gRPC will
224
+ // be happy). In addition, it is also asynchronous so send-remoterecv--localrecv loop
225
+ // can be nonblocking. Only errors need to be handled and these are handled by
226
+ // communication on supplied error channel. A typical use will be a non-blocking or
227
+ // nil channel
228
228
func (h * Handler ) serialSendAsync (msg * pb.ChaincodeMessage , sendErr bool ) {
229
229
go func () {
230
230
if err := h .serialSend (msg ); err != nil {
@@ -235,9 +235,9 @@ func (h *Handler) serialSendAsync(msg *pb.ChaincodeMessage, sendErr bool) {
235
235
}()
236
236
}
237
237
238
- //transaction context id should be composed of chainID and txid. While
239
- //needed for CC-2-CC, it also allows users to concurrently send proposals
240
- //with the same TXID to the SAME CC on multiple channels
238
+ // transaction context id should be composed of chainID and txid. While
239
+ // needed for CC-2-CC, it also allows users to concurrently send proposals
240
+ // with the same TXID to the SAME CC on multiple channels
241
241
func (h * Handler ) getTxCtxId (chainID string , txid string ) string {
242
242
return chainID + txid
243
243
}
@@ -300,7 +300,7 @@ func (h *Handler) waitForKeepaliveTimer() <-chan time.Time {
300
300
func (h * Handler ) processStream () error {
301
301
defer h .deregister ()
302
302
303
- //holds return values from gRPC Recv below
303
+ // holds return values from gRPC Recv below
304
304
type recvMsg struct {
305
305
msg * pb.ChaincodeMessage
306
306
err error
@@ -311,11 +311,11 @@ func (h *Handler) processStream() error {
311
311
var in * pb.ChaincodeMessage
312
312
var err error
313
313
314
- //recv is used to spin Recv routine after previous received msg
315
- //has been processed
314
+ // recv is used to spin Recv routine after previous received msg
315
+ // has been processed
316
316
recv := true
317
317
318
- //catch send errors and bail now that sends aren't synchronous
318
+ // catch send errors and bail now that sends aren't synchronous
319
319
for {
320
320
in = nil
321
321
err = nil
@@ -365,8 +365,8 @@ func (h *Handler) processStream() error {
365
365
continue
366
366
}
367
367
368
- //if no error message from serialSend, KEEPALIVE happy, and don't care about error
369
- //(maybe it'll work later)
368
+ // if no error message from serialSend, KEEPALIVE happy, and don't care about error
369
+ // (maybe it'll work later)
370
370
h .serialSendAsync (& pb.ChaincodeMessage {Type : pb .ChaincodeMessage_KEEPALIVE }, false )
371
371
continue
372
372
}
@@ -396,12 +396,12 @@ func (h *Handler) deleteTXIDEntry(channelID, txid string) {
396
396
h .activeTransactions .Remove (channelID , txid )
397
397
}
398
398
399
- //sendReady sends READY to chaincode serially (just like REGISTER)
399
+ // sendReady sends READY to chaincode serially (just like REGISTER)
400
400
func (h * Handler ) sendReady () error {
401
401
chaincodeLogger .Debugf ("sending READY for chaincode %+v" , h .ChaincodeID )
402
402
ccMsg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_READY }
403
403
404
- //if error in sending tear down the h
404
+ // if error in sending tear down the h
405
405
if err := h .serialSend (ccMsg ); err != nil {
406
406
chaincodeLogger .Errorf ("error sending READY (%s) for chaincode %+v" , err , h .ChaincodeID )
407
407
return err
@@ -415,11 +415,11 @@ func (h *Handler) sendReady() error {
415
415
return nil
416
416
}
417
417
418
- //notifyDuringStartup will send ready on registration
418
+ // notifyDuringStartup will send ready on registration
419
419
func (h * Handler ) notifyDuringStartup (val bool ) {
420
420
if val {
421
- //if send failed, notify failure which will initiate
422
- //tearing down
421
+ // if send failed, notify failure which will initiate
422
+ // tearing down
423
423
if err := h .sendReady (); err != nil {
424
424
chaincodeLogger .Debugf ("sendReady failed: %s" , err )
425
425
}
@@ -444,8 +444,8 @@ func (h *Handler) handleRegister(msg *pb.ChaincodeMessage) {
444
444
return
445
445
}
446
446
447
- //get the component parts so we can use the root chaincode
448
- //name in keys
447
+ // get the component parts so we can use the root chaincode
448
+ // name in keys
449
449
h .decomposeRegisteredName (h .ChaincodeID )
450
450
451
451
chaincodeLogger .Debugf ("Got %s for chaincodeID = %s, sending back %s" , pb .ChaincodeMessage_REGISTER , chaincodeID , pb .ChaincodeMessage_REGISTERED )
@@ -459,7 +459,7 @@ func (h *Handler) handleRegister(msg *pb.ChaincodeMessage) {
459
459
460
460
chaincodeLogger .Debugf ("Changed state to established for %+v" , h .ChaincodeID )
461
461
462
- //for dev mode this will also move to ready automatically
462
+ // for dev mode this will also move to ready automatically
463
463
h .notifyDuringStartup (true )
464
464
}
465
465
@@ -487,7 +487,7 @@ func (h *Handler) isValidTxSim(channelID string, txid string, fmtStr string, arg
487
487
return txContext , nil
488
488
}
489
489
490
- //register Txid to prevent overlapping handle messages from chaincode
490
+ // register Txid to prevent overlapping handle messages from chaincode
491
491
func (h * Handler ) registerTxid (msg * pb.ChaincodeMessage ) bool {
492
492
// Check if this is the unique state request from this chaincode txid
493
493
if uniqueReq := h .createTXIDEntry (msg .ChannelId , msg .Txid ); ! uniqueReq {
@@ -498,7 +498,7 @@ func (h *Handler) registerTxid(msg *pb.ChaincodeMessage) bool {
498
498
return true
499
499
}
500
500
501
- //deregister current txid on completion
501
+ // deregister current txid on completion
502
502
func (h * Handler ) deRegisterTxid (msg , serialSendMsg * pb.ChaincodeMessage , serial bool ) {
503
503
h .deleteTXIDEntry (msg .ChannelId , msg .Txid )
504
504
chaincodeLogger .Debugf ("[%s]send %s(serial-%t)" , shorttxid (serialSendMsg .Txid ), serialSendMsg .Type , serial )
@@ -551,7 +551,7 @@ func (h *Handler) handleGetState(msg *pb.ChaincodeMessage) {
551
551
shorttxid (msg .Txid ), err , pb .ChaincodeMessage_ERROR )
552
552
serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid , ChannelId : msg .ChannelId }
553
553
} else if res == nil {
554
- //The state object being requested does not exist
554
+ // The state object being requested does not exist
555
555
chaincodeLogger .Debugf ("[%s]No state associated with key: %s. Sending %s with an empty payload" ,
556
556
shorttxid (msg .Txid ), key , pb .ChaincodeMessage_RESPONSE )
557
557
serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_RESPONSE , Payload : res , Txid : msg .Txid , ChannelId : msg .ChannelId }
@@ -643,7 +643,7 @@ func (h *Handler) handleGetStateByRange(msg *pb.ChaincodeMessage) {
643
643
644
644
const maxResultLimit = 100
645
645
646
- //getQueryResponse takes an iterator and fetch state to construct QueryResponse
646
+ // getQueryResponse takes an iterator and fetch state to construct QueryResponse
647
647
func getQueryResponse (txContext * TransactionContext , iter commonledger.ResultsIterator , iterID string ) (* pb.QueryResponse , error ) {
648
648
pendingQueryResults := txContext .pendingQueryResults [iterID ]
649
649
for {
@@ -944,8 +944,8 @@ func isCollectionSet(collection string) bool {
944
944
}
945
945
946
946
func (h * Handler ) getTxContextForMessage (channelID string , txid string , msgType string , payload []byte , fmtStr string , args ... interface {}) (* TransactionContext , * pb.ChaincodeMessage ) {
947
- //if we have a channelID, just get the txsim from isValidTxSim
948
- //if this is NOT an INVOKE_CHAINCODE, then let isValidTxSim handle retrieving the txContext
947
+ // if we have a channelID, just get the txsim from isValidTxSim
948
+ // if this is NOT an INVOKE_CHAINCODE, then let isValidTxSim handle retrieving the txContext
949
949
if channelID != "" || msgType != pb .ChaincodeMessage_INVOKE_CHAINCODE .String () {
950
950
return h .isValidTxSim (channelID , txid , fmtStr , args )
951
951
}
@@ -1109,12 +1109,12 @@ func (h *Handler) handleModState(msg *pb.ChaincodeMessage) {
1109
1109
chaincodeLogger .Debugf ("[%s] getting chaincode data for %s on channel %s" ,
1110
1110
shorttxid (msg .Txid ), calledCcIns .ChaincodeName , calledCcIns .ChainID )
1111
1111
1112
- //is the chaincode a system chaincode ?
1112
+ // is the chaincode a system chaincode ?
1113
1113
isscc := h .sccp .IsSysCC (calledCcIns .ChaincodeName )
1114
1114
1115
1115
var version string
1116
1116
if ! isscc {
1117
- //if its a user chaincode, get the details
1117
+ // if its a user chaincode, get the details
1118
1118
cd , err := h .lifecycle .GetChaincodeDefinition (ctxt , msg .Txid , txContext .signedProp , txContext .proposal , calledCcIns .ChainID , calledCcIns .ChaincodeName )
1119
1119
if err != nil {
1120
1120
errHandler ([]byte (err .Error ()), "[%s]Failed to get chaincode data (%s) for invoked chaincode. Sending %s" , shorttxid (msg .Txid ), err , pb .ChaincodeMessage_ERROR )
@@ -1129,7 +1129,7 @@ func (h *Handler) handleModState(msg *pb.ChaincodeMessage) {
1129
1129
return
1130
1130
}
1131
1131
} else {
1132
- //this is a system cc, just call it directly
1132
+ // this is a system cc, just call it directly
1133
1133
version = util .GetSysCCVersion ()
1134
1134
}
1135
1135
@@ -1155,8 +1155,8 @@ func (h *Handler) handleModState(msg *pb.ChaincodeMessage) {
1155
1155
// Execute the chaincode... this CANNOT be an init at least for now
1156
1156
response , execErr := h .handlerSupport .execute (ctxt , cccid , ccMsg )
1157
1157
1158
- //payload is marshalled and send to the calling chaincode's shim which unmarshals and
1159
- //sends it to chaincode
1158
+ // payload is marshalled and send to the calling chaincode's shim which unmarshals and
1159
+ // sends it to chaincode
1160
1160
res = nil
1161
1161
if execErr != nil {
1162
1162
err = execErr
@@ -1206,8 +1206,8 @@ func (h *Handler) Execute(ctxt context.Context, cccid *ccprovider.CCContext, msg
1206
1206
var ccresp * pb.ChaincodeMessage
1207
1207
select {
1208
1208
case ccresp = <- notfy :
1209
- //response is sent to user or calling chaincode. ChaincodeMessage_ERROR
1210
- //are typically treated as error
1209
+ // response is sent to user or calling chaincode. ChaincodeMessage_ERROR
1210
+ // are typically treated as error
1211
1211
case <- time .After (timeout ):
1212
1212
err = errors .New ("timeout expired while executing transaction" )
1213
1213
}
@@ -1225,7 +1225,7 @@ func (h *Handler) sendExecuteMessage(ctxt context.Context, chainID string, msg *
1225
1225
}
1226
1226
chaincodeLogger .Debugf ("[%s]Inside sendExecuteMessage. Message %s" , shorttxid (msg .Txid ), msg .Type )
1227
1227
1228
- //if security is disabled the context elements will just be nil
1228
+ // if security is disabled the context elements will just be nil
1229
1229
if err = h .setChaincodeProposal (signedProp , prop , msg ); err != nil {
1230
1230
return nil , err
1231
1231
}
0 commit comments