Skip to content

Commit 29e0c40

Browse files
author
Srinivasan Muralidharan
committed
[FAB-3850] disable java chaincode as its WIP
Java CC has made good progress with https://jira.hyperledger.org/browse/FAB-3218. However its not quite ready yet. Its better to disable it for alpha2 and enable it when its more usable. The disable will add endorser and CLI checks to error out if accessing java chaincode. We may just prevent install/instantiate/upgrade of Java CC to make it less invasive (ie, not checking invoke as we cannot invoke what's not instantiated). Change-Id: I6109833cc9276c5d7f0679b9987e43677125778a Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent f3bb8b7 commit 29e0c40

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

core/endorser/endorser.go

+49
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,50 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
154154
return res, ccevent, err
155155
}
156156

157+
//TO BE REMOVED WHEN JAVA CC IS ENABLED
158+
//disableJavaCCInst if trying to install, instantiate or upgrade Java CC
159+
func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvocationSpec) error {
160+
//if not lscc we don't care
161+
if cid.Name != "lscc" {
162+
return nil
163+
}
164+
165+
//non-nil spec ? leave it to callers to handle error if this is an error
166+
if cis.ChaincodeSpec == nil || cis.ChaincodeSpec.Input == nil {
167+
return nil
168+
}
169+
170+
//should at least have a command arg, leave it to callers if this is an error
171+
if len(cis.ChaincodeSpec.Input.Args) < 1 {
172+
return nil
173+
}
174+
175+
var argNo int
176+
switch string(cis.ChaincodeSpec.Input.Args[0]) {
177+
case "install":
178+
argNo = 1
179+
case "deploy", "upgrade":
180+
argNo = 2
181+
default:
182+
//what else can it be ? leave it caller to handle it if error
183+
return nil
184+
}
185+
186+
//the inner dep spec will contain the type
187+
cds, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[argNo])
188+
if err != nil {
189+
return err
190+
}
191+
192+
//finally, if JAVA error out
193+
if cds.ChaincodeSpec.Type == pb.ChaincodeSpec_JAVA {
194+
return fmt.Errorf("Java chaincode is work-in-progress and disabled")
195+
}
196+
197+
//not a java install, instantiate or upgrade op
198+
return nil
199+
}
200+
157201
//simulate the proposal by calling the chaincode
158202
func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, cid *pb.ChaincodeID, txsim ledger.TxSimulator) (*ccprovider.ChaincodeData, *pb.Response, []byte, *pb.ChaincodeEvent, error) {
159203
//we do expect the payload to be a ChaincodeInvocationSpec
@@ -164,6 +208,11 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
164208
return nil, nil, nil, nil, err
165209
}
166210

211+
//disable Java install,instantiate,upgrade for now
212+
if err = e.disableJavaCCInst(cid, cis); err != nil {
213+
return nil, nil, nil, nil, err
214+
}
215+
167216
//---1. check ESCC and VSCC for the chaincode
168217
if err = e.checkEsccAndVscc(prop); err != nil {
169218
return nil, nil, nil, nil, err

core/endorser/endorser_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,25 @@ func TestDeploy(t *testing.T) {
343343
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
344344
}
345345

346+
//REMOVE WHEN JAVA CC IS ENABLED
347+
func TestJavaDeploy(t *testing.T) {
348+
chainID := util.GetTestChainID()
349+
//pretend this is a java CC (type 4)
350+
spec := &pb.ChaincodeSpec{Type: 4, ChaincodeId: &pb.ChaincodeID{Name: "javacc", Path: "../../examples/chaincode/java/chaincode_example02", Version: "0"}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}}}
351+
defer deleteChaincodeOnDisk("javacc.0")
352+
353+
cccid := ccprovider.NewCCContext(chainID, "javacc", "0", "", false, nil, nil)
354+
355+
_, _, err := deploy(endorserServer, chainID, spec, nil)
356+
if err == nil {
357+
t.Fail()
358+
t.Logf("expected java CC deploy to fail")
359+
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
360+
return
361+
}
362+
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
363+
}
364+
346365
//TestRedeploy - deploy two times, second time should fail but example02 should remain deployed
347366
func TestRedeploy(t *testing.T) {
348367
chainID := util.GetTestChainID()

peer/chaincode/common.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
8484
}
8585

8686
chaincodeLang = strings.ToUpper(chaincodeLang)
87+
if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) {
88+
return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled")
89+
}
8790
spec = &pb.ChaincodeSpec{
8891
Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value[chaincodeLang]),
8992
ChaincodeId: &pb.ChaincodeID{Path: chaincodePath, Name: chaincodeName, Version: chaincodeVersion},

0 commit comments

Comments
 (0)