Skip to content

Commit d3790af

Browse files
author
Jason Yellick
committed
FAB-14628 _lifecycle give containerinfo for SCC
Presently, there is special case logic for system chaincodes around gathering container info. This is extra silly since system chaincodes never need to be launched. Still, the lifecycle can provide this info so as to avoid the special casing. Change-Id: If5366c2cafdb5f285ce1150967580d359883b498 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent d8d60da commit d3790af

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

core/chaincode/chaincode_support.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ func processChaincodeExecutionResult(txid, ccName string, resp *pb.ChaincodeMess
211211
// Invoke will invoke chaincode and return the message containing the response.
212212
// The chaincode will be launched if it is not already running.
213213
func (cs *ChaincodeSupport) Invoke(txParams *ccprovider.TransactionParams, cccid *ccprovider.CCContext, input *pb.ChaincodeInput) (*pb.ChaincodeMessage, error) {
214-
if cs.BuiltinSCCs.IsSysCC(cccid.Name) {
215-
return cs.invokeSystem(txParams, cccid, input)
216-
}
217-
218214
// go to _lifecycle to retrieve information about the chaincode
219215
ccci, err := cs.Lifecycle.ChaincodeContainerInfo(txParams.ChannelID, cccid.Name, txParams.TXSimulator)
220216
if err != nil {
@@ -244,22 +240,6 @@ func (cs *ChaincodeSupport) Invoke(txParams *ccprovider.TransactionParams, cccid
244240
return cs.execute(cctype, txParams, cccid, input, h)
245241
}
246242

247-
func (cs *ChaincodeSupport) invokeSystem(txParams *ccprovider.TransactionParams, cccid *ccprovider.CCContext, input *pb.ChaincodeInput) (*pb.ChaincodeMessage, error) {
248-
// FIXME: remove this once _lifecycle has definitions for all system chaincodes (FAB-14628)
249-
ccci := &ccprovider.ChaincodeContainerInfo{
250-
Version: cs.SystemCCVersion,
251-
Name: cccid.Name,
252-
PackageID: persistence.PackageID(cccid.Name + ":" + cs.SystemCCVersion),
253-
}
254-
255-
h, err := cs.Launch(txParams.ChannelID, ccci)
256-
if err != nil {
257-
return nil, err
258-
}
259-
260-
return cs.execute(pb.ChaincodeMessage_TRANSACTION, txParams, cccid, input, h)
261-
}
262-
263243
func (cs *ChaincodeSupport) CheckInit(txParams *ccprovider.TransactionParams, cccid *ccprovider.CCContext, input *pb.ChaincodeInput) (bool, error) {
264244
if txParams.ChannelID == "" {
265245
// Channel-less invocations must be for SCCs, so, we ignore them for now

core/chaincode/lifecycle/legacy_lifecycle.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111

1212
"github.com/hyperledger/fabric/common/util"
1313
corechaincode "github.com/hyperledger/fabric/core/chaincode"
14+
persistence "github.com/hyperledger/fabric/core/chaincode/persistence/intf"
1415
"github.com/hyperledger/fabric/core/common/ccprovider"
1516
"github.com/hyperledger/fabric/core/ledger"
17+
"github.com/hyperledger/fabric/core/scc"
1618

1719
"github.com/pkg/errors"
1820
)
@@ -68,9 +70,11 @@ func (ld *LegacyDefinition) RequiresInit() bool {
6870
}
6971

7072
type ChaincodeEndorsementInfo struct {
71-
Resources *Resources
72-
Cache ChaincodeInfoCache
73-
LegacyImpl LegacyLifecycle
73+
Resources *Resources
74+
Cache ChaincodeInfoCache
75+
LegacyImpl LegacyLifecycle
76+
BuiltinSCCs scc.BuiltinSCCs
77+
SysCCVersion string
7478
}
7579

7680
func (cei *ChaincodeEndorsementInfo) CachedChaincodeInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*LocalChaincodeInfo, bool, error) {
@@ -142,8 +146,17 @@ func (cei *ChaincodeEndorsementInfo) ChaincodeDefinition(channelID, chaincodeNam
142146
}, nil
143147
}
144148

145-
// ChaincodeContainerInfo returns the information necessary to launch a chaincode
149+
// ChaincodeContainerInfo returns the information necessary to launch a chaincode, it also returns
150+
// static definitions for the fabric defined system chaincodes
146151
func (cei *ChaincodeEndorsementInfo) ChaincodeContainerInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error) {
152+
if cei.BuiltinSCCs.IsSysCC(chaincodeName) {
153+
return &ccprovider.ChaincodeContainerInfo{
154+
PackageID: persistence.PackageID(chaincodeName + ":" + cei.SysCCVersion),
155+
Name: chaincodeName,
156+
Version: cei.SysCCVersion,
157+
}, nil
158+
}
159+
147160
chaincodeInfo, ok, err := cei.CachedChaincodeInfo(channelID, chaincodeName, qe)
148161
if err != nil {
149162
return nil, err

core/chaincode/lifecycle/legacy_lifecycle_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
1414
"github.com/hyperledger/fabric/core/chaincode/lifecycle/mock"
1515
"github.com/hyperledger/fabric/core/common/ccprovider"
16+
"github.com/hyperledger/fabric/core/scc"
1617
lb "github.com/hyperledger/fabric/protos/peer/lifecycle"
1718

1819
persistence "github.com/hyperledger/fabric/core/chaincode/persistence/intf"
@@ -29,6 +30,7 @@ var _ = Describe("ChaincodeEndorsementInfo", func() {
2930
fakeQueryExecutor *mock.SimpleQueryExecutor
3031
fakeCache *mock.ChaincodeInfoCache
3132
testInfo *lifecycle.LocalChaincodeInfo
33+
builtinSCCs scc.BuiltinSCCs
3234
)
3335

3436
BeforeEach(func() {
@@ -44,6 +46,8 @@ var _ = Describe("ChaincodeEndorsementInfo", func() {
4446
return fakePublicState.GetState(key)
4547
}
4648

49+
builtinSCCs = map[string]struct{}{}
50+
4751
err := resources.Serializer.Serialize(lifecycle.NamespacesName,
4852
"name",
4953
&lifecycle.ChaincodeDefinition{
@@ -77,9 +81,11 @@ var _ = Describe("ChaincodeEndorsementInfo", func() {
7781
fakeCache.ChaincodeInfoReturns(testInfo, nil)
7882

7983
cei = &lifecycle.ChaincodeEndorsementInfo{
80-
LegacyImpl: fakeLegacyImpl,
81-
Resources: resources,
82-
Cache: fakeCache,
84+
LegacyImpl: fakeLegacyImpl,
85+
Resources: resources,
86+
Cache: fakeCache,
87+
BuiltinSCCs: builtinSCCs,
88+
SysCCVersion: "test-syscc-version",
8389
}
8490

8591
})
@@ -240,6 +246,22 @@ var _ = Describe("ChaincodeEndorsementInfo", func() {
240246
}))
241247
})
242248

249+
Context("when the chaincode is a builtin system chaincode", func() {
250+
BeforeEach(func() {
251+
builtinSCCs["test-syscc-name"] = struct{}{}
252+
})
253+
254+
It("returns a static definition", func() {
255+
res, err := cei.ChaincodeContainerInfo("channel-id", "test-syscc-name", fakeQueryExecutor)
256+
Expect(err).NotTo(HaveOccurred())
257+
Expect(res).To(Equal(&ccprovider.ChaincodeContainerInfo{
258+
Name: "test-syscc-name",
259+
Version: "test-syscc-version",
260+
PackageID: "test-syscc-name:test-syscc-version",
261+
}))
262+
})
263+
})
264+
243265
Context("when the definition does not exist in the new lifecycle", func() {
244266
var (
245267
legacyContainerInfo *ccprovider.ChaincodeContainerInfo

internal/peer/node/start.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,11 @@ func serve(args []string) error {
435435
HandlerRegistry: chaincodeHandlerRegistry,
436436
}
437437
chaincodeEndorsementInfo := &lifecycle.ChaincodeEndorsementInfo{
438-
LegacyImpl: lsccInst,
439-
Resources: lifecycleResources,
440-
Cache: lifecycleCache,
438+
LegacyImpl: lsccInst,
439+
Resources: lifecycleResources,
440+
Cache: lifecycleCache,
441+
BuiltinSCCs: builtinSCCs,
442+
SysCCVersion: sysCCVersion,
441443
}
442444

443445
lifecycleFunctions := &lifecycle.ExternalFunctions{

0 commit comments

Comments
 (0)