Skip to content

Commit

Permalink
FAB-2203 chaincode init should follow invoke FSM paths
Browse files Browse the repository at this point in the history
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 <muralisr@us.ibm.com>
  • Loading branch information
Srinivasan Muralidharan committed Feb 13, 2017
1 parent 398e366 commit 9a2d8fc
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions core/chaincode/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ func newChaincodeSupportHandler(chaincodeSupport *ChaincodeSupport, peerChatStre
fsm.Callbacks{
"before_" + pb.ChaincodeMessage_REGISTER.String(): func(e *fsm.Event) { v.beforeRegisterEvent(e, v.FSM.Current()) },
"before_" + pb.ChaincodeMessage_COMPLETED.String(): func(e *fsm.Event) { v.beforeCompletedEvent(e, v.FSM.Current()) },
"before_" + pb.ChaincodeMessage_INIT.String(): func(e *fsm.Event) { v.beforeInitState(e, v.FSM.Current()) },
"after_" + pb.ChaincodeMessage_GET_STATE.String(): func(e *fsm.Event) { v.afterGetState(e, v.FSM.Current()) },
"after_" + pb.ChaincodeMessage_RANGE_QUERY_STATE.String(): func(e *fsm.Event) { v.afterRangeQueryState(e, v.FSM.Current()) },
"after_" + pb.ChaincodeMessage_EXECUTE_QUERY_STATE.String(): func(e *fsm.Event) { v.afterExecuteQueryState(e, v.FSM.Current()) },
Expand Down Expand Up @@ -522,12 +521,6 @@ func (handler *Handler) beforeCompletedEvent(e *fsm.Event, state string) {
return
}

// beforeInitState is invoked before an init message is sent to the chaincode.
func (handler *Handler) beforeInitState(e *fsm.Event, state string) {
chaincodeLogger.Debugf("Before state %s.. notifying waiter that we are up", state)
handler.notifyDuringStartup(true)
}

// afterGetState handles a GET_STATE request from the chaincode.
func (handler *Handler) afterGetState(e *fsm.Event, state string) {
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
Expand Down Expand Up @@ -1333,18 +1326,8 @@ func (handler *Handler) sendExecuteMessage(ctxt context.Context, chainID string,
return nil, err
}

// Trigger FSM event if it is a transaction
if msg.Type.String() == pb.ChaincodeMessage_TRANSACTION.String() {
chaincodeLogger.Debugf("[%s]sendExecuteMsg trigger event %s", shorttxid(msg.Txid), msg.Type)
handler.triggerNextState(msg, true)
} else {
// Send the message to shim
chaincodeLogger.Debugf("[%s]sending query", shorttxid(msg.Txid))
if err = handler.serialSend(msg); err != nil {
handler.deleteTxContext(msg.Txid)
return nil, fmt.Errorf("[%s]SendMessage error sending (%s)", shorttxid(msg.Txid), err)
}
}
chaincodeLogger.Debugf("[%s]sendExecuteMsg trigger event %s", shorttxid(msg.Txid), msg.Type)
handler.triggerNextState(msg, true)

return txctx.responseNotifier, nil
}
Expand Down

0 comments on commit 9a2d8fc

Please sign in to comment.