Skip to content

Commit

Permalink
[FAB-9737] Introduce PackageProvider interface
Browse files Browse the repository at this point in the history
Change-Id: Ic76e26eb9e8d145eb48c2d792c01c87e0e3c538a
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Apr 27, 2018
1 parent 9d781a1 commit a12d256
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ type Runtime interface {
Stop(ctxt context.Context, cccid *ccprovider.CCContext, cds *pb.ChaincodeDeploymentSpec) error
}

// PackageProvider is responsible for getting the chaincode package from
// the filesystem.
type PackageProvider interface {
GetChaincode(ccname string, ccversion string) (ccprovider.CCPackage, error)
}

// NewChaincodeSupport creates a new ChaincodeSupport instance
func NewChaincodeSupport(
config *Config,
Expand All @@ -45,6 +51,7 @@ func NewChaincodeSupport(
ccstartuptimeout time.Duration,
caCert []byte,
certGenerator CertGenerator,
packageProvider PackageProvider,
) *ChaincodeSupport {
cs := &ChaincodeSupport{
caCert: caCert,
Expand All @@ -55,6 +62,7 @@ func NewChaincodeSupport(
keepalive: config.Keepalive,
executetimeout: config.ExecuteTimeout,
handlerRegistry: NewHandlerRegistry(userrunsCC),
PackageProvider: packageProvider,
}

// Keep TestQueries working
Expand Down Expand Up @@ -91,6 +99,7 @@ type ChaincodeSupport struct {
executetimeout time.Duration
userRunsCC bool
ContainerRuntime Runtime
PackageProvider PackageProvider
sccp sysccprovider.SystemChaincodeProvider
}

Expand Down Expand Up @@ -228,7 +237,7 @@ func (cs *ChaincodeSupport) Launch(context context.Context, cccid *ccprovider.CC
if cds.CodePackage == nil {
//no code bytes for these situations
if !(cs.userRunsCC || cds.ExecEnv == pb.ChaincodeDeploymentSpec_SYSTEM) {
ccpack, err := ccprovider.GetChaincodeFromFS(cID.Name, cID.Version)
ccpack, err := cs.PackageProvider.GetChaincode(cID.Name, cID.Version)
if err != nil {
return cID, cMsg, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/chaincode_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, error) {
ccprovider.SetChaincodesPath(ccprovider.GetCCsPath())
ca, _ := accesscontrol.NewCA()
certGenerator := accesscontrol.NewAuthenticator(ca)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), "0.0.0.0:7052", true, ccStartupTimeout, ca.CertBytes(), certGenerator)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), "0.0.0.0:7052", true, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
SideEffectInitialize(chaincodeSupport)
chaincodeSupport.SetSysCCProvider(sccp)
chaincodeSupport.executetimeout = time.Duration(1) * time.Second
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
ccprovider.SetChaincodesPath(ccprovider.GetCCsPath())
ca, _ := accesscontrol.NewCA()
certGenerator := accesscontrol.NewAuthenticator(ca)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
chaincodeSupport.SetSysCCProvider(sccp)
SideEffectInitialize(chaincodeSupport)
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/systemchaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, *ChaincodeSupport, error) {
ccStartupTimeout := time.Duration(5000) * time.Millisecond
ca, _ := accesscontrol.NewCA()
certGenerator := accesscontrol.NewAuthenticator(ca)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator)
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)

go grpcServer.Serve(lis)
Expand Down
2 changes: 1 addition & 1 deletion core/scc/cscc/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
ccStartupTimeout := time.Duration(30000) * time.Millisecond
ca, _ := accesscontrol.NewCA()
certGenerator := accesscontrol.NewAuthenticator(ca)
chaincode.NewChaincodeSupport(chaincode.GlobalConfig(), peerEndpoint, false, ccStartupTimeout, ca.CertBytes(), certGenerator)
chaincode.NewChaincodeSupport(chaincode.GlobalConfig(), peerEndpoint, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})

// Init the policy checker
policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{
Expand Down
1 change: 1 addition & 0 deletions peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ func registerChaincodeSupport(grpcServer *comm.GRPCServer, ccEndpoint string, ca
ccStartupTimeout,
ca.CertBytes(),
authenticator,
&ccprovider.CCInfoFSImpl{},
)
chaincode.SideEffectInitialize(chaincodeSupport)

Expand Down

0 comments on commit a12d256

Please sign in to comment.