Skip to content

Commit

Permalink
FAB-2524 - instantiate/upgrade should not specify code
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2524

Instantiate and Upgrade continue to use the ChaincodeDeploymentSpec.
They should instead use the CDS from the installed package.

We should note that a better way to do that is to not overload
ChaincodeDeploymentSpec but use it only for the install command. That is
a much bigger change involving protocol and best done in a future CR.

We could check instantiate and upgrade calls just have minimal
information in the CDS and return error. This is not done in this
CR for two reasons
   . this is a tactical fix pending the right protocol change mentioned
   . don't want to break SDKs which may be sending those spurious
     information. We will just ignore such information. They can make
     the change at their convenience

Change-Id: I9ee8e6e347e3f935626d8b113dbe512a85859f19
Signed-off-by: Srinivasan Muralidharan <muralisr@us.ibm.com>
  • Loading branch information
Srinivasan Muralidharan committed Mar 4, 2017
1 parent ebe1b4d commit 231bfd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
//build the chaincode
var cID *pb.ChaincodeID
var cMsg *pb.ChaincodeInput
var cLang pb.ChaincodeSpec_Type

var cds *pb.ChaincodeDeploymentSpec
var ci *pb.ChaincodeInvocationSpec
Expand All @@ -479,7 +478,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
if cds != nil {
cID = cds.ChaincodeSpec.ChaincodeId
cMsg = cds.ChaincodeSpec.Input
cLang = cds.ChaincodeSpec.Type
} else {
cID = ci.ChaincodeSpec.ChaincodeId
cMsg = ci.ChaincodeSpec.Input
Expand Down Expand Up @@ -536,8 +534,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
if err != nil {
return cID, cMsg, fmt.Errorf("failed to unmarshal deployment transactions for %s - %s", canName, err)
}

cLang = cds.ChaincodeSpec.Type
}

//from here on : if we launch the container and get an error, we need to stop the container
Expand All @@ -554,12 +550,18 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
if err != nil {
return cID, cMsg, err
}
cds.CodePackage = cdsfs.CodePackage
//we should use cdsfs completely. It is just a vestige of old protocol that we
//continue to use ChaincodeDeploymentSpec for anything other than Install. In
//particular, instantiate, invoke, upgrade should be using just some form of
//ChaincodeInvocationSpec.
cds = cdsfs
chaincodeLogger.Debugf("launchAndWaitForRegister fetched %d from file system", len(cds.CodePackage), err)
}
}

builder := func() (io.Reader, error) { return platforms.GenerateDockerBuild(cds) }

cLang := cds.ChaincodeSpec.Type
err = chaincodeSupport.launchAndWaitForRegister(context, cccid, cds, cLang, builder)
if err != nil {
chaincodeLogger.Errorf("launchAndWaitForRegister failed %s", err)
Expand Down
12 changes: 8 additions & 4 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func getUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string, creator
//getDeployOrUpgradeProposal gets the proposal for the chaincode deploy or upgrade
//the payload is a ChaincodeDeploymentSpec
func getDeployOrUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string, creator []byte, upgrade bool) (*pb.Proposal, error) {
//we need to save off the chaincode as we have to instantiate with nil CodePackage
var err error
if err = ccprovider.PutChaincodeIntoFS(cds); err != nil {
return nil, err
}

cds.CodePackage = nil

b, err := proto.Marshal(cds)
if err != nil {
return nil, err
Expand All @@ -166,10 +174,6 @@ func getDeployOrUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string,
return nil, err
}

if err = ccprovider.PutChaincodeIntoFS(cds); err != nil {
return nil, err
}

return prop, nil
}

Expand Down

0 comments on commit 231bfd0

Please sign in to comment.