From 4e6359a736ae33f45320b00f44e0229d19857612 Mon Sep 17 00:00:00 2001 From: Gregory Haskins Date: Wed, 18 Jan 2017 22:57:43 -0500 Subject: [PATCH] [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 --- core/chaincode/chaincode_support.go | 7 +++++++ core/endorser/endorser.go | 8 ++++++-- peer/chaincode/common.go | 4 +--- peer/node/start.go | 5 +---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/chaincode/chaincode_support.go b/core/chaincode/chaincode_support.go index c3f5da915c3..039f9b6c595 100644 --- a/core/chaincode/chaincode_support.go +++ b/core/chaincode/chaincode_support.go @@ -713,3 +713,10 @@ func (chaincodeSupport *ChaincodeSupport) Execute(ctxt context.Context, cccid *C return ccresp, err } + +// Returns true if the peer was configured with development-mode enabled +func IsDevMode() bool { + mode := viper.GetString("chaincode.mode") + + return mode == DevModeUserRunsChaincode +} diff --git a/core/endorser/endorser.go b/core/endorser/endorser.go index f72b9cf6f92..39616650b31 100644 --- a/core/endorser/endorser.go +++ b/core/endorser/endorser.go @@ -83,8 +83,12 @@ func (e *Endorser) deploy(ctxt context.Context, cccid *chaincode.CCContext, cds return fmt.Errorf("%s", err) } - //stop now that we are done - chaincodeSupport.Stop(ctxt, cccid, cds) + if chaincode.IsDevMode() == false { + //stop now that we are done + chaincodeSupport.Stop(ctxt, cccid, cds) + } else { + endorserLogger.Debug("devmode: skipping stop") + } return nil } diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index 2cf1b8336b9..8d080b91d87 100644 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -33,7 +33,6 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" putils "github.com/hyperledger/fabric/protos/utils" "github.com/spf13/cobra" - "github.com/spf13/viper" "golang.org/x/net/context" ) @@ -54,9 +53,8 @@ func checkSpec(spec *pb.ChaincodeSpec) error { // getChaincodeBytes get chaincode deployment spec given the chaincode spec func getChaincodeBytes(spec *pb.ChaincodeSpec) (*pb.ChaincodeDeploymentSpec, error) { - mode := viper.GetString("chaincode.mode") var codePackageBytes []byte - if mode != chaincode.DevModeUserRunsChaincode { + if chaincode.IsDevMode() == false { var err error if err = checkSpec(spec); err != nil { return nil, err diff --git a/peer/node/start.go b/peer/node/start.go index 9aefb83b8b4..db6b3f3a137 100644 --- a/peer/node/start.go +++ b/peer/node/start.go @@ -260,10 +260,7 @@ func serve(args []string) error { //which will be registered only during join phase. func registerChaincodeSupport(grpcServer *grpc.Server) { //get user mode - userRunsCC := false - if viper.GetString("chaincode.mode") == chaincode.DevModeUserRunsChaincode { - userRunsCC = true - } + userRunsCC := chaincode.IsDevMode() //get chaincode startup timeout tOut, err := strconv.Atoi(viper.GetString("chaincode.startuptimeout"))