Skip to content

Commit

Permalink
[FAB-9688] Remove dangerous unused CCID.ChainID
Browse files Browse the repository at this point in the history
The CCID struct has a ChainID field.  This field affects the output of
GetName().  There is a comment in GetName() indicating that if unset,
the chaincode must be a chainless system chaincode, however, this field
is in fact never set.  If it were, the rest of the chaincode container
logic would break, and we would spawn a container per chaincode per
channel, instead of just per chaincode.

This CR removes this unused field and the logic in GetName around it.

Change-Id: I9f666d7f2c2942372a363bc301f275c56fe55228
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Apr 24, 2018
1 parent 72ef358 commit addaee5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 43 deletions.
2 changes: 1 addition & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func invokeExample02Transaction(ctxt context.Context, cccid *ccprovider.CCContex

if destroyImage {
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
dir := container.DestroyImageReq{CCID: ccintf.CCID{ChaincodeSpec: spec, NetworkID: theChaincodeSupport.peerNetworkID, PeerID: theChaincodeSupport.peerID, ChainID: cccid.ChainID}, Force: true, NoPrune: true}
dir := container.DestroyImageReq{CCID: ccintf.CCID{ChaincodeSpec: spec, NetworkID: theChaincodeSupport.peerNetworkID, PeerID: theChaincodeSupport.peerID}, Force: true, NoPrune: true}

_, err = container.VMCProcess(ctxt, container.DOCKER, dir)
if err != nil {
Expand Down
25 changes: 2 additions & 23 deletions core/container/ccintf/ccintf.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package ccintf
Expand All @@ -21,9 +11,6 @@ package ccintf
//Currently inproccontroller uses it. dockercontroller does not.

import (
"encoding/hex"

"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
"golang.org/x/net/context"
)
Expand All @@ -50,7 +37,6 @@ type CCID struct {
ChaincodeSpec *pb.ChaincodeSpec
NetworkID string
PeerID string
ChainID string
Version string
}

Expand All @@ -65,12 +51,5 @@ func (ccid *CCID) GetName() string {
name = name + "-" + ccid.Version
}

//this better be chainless system chaincode!
if ccid.ChainID != "" {
hash := util.ComputeSHA256([]byte(ccid.ChainID))
hexstr := hex.EncodeToString(hash[:])
name = name + "-" + hexstr
}

return name
}
21 changes: 2 additions & 19 deletions core/container/ccintf/ccintf_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package ccintf

import (
"encoding/hex"
"testing"

"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
)
Expand All @@ -30,11 +18,6 @@ func TestGetName(t *testing.T) {
ccid := &CCID{ChaincodeSpec: spec, Version: "ver"}
name := ccid.GetName()
assert.Equal(t, "ccname-ver", name, "unexpected name")

ccid.ChainID = GetCCHandlerKey()
hash := hex.EncodeToString(util.ComputeSHA256([]byte(ccid.ChainID)))
name = ccid.GetName()
assert.Equal(t, "ccname-ver-"+hash, name, "unexpected name with hash")
}

func TestBadCCID(t *testing.T) {
Expand Down

0 comments on commit addaee5

Please sign in to comment.