Skip to content

Commit ad66c6f

Browse files
committed
[FAB-9721] check cd existance before col. validation
This CR rearranges a condition check. Before performing the collection validation, this CR checks whether the chaincode exist already on the ledger during deploy/upgrate. Change-Id: I6d2411e772468dbb35ef9b8d36c0e00255bdcd9b Signed-off-by: senthil <cendhu@gmail.com>
1 parent 8efecba commit ad66c6f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

core/scc/vscc/validator_onevalidsignature.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,16 @@ func (vscc *ValidatorOneValidSignature) ValidateLSCCInvocation(
491491

492492
switch lsccFunc {
493493
case lscc.DEPLOY:
494+
495+
/******************************************************************/
496+
/* security check 1 - cc not in the LCCC table of instantiated cc */
497+
/******************************************************************/
498+
if ccExistsOnLedger {
499+
return fmt.Errorf("Chaincode %s is already instantiated", cdsArgs.ChaincodeSpec.ChaincodeId.Name)
500+
}
501+
494502
/****************************************************************************/
495-
/* security check 0.a - validation of rwset (and of collections if enabled) */
503+
/* security check 2 - validation of rwset (and of collections if enabled) */
496504
/****************************************************************************/
497505
if ac.PrivateChannelData() {
498506
// do extra validation for collections
@@ -508,7 +516,7 @@ func (vscc *ValidatorOneValidSignature) ValidateLSCCInvocation(
508516
}
509517

510518
/*****************************************************/
511-
/* security check 1 - check the instantiation policy */
519+
/* security check 3 - check the instantiation policy */
512520
/*****************************************************/
513521
pol := cdRWSet.InstantiationPolicy
514522
if pol == nil {
@@ -524,13 +532,6 @@ func (vscc *ValidatorOneValidSignature) ValidateLSCCInvocation(
524532
return err
525533
}
526534

527-
/******************************************************************/
528-
/* security check 2 - cc not in the LCCC table of instantiated cc */
529-
/******************************************************************/
530-
if ccExistsOnLedger {
531-
return fmt.Errorf("Chaincode %s is already instantiated", cdsArgs.ChaincodeSpec.ChaincodeId.Name)
532-
}
533-
534535
case lscc.UPGRADE:
535536
/********************************************/
536537
/* security check 0.a - validation of rwset */
@@ -547,8 +548,15 @@ func (vscc *ValidatorOneValidSignature) ValidateLSCCInvocation(
547548
return fmt.Errorf("Upgrading non-existent chaincode %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name)
548549
}
549550

551+
/**********************************************************/
552+
/* security check 2 - existing cc's version was different */
553+
/**********************************************************/
554+
if cdLedger.Version == cdsArgs.ChaincodeSpec.ChaincodeId.Version {
555+
return fmt.Errorf("Existing version of the cc on the ledger (%s) should be different from the upgraded one", cdsArgs.ChaincodeSpec.ChaincodeId.Version)
556+
}
557+
550558
/*****************************************************/
551-
/* security check 2 - check the instantiation policy */
559+
/* security check 3 - check the instantiation policy */
552560
/*****************************************************/
553561
pol := cdLedger.InstantiationPolicy
554562
if pol == nil {
@@ -564,13 +572,6 @@ func (vscc *ValidatorOneValidSignature) ValidateLSCCInvocation(
564572
return err
565573
}
566574

567-
/**********************************************************/
568-
/* security check 3 - existing cc's version was different */
569-
/**********************************************************/
570-
if cdLedger.Version == cdsArgs.ChaincodeSpec.ChaincodeId.Version {
571-
return fmt.Errorf("Existing version of the cc on the ledger (%s) should be different from the upgraded one", cdsArgs.ChaincodeSpec.ChaincodeId.Version)
572-
}
573-
574575
/******************************************************************/
575576
/* security check 4 - check the instantiation policy in the rwset */
576577
/******************************************************************/

0 commit comments

Comments
 (0)