Skip to content

Commit

Permalink
FAB-2177 remove need for "chainless" sccs
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2177

There is no need for "chainless" System Chaincodes as the new
model chaincodes are launched outside of channels and are
instantiated on each. Use "" for system chaincode operation
outside of any channel.

With this change LCCC can be invoked outside of channel.

Change-Id: I82f4f1bfb5a2b05abd082a0b8d91fc1da1f94afb
Signed-off-by: Srinivasan Muralidharan <muralisr@us.ibm.com>
  • Loading branch information
Srinivasan Muralidharan committed Feb 13, 2017
1 parent 0e5b8a2 commit ffe4c91
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 84 deletions.
12 changes: 3 additions & 9 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,10 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
chainID := hdr.ChannelHeader.ChannelId

//chainless MSPs have "" chain name
ischainless := syscc.IsChainlessSysCC(hdrExt.ChaincodeId.Name)
ischainless := false

//chainID should be empty for chainless SysCC (such as CSCC for Join proposal) and for
//nothing else
if chainID == "" && !ischainless {
err = fmt.Errorf("chainID not provided for chaincode %s", hdrExt.ChaincodeId.Name)
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
} else if chainID != "" && ischainless {
err = fmt.Errorf("chainID %s provided for a chainless syscc", hdrExt.ChaincodeId.Name)
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
if chainID == "" {
ischainless = true
}

//TODO check for uniqueness of prop.TxID with ledger
Expand Down
84 changes: 27 additions & 57 deletions core/scc/importsysccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,39 @@ import (
//see systemchaincode_test.go for an example using "sample_syscc"
var systemChaincodes = []*SystemChaincode{
{
ChainlessCC: true,
Enabled: true,
Name: "cscc",
Path: "github.com/hyperledger/fabric/core/scc/cscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &cscc.PeerConfiger{},
Enabled: true,
Name: "cscc",
Path: "github.com/hyperledger/fabric/core/scc/cscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &cscc.PeerConfiger{},
},
{
ChainlessCC: false,
Enabled: true,
Name: "lccc",
Path: "github.com/hyperledger/fabric/core/scc/lccc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &lccc.LifeCycleSysCC{},
Enabled: true,
Name: "lccc",
Path: "github.com/hyperledger/fabric/core/scc/lccc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &lccc.LifeCycleSysCC{},
},
{
ChainlessCC: false,
Enabled: true,
Name: "escc",
Path: "github.com/hyperledger/fabric/core/scc/escc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &escc.EndorserOneValidSignature{},
Enabled: true,
Name: "escc",
Path: "github.com/hyperledger/fabric/core/scc/escc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &escc.EndorserOneValidSignature{},
},
{
ChainlessCC: false,
Enabled: true,
Name: "vscc",
Path: "github.com/hyperledger/fabric/core/scc/vscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &vscc.ValidatorOneValidSignature{},
Enabled: true,
Name: "vscc",
Path: "github.com/hyperledger/fabric/core/scc/vscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &vscc.ValidatorOneValidSignature{},
},
{
ChainlessCC: true,
Enabled: true,
Name: "qscc",
Path: "github.com/hyperledger/fabric/core/chaincode/qscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &qscc.LedgerQuerier{},
Enabled: true,
Name: "qscc",
Path: "github.com/hyperledger/fabric/core/chaincode/qscc",
InitArgs: [][]byte{[]byte("")},
Chaincode: &qscc.LedgerQuerier{},
},
}

Expand All @@ -81,19 +76,7 @@ func RegisterSysCCs() {
//note the chaincode must still be deployed and launched like a user chaincode will be
func DeploySysCCs(chainID string) {
for _, sysCC := range systemChaincodes {
if !sysCC.ChainlessCC {
deploySysCC(chainID, sysCC)
}
}
}

//DeployChainlessSysCCs is the hook for deploying chainless system chaincodes
//these chaincodes cannot make any ledger calls
func DeployChainlessSysCCs() {
for _, sysCC := range systemChaincodes {
if sysCC.ChainlessCC {
deploySysCC("", sysCC)
}
deploySysCC(chainID, sysCC)
}
}

Expand All @@ -102,9 +85,7 @@ func DeployChainlessSysCCs() {
//in the same process
func DeDeploySysCCs(chainID string) {
for _, sysCC := range systemChaincodes {
if !sysCC.ChainlessCC {
DeDeploySysCC(chainID, sysCC)
}
DeDeploySysCC(chainID, sysCC)
}
}

Expand All @@ -119,17 +100,6 @@ func IsSysCC(name string) bool {
return false
}

//IsChainlessSysCC returns true if the name matches a chainless system chaincode's
//system chaincode names are system, chain wide
func IsChainlessSysCC(name string) bool {
for _, sysCC := range systemChaincodes {
if sysCC.Name == name && sysCC.ChainlessCC {
return true
}
}
return false
}

// MockRegisterSysCCs is used only for testing
// This is needed to break import cycle
func MockRegisterSysCCs(mockSysCCs []*SystemChaincode) []*SystemChaincode {
Expand Down
13 changes: 4 additions & 9 deletions core/scc/sysccapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ var sysccLogger = logging.MustGetLogger("sysccapi")
// when the fabric comes up. SystemChaincodes are installed by adding an
// entry in importsysccs.go
type SystemChaincode struct {
//Global, once only not tied to chains. Such chaincodes cannot
//save state in the ledger. CSCC is an example
ChainlessCC bool

// Enabled a convenient switch to enable/disable system chaincode without
// having to remove entry from importsysccs.go
Enabled bool
Expand Down Expand Up @@ -88,18 +84,17 @@ func deploySysCC(chainID string, syscc *SystemChaincode) error {
return nil
}

if chainID == "" && !syscc.ChainlessCC {
return fmt.Errorf("cannot deploy system chaincode %s without chain id", syscc.Name)
} else if chainID != "" && syscc.ChainlessCC {
return fmt.Errorf("cannot deploy chainless system chaincode %s with chain id %s", syscc.Name, chainID)
chainless := false
if chainID == "" {
chainless = true
}

var err error

ccprov := ccprovider.GetChaincodeProvider()

ctxt := context.Background()
if !syscc.ChainlessCC {
if !chainless {
lgr := peer.GetLedger(chainID)
if lgr == nil {
panic(fmt.Sprintf("syschain %s start up failure - unexpected nil ledger for channel %s", syscc.Name, chainID))
Expand Down
16 changes: 7 additions & 9 deletions peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ var nodeStartCmd = &cobra.Command{
},
}

//!!!!!----IMPORTANT----IMPORTANT---IMPORTANT------!!!!
//This is a place holder for multichain work. Currently
//user to create a single chain and initialize it
func initChainless() {
//deploy the chainless system chaincodes
scc.DeployChainlessSysCCs()
logger.Infof("Deployed chainless system chaincodess")
//start chaincodes
func initSysCCs() {
//deploy system chaincodes
scc.DeploySysCCs("")
logger.Infof("Deployed system chaincodess")
}

func serve(args []string) error {
Expand Down Expand Up @@ -156,8 +154,8 @@ func serve(args []string) error {
service.InitGossipService(serializedIdentity, peerEndpoint.Address, grpcServer, bootstrap...)
defer service.GetGossipService().Stop()

//initialize the env for chainless startup
initChainless()
//initialize system chaincodes
initSysCCs()

// Begin startup of default chain
if peerDefaultChain {
Expand Down

0 comments on commit ffe4c91

Please sign in to comment.