@@ -79,15 +79,12 @@ type Handler struct {
79
79
chaincodeSupport * ChaincodeSupport
80
80
registered bool
81
81
readyNotify chan bool
82
- // Map of tx txid to either invoke or query tx. Each tx will be
82
+ // Map of tx txid to either invoke tx. Each tx will be
83
83
// added prior to execute and remove when done execute
84
84
txCtxs map [string ]* transactionContext
85
85
86
86
txidMap map [string ]bool
87
87
88
- // Track which TXIDs are queries; Although the shim maintains this, it cannot be trusted.
89
- isTransaction map [string ]bool
90
-
91
88
// used to do Send after making sure the state transition is complete
92
89
nextState chan * nextStateInfo
93
90
}
@@ -159,8 +156,8 @@ func (handler *Handler) deleteRangeQueryIterator(txContext *transactionContext,
159
156
delete (txContext .rangeQueryIteratorMap , txid )
160
157
}
161
158
162
- //THIS CAN BE REMOVED ONCE WE FULL SUPPORT (Invoke and Query ) CONFIDENTIALITY WITH CC-CALLING-CC
163
- //Only invocation are allowed, not queries
159
+ //THIS CAN BE REMOVED ONCE WE FULL SUPPORT (Invoke) CONFIDENTIALITY WITH CC-CALLING-CC
160
+ //Only invocation are allowed
164
161
func (handler * Handler ) canCallChaincode (txid string , isQuery bool ) * pb.ChaincodeMessage {
165
162
var errMsg string
166
163
txctx := handler .getTxContext (txid )
@@ -392,34 +389,6 @@ func (handler *Handler) deleteTXIDEntry(txid string) {
392
389
}
393
390
}
394
391
395
- // markIsTransaction marks a TXID as a transaction or a query; true = transaction, false = query
396
- func (handler * Handler ) markIsTransaction (txid string , isTrans bool ) bool {
397
- handler .Lock ()
398
- defer handler .Unlock ()
399
- if handler .isTransaction == nil {
400
- return false
401
- }
402
- handler .isTransaction [txid ] = isTrans
403
- return true
404
- }
405
-
406
- func (handler * Handler ) getIsTransaction (txid string ) bool {
407
- handler .Lock ()
408
- defer handler .Unlock ()
409
- if handler .isTransaction == nil {
410
- return false
411
- }
412
- return handler .isTransaction [txid ]
413
- }
414
-
415
- func (handler * Handler ) deleteIsTransaction (txid string ) {
416
- handler .Lock ()
417
- defer handler .Unlock ()
418
- if handler .isTransaction != nil {
419
- delete (handler .isTransaction , txid )
420
- }
421
- }
422
-
423
392
func (handler * Handler ) notifyDuringStartup (val bool ) {
424
393
//if USER_RUNS_CC readyNotify will be nil
425
394
if handler .readyNotify != nil {
@@ -479,7 +448,7 @@ func (handler *Handler) notify(msg *pb.ChaincodeMessage) {
479
448
}
480
449
}
481
450
482
- // beforeCompletedEvent is invoked when chaincode has completed execution of init, invoke or query .
451
+ // beforeCompletedEvent is invoked when chaincode has completed execution of init, invoke.
483
452
func (handler * Handler ) beforeCompletedEvent (e * fsm.Event , state string ) {
484
453
msg , ok := e .Args [0 ].(* pb.ChaincodeMessage )
485
454
if ! ok {
@@ -872,14 +841,6 @@ func (handler *Handler) afterInvokeChaincode(e *fsm.Event, state string) {
872
841
func (handler * Handler ) enterBusyState (e * fsm.Event , state string ) {
873
842
go func () {
874
843
msg , _ := e .Args [0 ].(* pb.ChaincodeMessage )
875
- // First check if this TXID is a transaction; error otherwise
876
- if ! handler .getIsTransaction (msg .Txid ) {
877
- payload := []byte (fmt .Sprintf ("Cannot handle %s in query context" , msg .Type .String ()))
878
- chaincodeLogger .Debugf ("[%s]Cannot handle %s in query context. Sending %s" , shorttxid (msg .Txid ), msg .Type .String (), pb .ChaincodeMessage_ERROR )
879
- errMsg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
880
- handler .triggerNextState (errMsg , true )
881
- return
882
- }
883
844
884
845
chaincodeLogger .Debugf ("[%s]state is %s" , shorttxid (msg .Txid ), state )
885
846
// Check if this is the unique request from this chaincode txid
@@ -1001,8 +962,6 @@ func (handler *Handler) enterInitState(e *fsm.Event, state string) {
1001
962
chaincodeLogger .Debugf ("[%s]Entered state %s" , shorttxid (ccMsg .Txid ), state )
1002
963
//very first time entering init state from established, send message to chaincode
1003
964
if ccMsg .Type == pb .ChaincodeMessage_INIT {
1004
- // Mark isTransaction to allow put/del state and invoke other chaincodes
1005
- handler .markIsTransaction (ccMsg .Txid , true )
1006
965
if err := handler .serialSend (ccMsg ); err != nil {
1007
966
errMsg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : []byte (fmt .Sprintf ("Error sending %s: %s" , pb .ChaincodeMessage_INIT , err )), Txid : ccMsg .Txid }
1008
967
handler .notify (errMsg )
@@ -1013,7 +972,6 @@ func (handler *Handler) enterInitState(e *fsm.Event, state string) {
1013
972
func (handler * Handler ) enterReadyState (e * fsm.Event , state string ) {
1014
973
// Now notify
1015
974
msg , ok := e .Args [0 ].(* pb.ChaincodeMessage )
1016
- handler .deleteIsTransaction (msg .Txid )
1017
975
if ! ok {
1018
976
e .Cancel (fmt .Errorf ("Received unexpected message type" ))
1019
977
return
@@ -1026,7 +984,6 @@ func (handler *Handler) enterEndState(e *fsm.Event, state string) {
1026
984
defer handler .deregister ()
1027
985
// Now notify
1028
986
msg , ok := e .Args [0 ].(* pb.ChaincodeMessage )
1029
- handler .deleteIsTransaction (msg .Txid )
1030
987
if ! ok {
1031
988
e .Cancel (fmt .Errorf ("Received unexpected message type" ))
1032
989
return
@@ -1083,107 +1040,11 @@ func (handler *Handler) initOrReady(ctxt context.Context, txid string, prop *pb.
1083
1040
return notfy , nil
1084
1041
}
1085
1042
1086
- // Handles request to query another chaincode
1087
- func (handler * Handler ) handleQueryChaincode (msg * pb.ChaincodeMessage ) {
1088
- go func () {
1089
- // Check if this is the unique request from this chaincode txid
1090
- uniqueReq := handler .createTXIDEntry (msg .Txid )
1091
- if ! uniqueReq {
1092
- // Drop this request
1093
- chaincodeLogger .Debugf ("[%s]Another request pending for this Txid. Cannot process." , shorttxid (msg .Txid ))
1094
- return
1095
- }
1096
-
1097
- var serialSendMsg * pb.ChaincodeMessage
1098
-
1099
- defer func () {
1100
- handler .deleteTXIDEntry (msg .Txid )
1101
- handler .serialSend (serialSendMsg )
1102
- }()
1103
-
1104
- //check and prohibit C-call-C for CONFIDENTIAL txs
1105
- if serialSendMsg = handler .canCallChaincode (msg .Txid , true ); serialSendMsg != nil {
1106
- return
1107
- }
1108
-
1109
- chaincodeSpec := & pb.ChaincodeSpec {}
1110
- unmarshalErr := proto .Unmarshal (msg .Payload , chaincodeSpec )
1111
- if unmarshalErr != nil {
1112
- payload := []byte (unmarshalErr .Error ())
1113
- chaincodeLogger .Debugf ("[%s]Unable to decipher payload. Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_ERROR )
1114
- serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
1115
- return
1116
- }
1117
-
1118
- // Get the chaincodeID to invoke
1119
- newChaincodeID := chaincodeSpec .ChaincodeID .Name
1120
-
1121
- // Create the invocation spec
1122
- chaincodeInvocationSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : chaincodeSpec }
1123
-
1124
- txContext := handler .getTxContext (msg .Txid )
1125
- ctxt := context .Background ()
1126
- ctxt = context .WithValue (ctxt , TXSimulatorKey , txContext .txsimulator )
1127
-
1128
- // Launch the new chaincode if not already running
1129
- _ , chaincodeInput , launchErr := handler .chaincodeSupport .Launch (ctxt , msg .Txid , txContext .proposal , chaincodeInvocationSpec )
1130
- if launchErr != nil {
1131
- payload := []byte (launchErr .Error ())
1132
- chaincodeLogger .Debugf ("[%s]Failed to launch invoked chaincode. Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_ERROR )
1133
- serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
1134
- return
1135
- }
1136
-
1137
- // TODO: Need to handle timeout correctly
1138
- timeout := time .Duration (30000 ) * time .Millisecond
1139
-
1140
- //queries are all invokes
1141
- ccMsg , _ := createTransactionMessage (msg .Txid , chaincodeInput )
1142
-
1143
- // Query the chaincode
1144
- //NOTE: when confidential C-call-C is understood, transaction should have the correct sec context for enc/dec
1145
- response , execErr := handler .chaincodeSupport .Execute (ctxt , newChaincodeID , ccMsg , timeout , txContext .proposal )
1146
-
1147
- if execErr != nil {
1148
- // Send error msg back to chaincode and trigger event
1149
- payload := []byte (execErr .Error ())
1150
- chaincodeLogger .Debugf ("[%s]Failed to handle %s. Sending %s" , shorttxid (msg .Txid ), msg .Type .String (), pb .ChaincodeMessage_ERROR )
1151
- serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
1152
- return
1153
- }
1154
-
1155
- // Send response msg back to chaincode.
1156
-
1157
- //this is need to send the payload directly to calling chaincode without
1158
- //interpreting (in particular, don't look for errors)
1159
- if respBytes , err := proto .Marshal (response ); err != nil {
1160
- chaincodeLogger .Errorf ("[%s]Error marshaling response. Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_ERROR )
1161
- payload := []byte (execErr .Error ())
1162
- serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
1163
- } else {
1164
- chaincodeLogger .Debugf ("[%s]Completed %s. Sending %s" , shorttxid (msg .Txid ), msg .Type .String (), pb .ChaincodeMessage_RESPONSE )
1165
- serialSendMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_RESPONSE , Payload : respBytes , Txid : msg .Txid }
1166
- }
1167
- }()
1168
- }
1169
-
1170
1043
// HandleMessage implementation of MessageHandler interface. Peer's handling of Chaincode messages.
1171
1044
func (handler * Handler ) HandleMessage (msg * pb.ChaincodeMessage ) error {
1172
1045
chaincodeLogger .Debugf ("[%s]Handling ChaincodeMessage of type: %s in state %s" , shorttxid (msg .Txid ), msg .Type , handler .FSM .Current ())
1173
1046
1174
1047
if handler .FSM .Cannot (msg .Type .String ()) {
1175
- // Check if this is a request from validator in query context
1176
- if msg .Type .String () == pb .ChaincodeMessage_PUT_STATE .String () || msg .Type .String () == pb .ChaincodeMessage_DEL_STATE .String () || msg .Type .String () == pb .ChaincodeMessage_INVOKE_CHAINCODE .String () {
1177
- // Check if this TXID is a transaction
1178
- if ! handler .getIsTransaction (msg .Txid ) {
1179
- payload := []byte (fmt .Sprintf ("[%s]Cannot handle %s in query context" , msg .Txid , msg .Type .String ()))
1180
- chaincodeLogger .Errorf ("[%s]Cannot handle %s in query context. Sending %s" , msg .Txid , msg .Type .String (), pb .ChaincodeMessage_ERROR )
1181
- errMsg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR , Payload : payload , Txid : msg .Txid }
1182
- handler .serialSend (errMsg )
1183
- return fmt .Errorf ("Cannot handle %s in query context" , msg .Type .String ())
1184
- }
1185
- }
1186
-
1187
1048
// Other errors
1188
1049
return fmt .Errorf ("[%s]Chaincode handler validator FSM cannot handle message (%s) with payload size (%d) while in state: %s" , msg .Txid , msg .Type .String (), len (msg .Payload ), handler .FSM .Current ())
1189
1050
}
@@ -1223,9 +1084,7 @@ func (handler *Handler) sendExecuteMessage(ctxt context.Context, msg *pb.Chainco
1223
1084
return nil , err
1224
1085
}
1225
1086
1226
- // Mark TXID as either transaction or query
1227
1087
chaincodeLogger .Debugf ("[%s]Inside sendExecuteMessage. Message %s" , shorttxid (msg .Txid ), msg .Type .String ())
1228
- handler .markIsTransaction (msg .Txid , true )
1229
1088
1230
1089
//if security is disabled the context elements will just be nil
1231
1090
if err := handler .setChaincodeProposal (prop , msg ); err != nil {
0 commit comments