Skip to content

Commit 82332b0

Browse files
committed
[FAB-1055] remove chaincode query interface
Part of FAB-1055. Clean up chaincode query interface and chaincodequeychaincode interface of stub. Remove query interface of system chaincode. Change-Id: I9ec7ff3c7769c9d588e24013a01faa6971d951ea Signed-off-by: jiangyaoguo <[email protected]>
1 parent 1a2bdb4 commit 82332b0

9 files changed

+14
-221
lines changed

core/chaincode/chaincode_support.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (chaincodeSupport *ChaincodeSupport) registerHandler(chaincodehandler *Hand
227227
// Duplicate, return error
228228
return newDuplicateChaincodeHandlerError(chaincodehandler)
229229
}
230-
//a placeholder, unregistered handler will be setup by query or transaction processing that comes
230+
//a placeholder, unregistered handler will be setup by transaction processing that comes
231231
//through via consensus. In this case we swap the handler and give it the notify channel
232232
if chrte2 != nil {
233233
chaincodehandler.readyNotify = chrte2.handler.readyNotify
@@ -241,7 +241,6 @@ func (chaincodeSupport *ChaincodeSupport) registerHandler(chaincodehandler *Hand
241241
//now we are ready to receive messages and send back responses
242242
chaincodehandler.txCtxs = make(map[string]*transactionContext)
243243
chaincodehandler.txidMap = make(map[string]bool)
244-
chaincodehandler.isTransaction = make(map[string]bool)
245244

246245
chaincodeLogger.Debugf("registered handler complete for chaincode %s", key)
247246

@@ -626,7 +625,7 @@ func (chaincodeSupport *ChaincodeSupport) Execute(ctxt context.Context, chaincod
626625
if !ok {
627626
chaincodeSupport.runningChaincodes.Unlock()
628627
chaincodeLogger.Debugf("cannot execute-chaincode is not running: %s", chaincode)
629-
return nil, fmt.Errorf("Cannot execute transaction or query for %s", chaincode)
628+
return nil, fmt.Errorf("Cannot execute transaction for %s", chaincode)
630629
}
631630
chaincodeSupport.runningChaincodes.Unlock()
632631

core/chaincode/exectransaction.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
pb "github.com/hyperledger/fabric/protos/peer"
2828
)
2929

30-
//Execute - execute transaction or a query
30+
//Execute - execute proposal
3131
func Execute(ctxt context.Context, chain *ChaincodeSupport, txid string, prop *pb.Proposal, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
3232
var err error
3333
var cds *pb.ChaincodeDeploymentSpec
@@ -78,7 +78,7 @@ func Execute(ctxt context.Context, chain *ChaincodeSupport, txid string, prop *p
7878
resp, err := chain.Execute(ctxt, chaincode, ccMsg, timeout, prop)
7979
if err != nil {
8080
// Rollback transaction
81-
return nil, nil, fmt.Errorf("Failed to execute transaction or query(%s)", err)
81+
return nil, nil, fmt.Errorf("Failed to execute transaction (%s)", err)
8282
} else if resp == nil {
8383
// Rollback transaction
8484
return nil, nil, fmt.Errorf("Failed to receive a response for (%s)", txid)
@@ -93,7 +93,7 @@ func Execute(ctxt context.Context, chain *ChaincodeSupport, txid string, prop *p
9393
return resp.Payload, resp.ChaincodeEvent, nil
9494
} else if resp.Type == pb.ChaincodeMessage_ERROR {
9595
// Rollback transaction
96-
return nil, resp.ChaincodeEvent, fmt.Errorf("Transaction or query returned with failure: %s", string(resp.Payload))
96+
return nil, resp.ChaincodeEvent, fmt.Errorf("Transaction returned with failure: %s", string(resp.Payload))
9797
}
9898
return resp.Payload, nil, fmt.Errorf("receive a response for (%s) but in invalid state(%d)", txid, resp.Type)
9999
}

core/chaincode/exectransaction_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
"google.golang.org/grpc/credentials"
4747
)
4848

49-
// attributes to request in the batch of tcerts while deploying, invoking or querying
49+
// attributes to request in the batch of tcerts while deploying, invoking
5050
var attributes = []string{"company", "position"}
5151

5252
func getNowMillis() int64 {
@@ -269,7 +269,7 @@ func deploy2(ctx context.Context, chaincodeDeploymentSpec *pb.ChaincodeDeploymen
269269
return b, nil
270270
}
271271

272-
// Invoke or query a chaincode.
272+
// Invoke a chaincode.
273273
func invoke(ctx context.Context, spec *pb.ChaincodeSpec) (ccevt *pb.ChaincodeEvent, uuid string, retval []byte, err error) {
274274
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
275275

core/chaincode/handler.go

+4-145
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,12 @@ type Handler struct {
7979
chaincodeSupport *ChaincodeSupport
8080
registered bool
8181
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
8383
// added prior to execute and remove when done execute
8484
txCtxs map[string]*transactionContext
8585

8686
txidMap map[string]bool
8787

88-
// Track which TXIDs are queries; Although the shim maintains this, it cannot be trusted.
89-
isTransaction map[string]bool
90-
9188
// used to do Send after making sure the state transition is complete
9289
nextState chan *nextStateInfo
9390
}
@@ -159,8 +156,8 @@ func (handler *Handler) deleteRangeQueryIterator(txContext *transactionContext,
159156
delete(txContext.rangeQueryIteratorMap, txid)
160157
}
161158

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
164161
func (handler *Handler) canCallChaincode(txid string, isQuery bool) *pb.ChaincodeMessage {
165162
var errMsg string
166163
txctx := handler.getTxContext(txid)
@@ -392,34 +389,6 @@ func (handler *Handler) deleteTXIDEntry(txid string) {
392389
}
393390
}
394391

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-
423392
func (handler *Handler) notifyDuringStartup(val bool) {
424393
//if USER_RUNS_CC readyNotify will be nil
425394
if handler.readyNotify != nil {
@@ -479,7 +448,7 @@ func (handler *Handler) notify(msg *pb.ChaincodeMessage) {
479448
}
480449
}
481450

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.
483452
func (handler *Handler) beforeCompletedEvent(e *fsm.Event, state string) {
484453
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
485454
if !ok {
@@ -872,14 +841,6 @@ func (handler *Handler) afterInvokeChaincode(e *fsm.Event, state string) {
872841
func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
873842
go func() {
874843
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-
}
883844

884845
chaincodeLogger.Debugf("[%s]state is %s", shorttxid(msg.Txid), state)
885846
// Check if this is the unique request from this chaincode txid
@@ -1001,8 +962,6 @@ func (handler *Handler) enterInitState(e *fsm.Event, state string) {
1001962
chaincodeLogger.Debugf("[%s]Entered state %s", shorttxid(ccMsg.Txid), state)
1002963
//very first time entering init state from established, send message to chaincode
1003964
if ccMsg.Type == pb.ChaincodeMessage_INIT {
1004-
// Mark isTransaction to allow put/del state and invoke other chaincodes
1005-
handler.markIsTransaction(ccMsg.Txid, true)
1006965
if err := handler.serialSend(ccMsg); err != nil {
1007966
errMsg := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: []byte(fmt.Sprintf("Error sending %s: %s", pb.ChaincodeMessage_INIT, err)), Txid: ccMsg.Txid}
1008967
handler.notify(errMsg)
@@ -1013,7 +972,6 @@ func (handler *Handler) enterInitState(e *fsm.Event, state string) {
1013972
func (handler *Handler) enterReadyState(e *fsm.Event, state string) {
1014973
// Now notify
1015974
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
1016-
handler.deleteIsTransaction(msg.Txid)
1017975
if !ok {
1018976
e.Cancel(fmt.Errorf("Received unexpected message type"))
1019977
return
@@ -1026,7 +984,6 @@ func (handler *Handler) enterEndState(e *fsm.Event, state string) {
1026984
defer handler.deregister()
1027985
// Now notify
1028986
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
1029-
handler.deleteIsTransaction(msg.Txid)
1030987
if !ok {
1031988
e.Cancel(fmt.Errorf("Received unexpected message type"))
1032989
return
@@ -1083,107 +1040,11 @@ func (handler *Handler) initOrReady(ctxt context.Context, txid string, prop *pb.
10831040
return notfy, nil
10841041
}
10851042

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-
11701043
// HandleMessage implementation of MessageHandler interface. Peer's handling of Chaincode messages.
11711044
func (handler *Handler) HandleMessage(msg *pb.ChaincodeMessage) error {
11721045
chaincodeLogger.Debugf("[%s]Handling ChaincodeMessage of type: %s in state %s", shorttxid(msg.Txid), msg.Type, handler.FSM.Current())
11731046

11741047
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-
11871048
// Other errors
11881049
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())
11891050
}
@@ -1223,9 +1084,7 @@ func (handler *Handler) sendExecuteMessage(ctxt context.Context, msg *pb.Chainco
12231084
return nil, err
12241085
}
12251086

1226-
// Mark TXID as either transaction or query
12271087
chaincodeLogger.Debugf("[%s]Inside sendExecuteMessage. Message %s", shorttxid(msg.Txid), msg.Type.String())
1228-
handler.markIsTransaction(msg.Txid, true)
12291088

12301089
//if security is disabled the context elements will just be nil
12311090
if err := handler.setChaincodeProposal(prop, msg); err != nil {

core/chaincode/lccc.go

-7
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ const (
4848
//DEPLOY deploy command
4949
DEPLOY = "deploy"
5050

51-
//chaincode query commands
52-
5351
//GETCCINFO get chaincode
5452
GETCCINFO = "getid"
5553

@@ -411,8 +409,3 @@ func (lccc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) ([]byte, er
411409

412410
return nil, InvalidFunctionErr(function)
413411
}
414-
415-
// Query is no longer implemented. Will be removed
416-
func (lccc *LifeCycleSysCC) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
417-
return nil, nil
418-
}

0 commit comments

Comments
 (0)