Skip to content

Commit 4e6359a

Browse files
committed
[FAB-1747] Do not stop devmode chaincode after deploy
The normal flow for chaincode deployment involves an implicit stop of the container as subphases of deployment. However, devmode chaincode is primarily under the control of a user, not the peer. Therefore, the current peer is broken for devmode because it tries to shutdown the container after registration. Because the chaincode was started by the user, the stop ultimately fails but not before the peer has confused its internal state by marking it as down. The primary problem is that subsequent calls into the chaincode will ultimately fail on account of the quasi running-but-not-really-running state and an inability to try to correct the problem autonomously due to the lack of control over the users process. This patch addresses all of the above by acnowledging that devmode chaincode should simply be left in a running state. Change-Id: I2e8f1f81a33019a10e3e65d1416ea4426a19e77a Signed-off-by: Greg Haskins <[email protected]>
1 parent c9242fe commit 4e6359a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

core/chaincode/chaincode_support.go

+7
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,10 @@ func (chaincodeSupport *ChaincodeSupport) Execute(ctxt context.Context, cccid *C
713713

714714
return ccresp, err
715715
}
716+
717+
// Returns true if the peer was configured with development-mode enabled
718+
func IsDevMode() bool {
719+
mode := viper.GetString("chaincode.mode")
720+
721+
return mode == DevModeUserRunsChaincode
722+
}

core/endorser/endorser.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ func (e *Endorser) deploy(ctxt context.Context, cccid *chaincode.CCContext, cds
8383
return fmt.Errorf("%s", err)
8484
}
8585

86-
//stop now that we are done
87-
chaincodeSupport.Stop(ctxt, cccid, cds)
86+
if chaincode.IsDevMode() == false {
87+
//stop now that we are done
88+
chaincodeSupport.Stop(ctxt, cccid, cds)
89+
} else {
90+
endorserLogger.Debug("devmode: skipping stop")
91+
}
8892

8993
return nil
9094
}

peer/chaincode/common.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
pb "github.com/hyperledger/fabric/protos/peer"
3434
putils "github.com/hyperledger/fabric/protos/utils"
3535
"github.com/spf13/cobra"
36-
"github.com/spf13/viper"
3736
"golang.org/x/net/context"
3837
)
3938

@@ -54,9 +53,8 @@ func checkSpec(spec *pb.ChaincodeSpec) error {
5453

5554
// getChaincodeBytes get chaincode deployment spec given the chaincode spec
5655
func getChaincodeBytes(spec *pb.ChaincodeSpec) (*pb.ChaincodeDeploymentSpec, error) {
57-
mode := viper.GetString("chaincode.mode")
5856
var codePackageBytes []byte
59-
if mode != chaincode.DevModeUserRunsChaincode {
57+
if chaincode.IsDevMode() == false {
6058
var err error
6159
if err = checkSpec(spec); err != nil {
6260
return nil, err

peer/node/start.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,7 @@ func serve(args []string) error {
260260
//which will be registered only during join phase.
261261
func registerChaincodeSupport(grpcServer *grpc.Server) {
262262
//get user mode
263-
userRunsCC := false
264-
if viper.GetString("chaincode.mode") == chaincode.DevModeUserRunsChaincode {
265-
userRunsCC = true
266-
}
263+
userRunsCC := chaincode.IsDevMode()
267264

268265
//get chaincode startup timeout
269266
tOut, err := strconv.Atoi(viper.GetString("chaincode.startuptimeout"))

0 commit comments

Comments
 (0)