Skip to content

Commit

Permalink
Merge "[FAB-3171] Rename the lifecycle system chaincode"
Browse files Browse the repository at this point in the history
  • Loading branch information
binhn authored and Gerrit Code Review committed Apr 18, 2017
2 parents fb9c15e + f477ccc commit 599a7fa
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 195 deletions.
2 changes: 1 addition & 1 deletion bddtests/chaincode.go
Expand Up @@ -42,7 +42,7 @@ func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymen
return nil, fmt.Errorf("Error creating proposal from ChaincodeDeploymentSpec: %s", err)
}
lcChaincodeSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: "lccc"},
ChaincodeId: &pb.ChaincodeID{Name: "lscc"},
Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), ccDeploymentSpecBytes}}}
lcChaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: lcChaincodeSpec}

Expand Down
4 changes: 2 additions & 2 deletions bddtests/steps/endorser_util.py
Expand Up @@ -124,12 +124,12 @@ def signProposal(proposal, entity, signersCert):


def createDeploymentChaincodeSpecForBDD(ccDeploymentSpec, chainID):
lc_chaincode_spec = getChaincodeSpec(ccType="GOLANG", path="", name="lccc",
lc_chaincode_spec = getChaincodeSpec(ccType="GOLANG", path="", name="lscc",
args=['deploy', chainID, ccDeploymentSpec.SerializeToString()])
return lc_chaincode_spec

def createInstallChaincodeSpecForBDD(ccDeploymentSpec, chainID):
lc_chaincode_spec = getChaincodeSpec(ccType="GOLANG", path="", name="lccc",
lc_chaincode_spec = getChaincodeSpec(ccType="GOLANG", path="", name="lscc",
args=['install', ccDeploymentSpec.SerializeToString()])
return lc_chaincode_spec

Expand Down
16 changes: 8 additions & 8 deletions core/chaincode/ccproviderimpl.go
Expand Up @@ -72,22 +72,22 @@ func (c *ccProviderImpl) GetCCContext(cid, name, version, txid string, syscc boo
return &ccProviderContextImpl{ctx: ctx}
}

// GetCCValidationInfoFromLCCC returns the VSCC and the policy listed in LCCC for the supplied chaincode
func (c *ccProviderImpl) GetCCValidationInfoFromLCCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) (string, []byte, error) {
// LCCC does not have any notion about its own
// GetCCValidationInfoFromLSCC returns the VSCC and the policy listed in LSCC for the supplied chaincode
func (c *ccProviderImpl) GetCCValidationInfoFromLSCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) (string, []byte, error) {
// LSCC does not have any notion about its own
// endorsing policy - we should never call this
// function with lccc as the chaincodeID
if chaincodeID == "lccc" {
panic("GetCCValidationInfoFromLCCC invoke for LCCC")
// function with lscc as the chaincodeID
if chaincodeID == "lscc" {
panic("GetCCValidationInfoFromLSCC invoke for LSCC")
}

data, err := GetChaincodeDataFromLCCC(ctxt, txid, signedProp, prop, chainID, chaincodeID)
data, err := GetChaincodeDataFromLSCC(ctxt, txid, signedProp, prop, chainID, chaincodeID)
if err != nil {
return "", nil, err
}

if data == nil || data.Vscc == "" || data.Policy == nil {
return "", nil, fmt.Errorf("Incorrect validation info in LCCC")
return "", nil, fmt.Errorf("Incorrect validation info in LSCC")
}

return data.Vscc, data.Policy, nil
Expand Down
12 changes: 6 additions & 6 deletions core/chaincode/chaincode_support.go
Expand Up @@ -537,10 +537,10 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
var depPayload []byte

//hopefully we are restarting from existing image and the deployed transaction exists
//this will also validate the ID from the LCCC
depPayload, err = GetCDSFromLCCC(context, cccid.TxID, cccid.SignedProposal, cccid.Proposal, cccid.ChainID, cID.Name)
//this will also validate the ID from the LSCC
depPayload, err = GetCDSFromLSCC(context, cccid.TxID, cccid.SignedProposal, cccid.Proposal, cccid.ChainID, cID.Name)
if err != nil {
return cID, cMsg, fmt.Errorf("Could not get deployment transaction from LCCC for %s - %s", canName, err)
return cID, cMsg, fmt.Errorf("Could not get deployment transaction from LSCC for %s - %s", canName, err)
}
if depPayload == nil {
return cID, cMsg, fmt.Errorf("failed to get deployment payload %s - %s", canName, err)
Expand All @@ -559,15 +559,15 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid

//launch container if it is a System container or not in dev mode
if (!chaincodeSupport.userRunsCC || cds.ExecEnv == pb.ChaincodeDeploymentSpec_SYSTEM) && (chrte == nil || chrte.handler == nil) {
//NOTE-We need to streamline code a bit so the data from LCCC gets passed to this thus
//NOTE-We need to streamline code a bit so the data from LSCC gets passed to this thus
//avoiding the need to go to the FS. In particular, we should use cdsfs completely. It is
//just a vestige of old protocol that we continue to use ChaincodeDeploymentSpec for
//anything other than Install. In particular, instantiate, invoke, upgrade should be using
//just some form of ChaincodeInvocationSpec.
//
//But for now, if we are invoking we have gone through the LCCC path above. If instantiating
//But for now, if we are invoking we have gone through the LSCC path above. If instantiating
//or upgrading currently we send a CDS with nil CodePackage. In this case the codepath
//in the endorser has gone through LCCC validation. Just get the code from the FS.
//in the endorser has gone through LSCC validation. Just get the code from the FS.
if cds.CodePackage == nil {
//no code bytes for these situations
if !(chaincodeSupport.userRunsCC || cds.ExecEnv == pb.ChaincodeDeploymentSpec_SYSTEM) {
Expand Down
16 changes: 8 additions & 8 deletions core/chaincode/chaincodeexec.go
Expand Up @@ -38,25 +38,25 @@ func createCIS(ccname string, args [][]byte) (*pb.ChaincodeInvocationSpec, error
return spec, nil
}

// GetCDSFromLCCC gets chaincode deployment spec from LCCC
func GetCDSFromLCCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) ([]byte, error) {
// GetCDSFromLSCC gets chaincode deployment spec from LSCC
func GetCDSFromLSCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) ([]byte, error) {
version := util.GetSysCCVersion()
cccid := ccprovider.NewCCContext(chainID, "lccc", version, txid, true, signedProp, prop)
cccid := ccprovider.NewCCContext(chainID, "lscc", version, txid, true, signedProp, prop)
res, _, err := ExecuteChaincode(ctxt, cccid, [][]byte{[]byte("getdepspec"), []byte(chainID), []byte(chaincodeID)})
if err != nil {
return nil, fmt.Errorf("Execute getdepspec(%s, %s) of LCCC error: %s", chainID, chaincodeID, err)
return nil, fmt.Errorf("Execute getdepspec(%s, %s) of LSCC error: %s", chainID, chaincodeID, err)
}
if res.Status != shim.OK {
return nil, fmt.Errorf("Get ChaincodeDeploymentSpec for %s/%s from LCCC error: %s", chaincodeID, chainID, res.Message)
return nil, fmt.Errorf("Get ChaincodeDeploymentSpec for %s/%s from LSCC error: %s", chaincodeID, chainID, res.Message)
}

return res.Payload, nil
}

// GetChaincodeDataFromLCCC gets chaincode data from LCCC given name
func GetChaincodeDataFromLCCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) (*ccprovider.ChaincodeData, error) {
// GetChaincodeDataFromLSCC gets chaincode data from LSCC given name
func GetChaincodeDataFromLSCC(ctxt context.Context, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chainID string, chaincodeID string) (*ccprovider.ChaincodeData, error) {
version := util.GetSysCCVersion()
cccid := ccprovider.NewCCContext(chainID, "lccc", version, txid, true, signedProp, prop)
cccid := ccprovider.NewCCContext(chainID, "lscc", version, txid, true, signedProp, prop)
res, _, err := ExecuteChaincode(ctxt, cccid, [][]byte{[]byte("getccdata"), []byte(chainID), []byte(chaincodeID)})
if err == nil {
if res.Status != shim.OK {
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/chaincodetest.yaml
Expand Up @@ -403,7 +403,7 @@ chaincode:
# whitelist, add "myscc: enable" to the list
system:
cscc: enable
lccc: enable
lscc: enable
escc: enable
vscc: enable

Expand Down
28 changes: 14 additions & 14 deletions core/chaincode/exectransaction_test.go
Expand Up @@ -247,19 +247,19 @@ func getDeploymentSpec(_ context.Context, spec *pb.ChaincodeSpec) (*pb.Chaincode
return cdDeploymentSpec, nil
}

//getDeployLCCCSpec gets the spec for the chaincode deployment to be sent to LCCC
func getDeployLCCCSpec(chainID string, cds *pb.ChaincodeDeploymentSpec) (*pb.ChaincodeInvocationSpec, error) {
//getDeployLSCCSpec gets the spec for the chaincode deployment to be sent to LSCC
func getDeployLSCCSpec(chainID string, cds *pb.ChaincodeDeploymentSpec) (*pb.ChaincodeInvocationSpec, error) {
b, err := proto.Marshal(cds)
if err != nil {
return nil, err
}

sysCCVers := util.GetSysCCVersion()

//wrap the deployment in an invocation spec to lccc...
lcccSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "lccc", Version: sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte(chainID), b}}}}
//wrap the deployment in an invocation spec to lscc...
lsccSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "lscc", Version: sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte(chainID), b}}}}

return lcccSpec, nil
return lsccSpec, nil
}

// Deploy a chaincode - i.e., build and initialize.
Expand All @@ -274,9 +274,9 @@ func deploy(ctx context.Context, cccid *ccprovider.CCContext, spec *pb.Chaincode
}

func deploy2(ctx context.Context, cccid *ccprovider.CCContext, chaincodeDeploymentSpec *pb.ChaincodeDeploymentSpec, blockNumber uint64) (b []byte, err error) {
cis, err := getDeployLCCCSpec(cccid.ChainID, chaincodeDeploymentSpec)
cis, err := getDeployLSCCSpec(cccid.ChainID, chaincodeDeploymentSpec)
if err != nil {
return nil, fmt.Errorf("Error creating lccc spec : %s\n", err)
return nil, fmt.Errorf("Error creating lscc spec : %s\n", err)
}

ctx, txsim, err := startTxSimulation(ctx, cccid.ChainID)
Expand All @@ -303,10 +303,10 @@ func deploy2(ctx context.Context, cccid *ccprovider.CCContext, chaincodeDeployme
ccprovider.PutChaincodeIntoFS(chaincodeDeploymentSpec)

sysCCVers := util.GetSysCCVersion()
lcccid := ccprovider.NewCCContext(cccid.ChainID, cis.ChaincodeSpec.ChaincodeId.Name, sysCCVers, uuid, true, nil, nil)
lsccid := ccprovider.NewCCContext(cccid.ChainID, cis.ChaincodeSpec.ChaincodeId.Name, sysCCVers, uuid, true, nil, nil)

//write to lccc
if _, _, err = ExecuteWithErrorFilter(ctx, lcccid, cis); err != nil {
//write to lscc
if _, _, err = ExecuteWithErrorFilter(ctx, lsccid, cis); err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s", err)
}

Expand Down Expand Up @@ -1473,7 +1473,7 @@ func TestChaincodeQueryChaincodeUsingInvoke(t *testing.T) {
}

// Test the execution of a chaincode that invokes system chaincode
// uses the "pthru" chaincode to query "lccc" for the "pthru" chaincode
// uses the "pthru" chaincode to query "lscc" for the "pthru" chaincode
func TestChaincodeInvokesSystemChaincode(t *testing.T) {
chainID := util.GetTestChainID()

Expand Down Expand Up @@ -1512,9 +1512,9 @@ func TestChaincodeInvokesSystemChaincode(t *testing.T) {

time.Sleep(time.Second)

//send an invoke to pass thru to query "lccc" system chaincode on chainID to get
//send an invoke to pass thru to query "lscc" system chaincode on chainID to get
//information about "pthru"
args = util.ToChaincodeArgs("lccc/"+chainID, "getid", chainID, "pthru")
args = util.ToChaincodeArgs("lscc/"+chainID, "getid", chainID, "pthru")

spec = &pb.ChaincodeSpec{Type: 1, ChaincodeId: cID, Input: &pb.ChaincodeInput{Args: args}}
// Invoke chaincode
Expand All @@ -1529,7 +1529,7 @@ func TestChaincodeInvokesSystemChaincode(t *testing.T) {

if string(retval) != "pthru" {
t.Fail()
t.Logf("Expected to get back \"pthru\" from lccc but got back %s", string(retval))
t.Logf("Expected to get back \"pthru\" from lscc but got back %s", string(retval))
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
Expand Down
12 changes: 6 additions & 6 deletions core/chaincode/handler.go
Expand Up @@ -121,7 +121,7 @@ func shorttxid(txid string) string {
//This is needed for the "one-instance-per-chain" model when
//starting up the chaincode for each chain. It will still
//work for the "one-instance-for-all-chains" as the version
//and suffix will just be absent (also note that LCCC reserves
//and suffix will just be absent (also note that LSCC reserves
//"/:[]${}" as special chars mainly for such namespace uses)
func (handler *Handler) decomposeRegisteredName(cid *pb.ChaincodeID) {
handler.ccCompParts = chaincodeIDParts(cid.Name)
Expand Down Expand Up @@ -1300,20 +1300,20 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
ctxt = context.WithValue(ctxt, HistoryQueryExecutorKey, historyQueryExecutor)

if chaincodeLogger.IsEnabledFor(logging.DEBUG) {
chaincodeLogger.Debugf("[%s] calling lccc to get chaincode data for %s on channel %s",
chaincodeLogger.Debugf("[%s] calling lscc to get chaincode data for %s on channel %s",
shorttxid(msg.Txid), calledCcParts.name, calledCcParts.suffix)
}

//Call LCCC to get the called chaincode artifacts
//Call LSCC to get the called chaincode artifacts

//is the chaincode a system chaincode ?
isscc := sysccprovider.GetSystemChaincodeProvider().IsSysCC(calledCcParts.name)

var cd *ccprovider.ChaincodeData
if !isscc {
//if its a user chaincode, get the details from LCCC
//Call LCCC to get the called chaincode artifacts
cd, err = GetChaincodeDataFromLCCC(ctxt, msg.Txid, txContext.signedProp, txContext.proposal, calledCcParts.suffix, calledCcParts.name)
//if its a user chaincode, get the details from LSCC
//Call LSCC to get the called chaincode artifacts
cd, err = GetChaincodeDataFromLSCC(ctxt, msg.Txid, txContext.signedProp, txContext.proposal, calledCcParts.suffix, calledCcParts.name)
if err != nil {
payload := []byte(err.Error())
chaincodeLogger.Debugf("[%s]Failed to get chaincoed data (%s) for invoked chaincode. Sending %s",
Expand Down
28 changes: 14 additions & 14 deletions core/chaincode/upgrade_test.go
Expand Up @@ -29,17 +29,17 @@ import (
"golang.org/x/net/context"
)

//getUpgradeLCCCSpec gets the spec for the chaincode upgrade to be sent to LCCC
func getUpgradeLCCCSpec(chainID string, cds *pb.ChaincodeDeploymentSpec) (*pb.ChaincodeInvocationSpec, error) {
//getUpgradeLSCCSpec gets the spec for the chaincode upgrade to be sent to LSCC
func getUpgradeLSCCSpec(chainID string, cds *pb.ChaincodeDeploymentSpec) (*pb.ChaincodeInvocationSpec, error) {
b, err := proto.Marshal(cds)
if err != nil {
return nil, err
}

//wrap the deployment in an invocation spec to lccc...
lcccSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "lccc"}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("upgrade"), []byte(chainID), b}}}}
//wrap the deployment in an invocation spec to lscc...
lsccSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "lscc"}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("upgrade"), []byte(chainID), b}}}}

return lcccSpec, nil
return lsccSpec, nil
}

// upgrade a chaincode - i.e., build and initialize.
Expand All @@ -55,9 +55,9 @@ func upgrade(ctx context.Context, cccid *ccprovider.CCContext, spec *pb.Chaincod

func upgrade2(ctx context.Context, cccid *ccprovider.CCContext,
chaincodeDeploymentSpec *pb.ChaincodeDeploymentSpec, blockNumber uint64) (newcccid *ccprovider.CCContext, err error) {
cis, err := getUpgradeLCCCSpec(cccid.ChainID, chaincodeDeploymentSpec)
cis, err := getUpgradeLSCCSpec(cccid.ChainID, chaincodeDeploymentSpec)
if err != nil {
return nil, fmt.Errorf("Error creating lccc spec : %s\n", err)
return nil, fmt.Errorf("Error creating lscc spec : %s\n", err)
}

ctx, txsim, err := startTxSimulation(ctx, cccid.ChainID)
Expand All @@ -84,16 +84,16 @@ func upgrade2(ctx context.Context, cccid *ccprovider.CCContext,
ccprovider.PutChaincodeIntoFS(chaincodeDeploymentSpec)

sysCCVers := util.GetSysCCVersion()
lcccid := ccprovider.NewCCContext(cccid.ChainID, cis.ChaincodeSpec.ChaincodeId.Name, sysCCVers, uuid, true, nil, nil)
lsccid := ccprovider.NewCCContext(cccid.ChainID, cis.ChaincodeSpec.ChaincodeId.Name, sysCCVers, uuid, true, nil, nil)

var cdbytes []byte
//write to lccc
if cdbytes, _, err = ExecuteWithErrorFilter(ctx, lcccid, cis); err != nil {
return nil, fmt.Errorf("Error executing LCCC for upgrade: %s", err)
//write to lscc
if cdbytes, _, err = ExecuteWithErrorFilter(ctx, lsccid, cis); err != nil {
return nil, fmt.Errorf("Error executing LSCC for upgrade: %s", err)
}

if cdbytes == nil {
return nil, fmt.Errorf("Expected ChaincodeData back from LCCC but got nil")
return nil, fmt.Errorf("Expected ChaincodeData back from LSCC but got nil")
}

cd := &ccprovider.ChaincodeData{}
Expand All @@ -103,7 +103,7 @@ func upgrade2(ctx context.Context, cccid *ccprovider.CCContext,

newVersion := string(cd.Version)
if newVersion == cccid.Version {
return nil, fmt.Errorf("Expected new version from LCCC but got same %s(%s)", newVersion, cccid.Version)
return nil, fmt.Errorf("Expected new version from LSCC but got same %s(%s)", newVersion, cccid.Version)
}

newcccid = ccprovider.NewCCContext(cccid.ChainID, chaincodeDeploymentSpec.ChaincodeSpec.ChaincodeId.Name, newVersion, uuid, false, nil, nil)
Expand All @@ -120,7 +120,7 @@ func upgrade2(ctx context.Context, cccid *ccprovider.CCContext,
// upgrade to exampl02
// show the upgrade worked using the same query successfully
//This test a variety of things in addition to basic upgrade
// uses next version from lccc
// uses next version from lscc
// re-initializtion of the same chaincode "mycc"
// upgrade when "mycc" is up and running (test version based namespace)
func TestUpgradeCC(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions core/committer/txvalidator/validator.go
Expand Up @@ -226,21 +226,21 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
return err
}

// LCCC should not undergo standard VSCC type of
// LSCC should not undergo standard VSCC type of
// validation. It should instead go through system
// policy validation to determine whether the issuer
// is entitled to deploy a chaincode on our chain
// VSCCValidateTx should
if hdrExt.ChaincodeId.Name == "lccc" {
if hdrExt.ChaincodeId.Name == "lscc" {
// TODO: until FAB-1934 is in, we need to stop here
logger.Debugf("Invocation of LCCC detected, no further VSCC validation necessary")
logger.Debugf("Invocation of LSCC detected, no further VSCC validation necessary")
return nil
}

// obtain name of the VSCC and the policy from LCCC
vscc, policy, err := v.ccprovider.GetCCValidationInfoFromLCCC(ctxt, txid, nil, nil, chainID, hdrExt.ChaincodeId.Name)
// obtain name of the VSCC and the policy from LSCC
vscc, policy, err := v.ccprovider.GetCCValidationInfoFromLSCC(ctxt, txid, nil, nil, chainID, hdrExt.ChaincodeId.Name)
if err != nil {
logger.Errorf("Unable to get chaincode data from LCCC for txid %s, due to %s", txid, err)
logger.Errorf("Unable to get chaincode data from LSCC for txid %s, due to %s", txid, err)
return err
}

Expand Down

0 comments on commit 599a7fa

Please sign in to comment.