From 29e0c4083f1f95d4f3513ecdfbbe7598e082238d Mon Sep 17 00:00:00 2001 From: Srinivasan Muralidharan Date: Thu, 11 May 2017 14:35:24 -0400 Subject: [PATCH] [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 --- core/endorser/endorser.go | 49 ++++++++++++++++++++++++++++++++++ core/endorser/endorser_test.go | 19 +++++++++++++ peer/chaincode/common.go | 3 +++ 3 files changed, 71 insertions(+) diff --git a/core/endorser/endorser.go b/core/endorser/endorser.go index 1f947cfdfd0..940278adfa8 100644 --- a/core/endorser/endorser.go +++ b/core/endorser/endorser.go @@ -154,6 +154,50 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s return res, ccevent, err } +//TO BE REMOVED WHEN JAVA CC IS ENABLED +//disableJavaCCInst if trying to install, instantiate or upgrade Java CC +func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvocationSpec) error { + //if not lscc we don't care + if cid.Name != "lscc" { + return nil + } + + //non-nil spec ? leave it to callers to handle error if this is an error + if cis.ChaincodeSpec == nil || cis.ChaincodeSpec.Input == nil { + return nil + } + + //should at least have a command arg, leave it to callers if this is an error + if len(cis.ChaincodeSpec.Input.Args) < 1 { + return nil + } + + var argNo int + switch string(cis.ChaincodeSpec.Input.Args[0]) { + case "install": + argNo = 1 + case "deploy", "upgrade": + argNo = 2 + default: + //what else can it be ? leave it caller to handle it if error + return nil + } + + //the inner dep spec will contain the type + cds, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[argNo]) + if err != nil { + return err + } + + //finally, if JAVA error out + if cds.ChaincodeSpec.Type == pb.ChaincodeSpec_JAVA { + return fmt.Errorf("Java chaincode is work-in-progress and disabled") + } + + //not a java install, instantiate or upgrade op + return nil +} + //simulate the proposal by calling the chaincode 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) { //we do expect the payload to be a ChaincodeInvocationSpec @@ -164,6 +208,11 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st return nil, nil, nil, nil, err } + //disable Java install,instantiate,upgrade for now + if err = e.disableJavaCCInst(cid, cis); err != nil { + return nil, nil, nil, nil, err + } + //---1. check ESCC and VSCC for the chaincode if err = e.checkEsccAndVscc(prop); err != nil { return nil, nil, nil, nil, err diff --git a/core/endorser/endorser_test.go b/core/endorser/endorser_test.go index e02980fece6..9a996267b7a 100644 --- a/core/endorser/endorser_test.go +++ b/core/endorser/endorser_test.go @@ -343,6 +343,25 @@ func TestDeploy(t *testing.T) { chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec}) } +//REMOVE WHEN JAVA CC IS ENABLED +func TestJavaDeploy(t *testing.T) { + chainID := util.GetTestChainID() + //pretend this is a java CC (type 4) + 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")}}} + defer deleteChaincodeOnDisk("javacc.0") + + cccid := ccprovider.NewCCContext(chainID, "javacc", "0", "", false, nil, nil) + + _, _, err := deploy(endorserServer, chainID, spec, nil) + if err == nil { + t.Fail() + t.Logf("expected java CC deploy to fail") + chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec}) + return + } + chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec}) +} + //TestRedeploy - deploy two times, second time should fail but example02 should remain deployed func TestRedeploy(t *testing.T) { chainID := util.GetTestChainID() diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index d93d7877e95..165b378e6d8 100644 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -84,6 +84,9 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) { } chaincodeLang = strings.ToUpper(chaincodeLang) + if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) { + return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled") + } spec = &pb.ChaincodeSpec{ Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value[chaincodeLang]), ChaincodeId: &pb.ChaincodeID{Path: chaincodePath, Name: chaincodeName, Version: chaincodeVersion},