Skip to content

Commit 007c80d

Browse files
author
Jason Yellick
committed
FAB-16124 Remove SysCCProvider as dep everywhere
There are no longer any locations in the code which actually need a reference to the system cc provider other than LSCC, which is only using the sysccprovider as a veneer to get at a peer instance. This change prepares to remove the SysCCProvider entirely. Change-Id: I6d468acf55e8d6e454ef2a3b6e3373f1ab4b09ab Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent e88a71d commit 007c80d

File tree

7 files changed

+37
-49
lines changed

7 files changed

+37
-49
lines changed

core/chaincode/chaincode_support_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ func (p *PackageProviderWrapper) GetChaincodeCodePackage(ccci *ccprovider.Chainc
152152
func initMockPeer(chainIDs ...string) (*peer.Peer, *ChaincodeSupport, func(), error) {
153153
peerInstance := &peer.Peer{}
154154
sccp := &scc.Provider{
155-
Peer: peerInstance,
156155
Whitelist: scc.GlobalWhitelist(),
157156
}
158157

@@ -177,7 +176,7 @@ func initMockPeer(chainIDs ...string) (*peer.Peer, *ChaincodeSupport, func(), er
177176
globalConfig := GlobalConfig()
178177
globalConfig.StartupTimeout = 10 * time.Second
179178
globalConfig.ExecuteTimeout = 1 * time.Second
180-
lsccImpl := lscc.New(map[string]struct{}{"lscc": {}}, sccp, mockAclProvider, peerInstance.GetMSPIDs, newPolicyChecker(peerInstance))
179+
lsccImpl := lscc.New(map[string]struct{}{"lscc": {}}, &lscc.PeerShim{Peer: peerInstance}, mockAclProvider, peerInstance.GetMSPIDs, newPolicyChecker(peerInstance))
181180
ml := &mock.Lifecycle{}
182181
ml.ChaincodeContainerInfoStub = func(_, name string, _ ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error) {
183182
switch name {

core/chaincode/exectransaction_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import (
7474
func initPeer(chainIDs ...string) (*cm.Lifecycle, net.Listener, *ChaincodeSupport, func(), error) {
7575
peerInstance := &peer.Peer{}
7676
sccp := &scc.Provider{
77-
Peer: peerInstance,
7877
Whitelist: scc.GlobalWhitelist(),
7978
}
8079

@@ -110,7 +109,7 @@ func initPeer(chainIDs ...string) (*cm.Lifecycle, net.Listener, *ChaincodeSuppor
110109
pr := platforms.NewRegistry(&golang.Platform{})
111110
mockAclProvider := &mock.ACLProvider{}
112111
builtinSCCs := map[string]struct{}{"lscc": {}}
113-
lsccImpl := lscc.New(builtinSCCs, sccp, mockAclProvider, peerInstance.GetMSPIDs, newPolicyChecker(peerInstance))
112+
lsccImpl := lscc.New(builtinSCCs, &lscc.PeerShim{Peer: peerInstance}, mockAclProvider, peerInstance.GetMSPIDs, newPolicyChecker(peerInstance))
114113
ml := &cm.Lifecycle{}
115114
ml.ChaincodeContainerInfoStub = func(_, name string, _ ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error) {
116115
switch name {

core/endorser/support.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type SupportImpl struct {
3939
identity.SignerSerializer
4040
Peer PeerOperations
4141
ChaincodeSupport *chaincode.ChaincodeSupport
42-
SysCCProvider *scc.Provider
4342
ACLProvider aclmgmt.ACLProvider
4443
BuiltinSCCs scc.BuiltinSCCs
4544
}

core/scc/lscc/lscc.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212

1313
"github.com/golang/protobuf/proto"
1414
"github.com/hyperledger/fabric/common/cauthdsl"
15+
"github.com/hyperledger/fabric/common/channelconfig"
1516
"github.com/hyperledger/fabric/common/flogging"
17+
"github.com/hyperledger/fabric/common/policies"
1618
"github.com/hyperledger/fabric/core/aclmgmt"
1719
"github.com/hyperledger/fabric/core/aclmgmt/resources"
1820
"github.com/hyperledger/fabric/core/chaincode/shim"
@@ -21,6 +23,7 @@ import (
2123
"github.com/hyperledger/fabric/core/common/sysccprovider"
2224
"github.com/hyperledger/fabric/core/ledger"
2325
"github.com/hyperledger/fabric/core/ledger/cceventmgmt"
26+
"github.com/hyperledger/fabric/core/peer"
2427
"github.com/hyperledger/fabric/core/policy"
2528
"github.com/hyperledger/fabric/core/scc"
2629
"github.com/hyperledger/fabric/internal/ccmetadata"
@@ -147,6 +150,37 @@ type LifeCycleSysCC struct {
147150
GetMSPIDs MSPIDsGetter
148151
}
149152

153+
// PeerShim adapts the peer instance for use with LSCC by providing methods
154+
// previously provided by the scc provider. If the lscc code weren't all getting
155+
// deleted soon, it would probably be worth rewriting it to use these APIs directly
156+
// rather that go through this shim, but it will be gone soon.
157+
type PeerShim struct {
158+
Peer *peer.Peer
159+
}
160+
161+
// GetQueryExecutorForLedger returns a query executor for the specified channel
162+
func (p *PeerShim) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) {
163+
l := p.Peer.GetLedger(cid)
164+
if l == nil {
165+
return nil, fmt.Errorf("Could not retrieve ledger for channel %s", cid)
166+
}
167+
168+
return l.NewQueryExecutor()
169+
}
170+
171+
// GetApplicationConfig returns the configtxapplication.SharedConfig for the channel
172+
// and whether the Application config exists
173+
func (p *PeerShim) GetApplicationConfig(cid string) (channelconfig.Application, bool) {
174+
return p.Peer.GetApplicationConfig(cid)
175+
}
176+
177+
// Returns the policy manager associated to the passed channel
178+
// and whether the policy manager exists
179+
func (p *PeerShim) PolicyManager(channelID string) (policies.Manager, bool) {
180+
m := p.Peer.GetPolicyManager(channelID)
181+
return m, (m != nil)
182+
}
183+
150184
// New creates a new instance of the LSCC
151185
// Typically there is only one of these per peer
152186
func New(

core/scc/scc_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212

1313
"github.com/hyperledger/fabric/core/container/ccintf"
14-
"github.com/hyperledger/fabric/core/peer"
1514
"github.com/hyperledger/fabric/core/scc"
1615
"github.com/hyperledger/fabric/core/scc/mock"
1716
"github.com/onsi/gomega"
@@ -30,7 +29,6 @@ func init() {
3029

3130
func newTestProvider() *scc.Provider {
3231
p := &scc.Provider{
33-
Peer: &peer.Peer{},
3432
Whitelist: map[string]bool{
3533
"invokableExternalButNotCC2CC": true,
3634
"invokableCC2CCButNotExternal": true,
@@ -81,15 +79,6 @@ func TestDeploy(t *testing.T) {
8179
gt.Eventually(csh.HandleChaincodeStreamCallCount).Should(gomega.Equal(2))
8280
}
8381

84-
func TestSccProviderImpl_GetQueryExecutorForLedger(t *testing.T) {
85-
p := &scc.Provider{
86-
Peer: &peer.Peer{},
87-
}
88-
qe, err := p.GetQueryExecutorForLedger("")
89-
assert.Nil(t, qe)
90-
assert.Error(t, err)
91-
}
92-
9382
func TestCreatePluginSysCCs(t *testing.T) {
9483
assert.NotPanics(t, func() { scc.CreatePluginSysCCs() }, "expected successful init")
9584
}

core/scc/sccproviderimpl.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package scc
88

99
import (
10-
"fmt"
11-
12-
"github.com/hyperledger/fabric/common/channelconfig"
13-
"github.com/hyperledger/fabric/common/policies"
14-
"github.com/hyperledger/fabric/core/ledger"
15-
"github.com/hyperledger/fabric/core/peer"
1610
"github.com/pkg/errors"
1711
)
1812

@@ -31,7 +25,6 @@ func (bccs BuiltinSCCs) IsSysCC(name string) bool {
3125

3226
// Provider implements sysccprovider.SystemChaincodeProvider
3327
type Provider struct {
34-
Peer *peer.Peer
3528
SysCCs []SelfDescribingSysCC
3629
Whitelist Whitelist
3730
}
@@ -47,29 +40,6 @@ func (p *Provider) RegisterSysCC(scc SelfDescribingSysCC) error {
4740
return nil
4841
}
4942

50-
// GetQueryExecutorForLedger returns a query executor for the specified channel
51-
func (p *Provider) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) {
52-
l := p.Peer.GetLedger(cid)
53-
if l == nil {
54-
return nil, fmt.Errorf("Could not retrieve ledger for channel %s", cid)
55-
}
56-
57-
return l.NewQueryExecutor()
58-
}
59-
60-
// GetApplicationConfig returns the configtxapplication.SharedConfig for the channel
61-
// and whether the Application config exists
62-
func (p *Provider) GetApplicationConfig(cid string) (channelconfig.Application, bool) {
63-
return p.Peer.GetApplicationConfig(cid)
64-
}
65-
66-
// Returns the policy manager associated to the passed channel
67-
// and whether the policy manager exists
68-
func (p *Provider) PolicyManager(channelID string) (policies.Manager, bool) {
69-
m := p.Peer.GetPolicyManager(channelID)
70-
return m, (m != nil)
71-
}
72-
7343
func (p *Provider) isWhitelisted(syscc SelfDescribingSysCC) bool {
7444
enabled, ok := p.Whitelist[syscc.Name()]
7545
return ok && enabled

internal/peer/node/start.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ func serve(args []string) error {
410410
authenticator := accesscontrol.NewAuthenticator(ca)
411411

412412
sccp := &scc.Provider{
413-
Peer: peerInstance,
414413
Whitelist: scc.GlobalWhitelist(),
415414
}
416415

@@ -427,7 +426,7 @@ func serve(args []string) error {
427426
"_lifecycle": {},
428427
}
429428

430-
lsccInst := lscc.New(builtinSCCs, sccp, aclProvider, peerInstance.GetMSPIDs, policyChecker)
429+
lsccInst := lscc.New(builtinSCCs, &lscc.PeerShim{Peer: peerInstance}, aclProvider, peerInstance.GetMSPIDs, policyChecker)
431430

432431
chaincodeHandlerRegistry := chaincode.NewHandlerRegistry(userRunsCC)
433432
lifecycleTxQueryExecutorGetter := &chaincode.TxQueryExecutorGetter{
@@ -588,7 +587,6 @@ func serve(args []string) error {
588587
SignerSerializer: signingIdentity,
589588
Peer: peerInstance,
590589
ChaincodeSupport: chaincodeSupport,
591-
SysCCProvider: sccp,
592590
ACLProvider: aclProvider,
593591
BuiltinSCCs: builtinSCCs,
594592
}

0 commit comments

Comments
 (0)