Commit 9112ebfb authored by Jason Yellick's avatar Jason Yellick
Browse files

FAB-10825 Make platform latent dependency explicit



Many of the assorted 'utils' functions actually reach into the
core/chaincode/platforms package to determine whether packages are
valid.  This historically has all been done in a source-coupled way,
pulling peer details into places it does not belong.  Although these
'util' functions should be refactored and removed, for the time being,
we can at least make the dependency on the platforms package explicit,
but requiring that an instance be passed into these util functions.

This has quite the ripple throughout the code, but the CR itself should
be trivial to review.

Change-Id: I0cc36e2f307474ddba7f6d20028a46f3aa94faf5
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent 9c774de8
......@@ -12,6 +12,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/common/sysccprovider"
"github.com/hyperledger/fabric/core/container/ccintf"
......@@ -55,6 +56,7 @@ func NewChaincodeSupport(
aclProvider ACLProvider,
processor Processor,
sccp sysccprovider.SystemChaincodeProvider,
platformRegistry *platforms.Registry,
) *ChaincodeSupport {
cs := &ChaincodeSupport{
UserRunsCC: userRunsCC,
......@@ -71,10 +73,11 @@ func NewChaincodeSupport(
}
cs.Runtime = &ContainerRuntime{
CertGenerator: certGenerator,
Processor: processor,
CACert: caCert,
PeerAddress: peerAddress,
CertGenerator: certGenerator,
Processor: processor,
CACert: caCert,
PeerAddress: peerAddress,
PlatformRegistry: platformRegistry,
CommonEnv: []string{
"CORE_CHAINCODE_LOGGING_LEVEL=" + config.LogLevel,
"CORE_CHAINCODE_LOGGING_SHIM=" + config.ShimLogLevel,
......
......@@ -31,6 +31,8 @@ import (
"github.com/hyperledger/fabric/core/aclmgmt/resources"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/mock"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/config"
......@@ -170,6 +172,7 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, error) {
config := GlobalConfig()
config.StartupTimeout = 10 * time.Second
config.ExecuteTimeout = 1 * time.Second
pr := platforms.NewRegistry(&golang.Platform{})
chaincodeSupport := NewChaincodeSupport(
config,
"0.0.0.0:7052",
......@@ -185,13 +188,14 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, error) {
},
),
sccp,
pr,
)
// Mock policy checker
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
ccp := &CCProviderImpl{cs: chaincodeSupport}
for _, cc := range scc.CreateSysCCs(ccp, sccp, mockAclProvider) {
for _, cc := range scc.CreateSysCCs(ccp, sccp, mockAclProvider, pr) {
sccp.RegisterSysCC(cc)
}
......
......@@ -13,6 +13,7 @@ import (
"strings"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
......@@ -37,11 +38,12 @@ type CertGenerator interface {
// ContainerRuntime is responsible for managing containerized chaincode.
type ContainerRuntime struct {
CertGenerator CertGenerator
Processor Processor
CACert []byte
CommonEnv []string
PeerAddress string
CertGenerator CertGenerator
Processor Processor
CACert []byte
CommonEnv []string
PeerAddress string
PlatformRegistry *platforms.Registry
}
// Start launches chaincode in a runtime environment.
......@@ -59,7 +61,8 @@ func (c *ContainerRuntime) Start(ctxt context.Context, cccid *ccprovider.CCConte
scr := container.StartContainerReq{
Builder: &container.PlatformBuilder{
DeploymentSpec: cds,
DeploymentSpec: cds,
PlatformRegistry: c.PlatformRegistry,
},
Args: lc.Args,
Env: lc.Envs,
......
......@@ -34,6 +34,8 @@ import (
"github.com/hyperledger/fabric/core/aclmgmt"
aclmocks "github.com/hyperledger/fabric/core/aclmgmt/mocks"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/config"
......@@ -125,6 +127,7 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
certGenerator := accesscontrol.NewAuthenticator(ca)
config := GlobalConfig()
config.StartupTimeout = 3 * time.Minute
pr := platforms.NewRegistry(&golang.Platform{})
chaincodeSupport := NewChaincodeSupport(
config,
peerAddress,
......@@ -140,6 +143,7 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
},
),
sccp,
pr,
)
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)
......@@ -147,7 +151,7 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
ccp := &CCProviderImpl{cs: chaincodeSupport}
for _, cc := range scc.CreateSysCCs(ccp, sccp, mockAclProvider) {
for _, cc := range scc.CreateSysCCs(ccp, sccp, mockAclProvider, pr) {
sccp.RegisterSysCC(cc)
}
......@@ -352,7 +356,7 @@ func endTxSimulation(chainID string, ccid *pb.ChaincodeID, txsim ledger.TxSimula
// Build a chaincode.
func getDeploymentSpec(_ context.Context, spec *pb.ChaincodeSpec) (*pb.ChaincodeDeploymentSpec, error) {
fmt.Printf("getting deployment spec for chaincode spec: %v\n", spec)
codePackageBytes, err := container.GetChaincodePackageBytes(spec)
codePackageBytes, err := container.GetChaincodePackageBytes(platforms.NewRegistry(&golang.Platform{}), spec)
if err != nil {
return nil, err
}
......
......@@ -35,6 +35,11 @@ import (
type Platform struct {
}
// Name returns the name of this platform
func (carPlatform *Platform) Name() string {
return pb.ChaincodeSpec_CAR.String()
}
// ValidateSpec validates the chaincode specification for CAR types to satisfy
// the platform interface. This chaincode type currently doesn't
// require anything specific so we just implicitly approve any spec
......
......@@ -12,6 +12,7 @@ import (
"github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/car"
"github.com/hyperledger/fabric/core/container"
cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer"
......@@ -34,13 +35,13 @@ func NewVM() (*VM, error) {
// BuildChaincodeContainer builds the container for the supplied chaincode specification
func (vm *VM) BuildChaincodeContainer(spec *pb.ChaincodeSpec) error {
codePackage, err := container.GetChaincodePackageBytes(spec)
codePackage, err := container.GetChaincodePackageBytes(platforms.NewRegistry(&car.Platform{}), spec)
if err != nil {
return fmt.Errorf("Error getting chaincode package bytes: %s", err)
}
cds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackage}
dockerSpec, err := platforms.NewRegistry().GenerateDockerBuild(cds)
dockerSpec, err := platforms.NewRegistry(&car.Platform{}).GenerateDockerBuild(cds)
if err != nil {
return fmt.Errorf("Error getting chaincode docker image: %s", err)
}
......
......@@ -98,6 +98,11 @@ func filter(vs []string, f func(string) bool) []string {
return vsf
}
// Name returns the name of this platform
func (goPlatform *Platform) Name() string {
return pb.ChaincodeSpec_GOLANG.String()
}
// ValidateSpec validates Go chaincodes
func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
path, err := url.Parse(spec.ChaincodeId.Path)
......
......@@ -23,6 +23,11 @@ import (
type Platform struct {
}
// Name returns the name of this platform
func (javaPlatform *Platform) Name() string {
return pb.ChaincodeSpec_JAVA.String()
}
//ValidateSpec validates the java chaincode specs
func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
path, err := url.Parse(spec.ChaincodeId.Path)
......
......@@ -10,6 +10,15 @@ import (
)
type Platform struct {
NameStub func() string
nameMutex sync.RWMutex
nameArgsForCall []struct{}
nameReturns struct {
result1 string
}
nameReturnsOnCall map[int]struct {
result1 string
}
ValidateSpecStub func(spec *pb.ChaincodeSpec) error
validateSpecMutex sync.RWMutex
validateSpecArgsForCall []struct {
......@@ -85,6 +94,46 @@ type Platform struct {
invocationsMutex sync.RWMutex
}
func (fake *Platform) Name() string {
fake.nameMutex.Lock()
ret, specificReturn := fake.nameReturnsOnCall[len(fake.nameArgsForCall)]
fake.nameArgsForCall = append(fake.nameArgsForCall, struct{}{})
fake.recordInvocation("Name", []interface{}{})
fake.nameMutex.Unlock()
if fake.NameStub != nil {
return fake.NameStub()
}
if specificReturn {
return ret.result1
}
return fake.nameReturns.result1
}
func (fake *Platform) NameCallCount() int {
fake.nameMutex.RLock()
defer fake.nameMutex.RUnlock()
return len(fake.nameArgsForCall)
}
func (fake *Platform) NameReturns(result1 string) {
fake.NameStub = nil
fake.nameReturns = struct {
result1 string
}{result1}
}
func (fake *Platform) NameReturnsOnCall(i int, result1 string) {
fake.NameStub = nil
if fake.nameReturnsOnCall == nil {
fake.nameReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.nameReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
fake.validateSpecMutex.Lock()
ret, specificReturn := fake.validateSpecReturnsOnCall[len(fake.validateSpecArgsForCall)]
......@@ -383,6 +432,8 @@ func (fake *Platform) GetMetadataProviderReturnsOnCall(i int, result1 ccmetadata
func (fake *Platform) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.nameMutex.RLock()
defer fake.nameMutex.RUnlock()
fake.validateSpecMutex.RLock()
defer fake.validateSpecMutex.RUnlock()
fake.validateDeploymentSpecMutex.RLock()
......
......@@ -43,6 +43,11 @@ func pathExists(path string) (bool, error) {
return true, err
}
// Name returns the name of this platform
func (nodePlatform *Platform) Name() string {
return pb.ChaincodeSpec_NODE.String()
}
// ValidateSpec validates Go chaincodes
func (nodePlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
path, err := url.Parse(spec.ChaincodeId.Path)
......
......@@ -16,11 +16,7 @@ import (
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/metadata"
"github.com/hyperledger/fabric/core/chaincode/platforms/car"
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/platforms/java"
"github.com/hyperledger/fabric/core/chaincode/platforms/node"
cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer"
)
......@@ -28,6 +24,7 @@ import (
// Interface for validating the specification and and writing the package for
// the given platform
type Platform interface {
Name() string
ValidateSpec(spec *pb.ChaincodeSpec) error
ValidateDeploymentSpec(spec *pb.ChaincodeDeploymentSpec) error
GetDeploymentPayload(spec *pb.ChaincodeSpec) ([]byte, error)
......@@ -53,15 +50,16 @@ type Registry struct {
var logger = flogging.MustGetLogger("chaincode-platform")
// TODO, ultimately this should take the platforms as parameters
func NewRegistry() *Registry {
func NewRegistry(platformTypes ...Platform) *Registry {
platforms := make(map[string]Platform)
for _, platform := range platformTypes {
if _, ok := platforms[platform.Name()]; ok {
logger.Panicf("Multiple platforms of the same name specified: %s", platform.Name())
}
platforms[platform.Name()] = platform
}
return &Registry{
Platforms: map[string]Platform{
pb.ChaincodeSpec_GOLANG.String(): &golang.Platform{},
pb.ChaincodeSpec_CAR.String(): &car.Platform{},
pb.ChaincodeSpec_JAVA.String(): &java.Platform{},
pb.ChaincodeSpec_NODE.String(): &node.Platform{},
},
Platforms: platforms,
PackageWriter: PackageWriterWrapper(cutil.WriteBytesToPackage),
}
}
......
......@@ -16,11 +16,7 @@ import (
"github.com/hyperledger/fabric/common/metadata"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/car"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/platforms/java"
"github.com/hyperledger/fabric/core/chaincode/platforms/mock"
"github.com/hyperledger/fabric/core/chaincode/platforms/node"
pb "github.com/hyperledger/fabric/protos/peer"
. "github.com/onsi/ginkgo"
......@@ -297,14 +293,28 @@ ENV CORE_CHAINCODE_BUILDLEVEL=%s`, metadata.Version, metadata.BaseVersion, metad
Describe("NewRegistry", func() {
It("initializes with the known platform types and util writer", func() {
registry = platforms.NewRegistry()
fakePlatformFoo := &mock.Platform{}
fakePlatformFoo.NameReturns("foo")
fakePlatformBar := &mock.Platform{}
fakePlatformBar.NameReturns("bar")
registry = platforms.NewRegistry(fakePlatformFoo, fakePlatformBar)
Expect(registry.Platforms).To(Equal(map[string]platforms.Platform{
pb.ChaincodeSpec_GOLANG.String(): &golang.Platform{},
pb.ChaincodeSpec_CAR.String(): &car.Platform{},
pb.ChaincodeSpec_JAVA.String(): &java.Platform{},
pb.ChaincodeSpec_NODE.String(): &node.Platform{},
"foo": fakePlatformFoo,
"bar": fakePlatformBar,
}))
})
Context("when two platforms report the same name", func() {
It("panics", func() {
fakePlatformFoo1 := &mock.Platform{}
fakePlatformFoo1.NameReturns("foo")
fakePlatformFoo2 := &mock.Platform{}
fakePlatformFoo2.NameReturns("foo")
Expect(func() { platforms.NewRegistry(fakePlatformFoo1, fakePlatformFoo2) }).To(Panic())
})
})
})
Describe("PackageWriterWrapper", func() {
......
......@@ -15,6 +15,8 @@ import (
"github.com/hyperledger/fabric/common/crypto/tlsgen"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container"
......@@ -141,6 +143,7 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, *ChaincodeSupport, error) {
},
),
sccp,
platforms.NewRegistry(&golang.Platform{}),
)
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)
......
......@@ -14,6 +14,8 @@ import (
"github.com/hyperledger/fabric/common/configtx"
commonerrors "github.com/hyperledger/fabric/common/errors"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/common/sysccprovider"
"github.com/hyperledger/fabric/core/common/validation"
"github.com/hyperledger/fabric/core/ledger"
......@@ -563,7 +565,7 @@ func (v *TxValidator) getTxCCInstance(payload *common.Payload) (invokeCCIns, upg
}
func (v *TxValidator) getUpgradeTxInstance(chainID string, cdsBytes []byte) (*sysccprovider.ChaincodeInstance, error) {
cds, err := utils.GetChaincodeDeploymentSpec(cdsBytes)
cds, err := utils.GetChaincodeDeploymentSpec(cdsBytes, platforms.NewRegistry(&golang.Platform{}))
if err != nil {
return nil, err
}
......
......@@ -31,7 +31,7 @@ type TarFileEntry struct {
// ExtractStatedbArtifactsAsTarbytes extracts the statedb artifacts from the code package tar and create a statedb artifact tar.
// The state db artifacts are expected to contain state db specific artifacts such as index specification in the case of couchdb.
// This function is intented to be used during chaincode instantiate/upgrade so that statedb artifacts can be created.
func ExtractStatedbArtifactsForChaincode(ccname, ccversion string) (installed bool, statedbArtifactsTar []byte, err error) {
func ExtractStatedbArtifactsForChaincode(ccname, ccversion string, pr *platforms.Registry) (installed bool, statedbArtifactsTar []byte, err error) {
ccpackage, err := GetChaincodeFromFS(ccname, ccversion)
if err != nil {
// TODO for now, we assume that an error indicates that the chaincode is not installed on the peer.
......@@ -41,16 +41,16 @@ func ExtractStatedbArtifactsForChaincode(ccname, ccversion string) (installed bo
return false, nil, nil
}
statedbArtifactsTar, err = ExtractStatedbArtifactsFromCCPackage(ccpackage)
statedbArtifactsTar, err = ExtractStatedbArtifactsFromCCPackage(ccpackage, pr)
return true, statedbArtifactsTar, err
}
// ExtractStatedbArtifactsFromCCPackage extracts the statedb artifacts from the code package tar and create a statedb artifact tar.
// The state db artifacts are expected to contain state db specific artifacts such as index specification in the case of couchdb.
// This function is called during chaincode instantiate/upgrade (from above), and from install, so that statedb artifacts can be created.
func ExtractStatedbArtifactsFromCCPackage(ccpackage CCPackage) (statedbArtifactsTar []byte, err error) {
func ExtractStatedbArtifactsFromCCPackage(ccpackage CCPackage, pr *platforms.Registry) (statedbArtifactsTar []byte, err error) {
cds := ccpackage.GetDepSpec()
metaprov, err := platforms.NewRegistry().GetMetadataProvider(cds)
metaprov, err := pr.GetMetadataProvider(cds)
if err != nil {
ccproviderLogger.Infof("invalid deployment spec: %s", err)
return nil, fmt.Errorf("invalid deployment spec")
......
......@@ -127,12 +127,13 @@ type StartContainerReq struct {
// the dockercontroller package with the CDS, which is also
// undesirable.
type PlatformBuilder struct {
DeploymentSpec *pb.ChaincodeDeploymentSpec
DeploymentSpec *pb.ChaincodeDeploymentSpec
PlatformRegistry *platforms.Registry
}
// Build a tar stream based on the CDS
func (b *PlatformBuilder) Build() (io.Reader, error) {
return platforms.NewRegistry().GenerateDockerBuild(b.DeploymentSpec)
return b.PlatformRegistry.GenerateDockerBuild(b.DeploymentSpec)
}
func (si StartContainerReq) Do(ctxt context.Context, v VM) error {
......@@ -195,10 +196,10 @@ func (vmc *VMController) Process(ctxt context.Context, vmtype string, req VMCReq
}
// GetChaincodePackageBytes creates bytes for docker container generation using the supplied chaincode specification
func GetChaincodePackageBytes(spec *pb.ChaincodeSpec) ([]byte, error) {
func GetChaincodePackageBytes(pr *platforms.Registry, spec *pb.ChaincodeSpec) ([]byte, error) {
if spec == nil || spec.ChaincodeId == nil {
return nil, fmt.Errorf("invalid chaincode spec")
}
return platforms.NewRegistry().GetDeploymentPayload(spec)
return pr.GetDeploymentPayload(spec)
}
......@@ -10,23 +10,25 @@ import (
"testing"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/container"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
)
func TestVM_GetChaincodePackageBytes(t *testing.T) {
_, err := container.GetChaincodePackageBytes(nil)
_, err := container.GetChaincodePackageBytes(nil, nil)
assert.Error(t, err,
"GetChaincodePackageBytes did not return error when chaincode spec is nil")
spec := &pb.ChaincodeSpec{ChaincodeId: nil}
_, err = container.GetChaincodePackageBytes(spec)
_, err = container.GetChaincodePackageBytes(nil, spec)
assert.Error(t, err, "Error expected when GetChaincodePackageBytes is called with nil chaincode ID")
assert.Contains(t, err.Error(), "invalid chaincode spec")
spec = &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: nil,
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
_, err = container.GetChaincodePackageBytes(spec)
_, err = container.GetChaincodePackageBytes(platforms.NewRegistry(&golang.Platform{}), spec)
assert.Error(t, err,
"GetChaincodePackageBytes did not return error when chaincode ID is nil")
}
......@@ -26,6 +26,7 @@ import (
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/container/ccintf"
coreutil "github.com/hyperledger/fabric/core/testutil"
pb "github.com/hyperledger/fabric/protos/peer"
......@@ -119,13 +120,13 @@ func Test_Start(t *testing.T) {
ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath},
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")},
}
codePackage, err := platforms.NewRegistry().GetDeploymentPayload(spec)
codePackage, err := platforms.NewRegistry(&golang.Platform{}).GetDeploymentPayload(spec)
if err != nil {
t.Fatal()
}
cds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackage}
bldr := &mockBuilder{
buildFunc: func() (io.Reader, error) { return platforms.NewRegistry().GenerateDockerBuild(cds) },
buildFunc: func() (io.Reader, error) { return platforms.NewRegistry(&golang.Platform{}).GenerateDockerBuild(cds) },
}
// case 4: start called with builder and dockerClient.CreateContainer returns
......
......@@ -15,6 +15,7 @@ import (
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/common/validation"
......@@ -96,6 +97,7 @@ type Support interface {
type Endorser struct {
distributePrivateData privateDataDistributor
s Support
PlatformRegistry *platforms.Registry
PvtRWSetAssembler
}
......@@ -109,10 +111,11 @@ type validateResult struct {
}
// NewEndorserServer creates and returns a new Endorser server instance.
func NewEndorserServer(privDist privateDataDistributor, s Support) *Endorser {
func NewEndorserServer(privDist privateDataDistributor, s Support, pr *platforms.Registry) *Endorser {
e := &Endorser{
distributePrivateData: privDist,
s: s,
PlatformRegistry: pr,
PvtRWSetAssembler: &rwSetAssembler{},
}
return e
......@@ -154,7 +157,7 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
// NOTE that if there's an error all simulation, including the chaincode
// table changes in lscc will be thrown away
if cid.Name == "lscc" && len(cis.ChaincodeSpec.Input.Args) >= 3 && (string(cis.ChaincodeSpec.Input.Args[0]) == "deploy" || string(cis.ChaincodeSpec.Input.Args[0]) == "upgrade") {
userCDS, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[2])
userCDS, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[2], e.PlatformRegistry)
if err != nil {
return nil, nil, err
}
......
......@@ -16,6 +16,8 @@ import (
mc "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/common/mocks/resourcesconfig"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/endorser"
"github.com/hyperledger/fabric/core/endorser/mocks"
......@@ -86,7 +88,7 @@ func TestEndorserNilProp(t *testing.T) {
PubSimulationResults: &rwset.TxReadWriteSet{},
},
},
})
}, platforms.NewRegistry(&golang.Platform{}))
pResp, err := es.ProcessProposal(context.Background(), nil)
assert.Error(t, err)
......@@ -100,7 +102,7 @@ func TestEndorserUninvokableSysCC(t *testing.T) {
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
IsSysCCAndNotInvokableExternalRv: true,
})
}, platforms.NewRegistry(&golang.Platform{}))
signedProp := getSignedProp("ccid", "0", t)
......@@ -122,7 +124,7 @@ func TestEndorserCCInvocationFailed(t *testing.T) {
PubSimulationResults: &rwset.TxReadWriteSet{},
},
},
})
}, platforms.NewRegistry(&golang.Platform{}))