Skip to content

Commit

Permalink
[FAB-1747] Do not stop devmode chaincode after deploy
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Jan 25, 2017
1 parent c9242fe commit 4e6359a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
7 changes: 7 additions & 0 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions peer/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 4e6359a

Please sign in to comment.