-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FAB-11201 shim pkg. provider to support both cc pkgs
This CR adds a new shim package provider which retrieves the code package for a given chaincode name/version and updates the peer to use it at startup. It first searches for a ChaincodeInstallPackage with the given name/version and falls back to searching for a ChaincodeDeploymentSpec. FAB-11201 #done Change-Id: I064dc2b364a1c8e1280ec1f2b3ffc21c8b3e2e96 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
- Loading branch information
Showing
11 changed files
with
534 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
core/chaincode/persistence/mock/legacy_package_provider.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
182 changes: 182 additions & 0 deletions
182
core/chaincode/persistence/mock/store_package_provider.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package persistence | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// StorePackageProvider is the interface needed to retrieve | ||
// the code package from a ChaincodeInstallPackage | ||
type StorePackageProvider interface { | ||
Load(hash []byte) (codePackage []byte, name, version string, err error) | ||
RetrieveHash(name, version string) (hash []byte, err error) | ||
} | ||
|
||
// LegacyPackageProvider is the interface needed to retrieve | ||
// the code package from a ChaincodeDeploymentSpec | ||
type LegacyPackageProvider interface { | ||
GetChaincodeCodePackage(name, version string) (codePackage []byte, err error) | ||
} | ||
|
||
// PackageProvider holds the necessary dependencies to obtain the code | ||
// package bytes for a chaincode | ||
type PackageProvider struct { | ||
Store StorePackageProvider | ||
LegacyPP LegacyPackageProvider | ||
} | ||
|
||
// GetChaincodeCodePackage gets the code package bytes for a chaincode given | ||
// the name and version. It first searches through the persisted | ||
// ChaincodeInstallPackages and then falls back to searching for | ||
// ChaincodeDeploymentSpecs | ||
func (p *PackageProvider) GetChaincodeCodePackage(name, version string) ([]byte, error) { | ||
codePackage, err := p.getCodePackageFromStore(name, version) | ||
if err == nil { | ||
return codePackage, nil | ||
} | ||
if _, ok := err.(*CodePackageNotFoundErr); !ok { | ||
// return the error if the hash cannot be retrieved or the code package | ||
// fails to load from the persistence store | ||
return nil, err | ||
} | ||
|
||
codePackage, err = p.getCodePackageFromLegacyPP(name, version) | ||
if err != nil { | ||
logger.Debug(err.Error()) | ||
err = errors.Errorf("code package not found for chaincode with name '%s', version '%s'", name, version) | ||
return nil, err | ||
} | ||
return codePackage, nil | ||
} | ||
|
||
// GetCodePackageFromStore gets the code package bytes from the package | ||
// provider's Store, which persists ChaincodeInstallPackages | ||
func (p *PackageProvider) getCodePackageFromStore(name, version string) ([]byte, error) { | ||
hash, err := p.Store.RetrieveHash(name, version) | ||
if _, ok := err.(*CodePackageNotFoundErr); ok { | ||
return nil, err | ||
} | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "error retrieving hash") | ||
} | ||
|
||
codePackage, _, _, err := p.Store.Load(hash) | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "error loading code package from ChaincodeInstallPackage") | ||
} | ||
return codePackage, nil | ||
} | ||
|
||
// GetCodePackageFromLegacyPP gets the code packages bytes from the | ||
// legacy package provider, which persists ChaincodeDeploymentSpecs | ||
func (p *PackageProvider) getCodePackageFromLegacyPP(name, version string) ([]byte, error) { | ||
codePackage, err := p.LegacyPP.GetChaincodeCodePackage(name, version) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error loading code package from ChaincodeDeploymentSpec") | ||
} | ||
return codePackage, nil | ||
} |
Oops, something went wrong.