Skip to content

Commit 9a2d8fc

Browse files
author
Srinivasan Muralidharan
committed
FAB-2203 chaincode init should follow invoke FSM paths
https://jira.hyperledger.org/browse/FAB-2203 Chaincode init was tied to deploy and had a different state model where invokes cannot happen while the chaincode was being initialized. With the change that separates launch from inits and invokes, init has to follow the same state as invokes. Currently init is sending message to chaincode OOB which caused a race with a subsequent invoke TX. Changing init to chaincode to follow the Invoke tx paths. Change-Id: Ic091782fd013a3a0e7781ba67449340fb90696e6 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent 398e366 commit 9a2d8fc

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

core/chaincode/handler.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ func newChaincodeSupportHandler(chaincodeSupport *ChaincodeSupport, peerChatStre
406406
fsm.Callbacks{
407407
"before_" + pb.ChaincodeMessage_REGISTER.String(): func(e *fsm.Event) { v.beforeRegisterEvent(e, v.FSM.Current()) },
408408
"before_" + pb.ChaincodeMessage_COMPLETED.String(): func(e *fsm.Event) { v.beforeCompletedEvent(e, v.FSM.Current()) },
409-
"before_" + pb.ChaincodeMessage_INIT.String(): func(e *fsm.Event) { v.beforeInitState(e, v.FSM.Current()) },
410409
"after_" + pb.ChaincodeMessage_GET_STATE.String(): func(e *fsm.Event) { v.afterGetState(e, v.FSM.Current()) },
411410
"after_" + pb.ChaincodeMessage_RANGE_QUERY_STATE.String(): func(e *fsm.Event) { v.afterRangeQueryState(e, v.FSM.Current()) },
412411
"after_" + pb.ChaincodeMessage_EXECUTE_QUERY_STATE.String(): func(e *fsm.Event) { v.afterExecuteQueryState(e, v.FSM.Current()) },
@@ -522,12 +521,6 @@ func (handler *Handler) beforeCompletedEvent(e *fsm.Event, state string) {
522521
return
523522
}
524523

525-
// beforeInitState is invoked before an init message is sent to the chaincode.
526-
func (handler *Handler) beforeInitState(e *fsm.Event, state string) {
527-
chaincodeLogger.Debugf("Before state %s.. notifying waiter that we are up", state)
528-
handler.notifyDuringStartup(true)
529-
}
530-
531524
// afterGetState handles a GET_STATE request from the chaincode.
532525
func (handler *Handler) afterGetState(e *fsm.Event, state string) {
533526
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
@@ -1333,18 +1326,8 @@ func (handler *Handler) sendExecuteMessage(ctxt context.Context, chainID string,
13331326
return nil, err
13341327
}
13351328

1336-
// Trigger FSM event if it is a transaction
1337-
if msg.Type.String() == pb.ChaincodeMessage_TRANSACTION.String() {
1338-
chaincodeLogger.Debugf("[%s]sendExecuteMsg trigger event %s", shorttxid(msg.Txid), msg.Type)
1339-
handler.triggerNextState(msg, true)
1340-
} else {
1341-
// Send the message to shim
1342-
chaincodeLogger.Debugf("[%s]sending query", shorttxid(msg.Txid))
1343-
if err = handler.serialSend(msg); err != nil {
1344-
handler.deleteTxContext(msg.Txid)
1345-
return nil, fmt.Errorf("[%s]SendMessage error sending (%s)", shorttxid(msg.Txid), err)
1346-
}
1347-
}
1329+
chaincodeLogger.Debugf("[%s]sendExecuteMsg trigger event %s", shorttxid(msg.Txid), msg.Type)
1330+
handler.triggerNextState(msg, true)
13481331

13491332
return txctx.responseNotifier, nil
13501333
}

0 commit comments

Comments
 (0)