Skip to content

Commit 231bfd0

Browse files
author
Srinivasan Muralidharan
committed
FAB-2524 - instantiate/upgrade should not specify code
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 <[email protected]>
1 parent ebe1b4d commit 231bfd0

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

core/chaincode/chaincode_support.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
467467
//build the chaincode
468468
var cID *pb.ChaincodeID
469469
var cMsg *pb.ChaincodeInput
470-
var cLang pb.ChaincodeSpec_Type
471470

472471
var cds *pb.ChaincodeDeploymentSpec
473472
var ci *pb.ChaincodeInvocationSpec
@@ -479,7 +478,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
479478
if cds != nil {
480479
cID = cds.ChaincodeSpec.ChaincodeId
481480
cMsg = cds.ChaincodeSpec.Input
482-
cLang = cds.ChaincodeSpec.Type
483481
} else {
484482
cID = ci.ChaincodeSpec.ChaincodeId
485483
cMsg = ci.ChaincodeSpec.Input
@@ -536,8 +534,6 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
536534
if err != nil {
537535
return cID, cMsg, fmt.Errorf("failed to unmarshal deployment transactions for %s - %s", canName, err)
538536
}
539-
540-
cLang = cds.ChaincodeSpec.Type
541537
}
542538

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

562562
builder := func() (io.Reader, error) { return platforms.GenerateDockerBuild(cds) }
563+
564+
cLang := cds.ChaincodeSpec.Type
563565
err = chaincodeSupport.launchAndWaitForRegister(context, cccid, cds, cLang, builder)
564566
if err != nil {
565567
chaincodeLogger.Errorf("launchAndWaitForRegister failed %s", err)

core/endorser/endorser_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func getUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string, creator
145145
//getDeployOrUpgradeProposal gets the proposal for the chaincode deploy or upgrade
146146
//the payload is a ChaincodeDeploymentSpec
147147
func getDeployOrUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string, creator []byte, upgrade bool) (*pb.Proposal, error) {
148+
//we need to save off the chaincode as we have to instantiate with nil CodePackage
149+
var err error
150+
if err = ccprovider.PutChaincodeIntoFS(cds); err != nil {
151+
return nil, err
152+
}
153+
154+
cds.CodePackage = nil
155+
148156
b, err := proto.Marshal(cds)
149157
if err != nil {
150158
return nil, err
@@ -166,10 +174,6 @@ func getDeployOrUpgradeProposal(cds *pb.ChaincodeDeploymentSpec, chainID string,
166174
return nil, err
167175
}
168176

169-
if err = ccprovider.PutChaincodeIntoFS(cds); err != nil {
170-
return nil, err
171-
}
172-
173177
return prop, nil
174178
}
175179

0 commit comments

Comments
 (0)