Skip to content

Commit

Permalink
Remove LifecycleV20 application capability
Browse files Browse the repository at this point in the history
Remove LifecycleV20 application capability.

This is the first step in removing all v1.x application capabilities.

v3.0 should not support v1.x application capabilities
(peer should not recognize application capabilities
lower than V2_0_0 so that peer fails to start
against a channel that has outdated application capabilities,
user needs to update application capabilities on the channel
to at least V2_0_0 before updating peer to v3.0).

Mocks have been regenerated with LifecycleV20 removal.

Mocks that were used in deleted lscc_test.go have also been removed.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Aug 19, 2024
1 parent 732369f commit 5437abd
Show file tree
Hide file tree
Showing 25 changed files with 418 additions and 1,875 deletions.
8 changes: 0 additions & 8 deletions common/capabilities/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ func (ap *ApplicationProvider) V2_0Validation() bool {
return ap.v20 || ap.v25
}

// LifecycleV20 indicates whether the peer should use the deprecated and problematic
// v1.x lifecycle, or whether it should use the newer per channel approve/commit definitions
// process introduced in v2.0. Note, this should only be used on the endorsing side
// of peer processing, so that we may safely remove all checks against it in v2.1.
func (ap *ApplicationProvider) LifecycleV20() bool {
return ap.v20 || ap.v25
}

// MetadataLifecycle always returns false
func (ap *ApplicationProvider) MetadataLifecycle() bool {
return false
Expand Down
2 changes: 0 additions & 2 deletions common/capabilities/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func TestApplicationV20(t *testing.T) {
require.True(t, ap.ACLs())
require.True(t, ap.CollectionUpgrade())
require.True(t, ap.PrivateChannelData())
require.True(t, ap.LifecycleV20())
require.True(t, ap.StorePvtDataOfInvalidTx())
}

Expand All @@ -103,7 +102,6 @@ func TestApplicationV25(t *testing.T) {
require.True(t, ap.ACLs())
require.True(t, ap.CollectionUpgrade())
require.True(t, ap.PrivateChannelData())
require.True(t, ap.LifecycleV20())
require.True(t, ap.StorePvtDataOfInvalidTx())
require.True(t, ap.PurgePvtData())
}
Expand Down
6 changes: 0 additions & 6 deletions common/channelconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ type ApplicationCapabilities interface {
// - implicit per-org collections
V2_0Validation() bool

// LifecycleV20 indicates whether the peer should use the deprecated and problematic
// v1.x lifecycle, or whether it should use the newer per channel approve/commit definitions
// process introduced in v2.0. Note, this should only be used on the endorsing side
// of peer processing, so that we may safely remove all checks against it in v2.1.
LifecycleV20() bool

// MetadataLifecycle always returns false
MetadataLifecycle() bool

Expand Down
7 changes: 0 additions & 7 deletions core/chaincode/lifecycle/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,6 @@ func (c *Cache) StateCommitDone(channelName string) {
// An error is returned only if either the channel or the chaincode do not exist.
func (c *Cache) ChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error) {
if name == LifecycleNamespace {
ac, ok := c.Resources.ChannelConfigSource.GetStableChannelConfig(channelID).ApplicationConfig()
if !ok {
return nil, errors.Errorf("application config does not exist for channel '%s'", channelID)
}
if !ac.Capabilities().LifecycleV20() {
return nil, errors.Errorf("cannot use _lifecycle without V2_0 application capabilities enabled for channel '%s'", channelID)
}
return c.getLifecycleSCCChaincodeInfo(channelID)
}

Expand Down
12 changes: 0 additions & 12 deletions core/chaincode/lifecycle/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var _ = Describe("Cache", func() {
fakeApplicationConfig = &mock.ApplicationConfig{}
fakeChannelConfig.ApplicationConfigReturns(fakeApplicationConfig, true)
fakeCapabilities = &mock.ApplicationCapabilities{}
fakeCapabilities.LifecycleV20Returns(true)
fakeApplicationConfig.CapabilitiesReturns(fakeCapabilities)
fakePolicyManager = &mock.PolicyManager{}
fakePolicyManager.GetPolicyReturns(nil, true)
Expand Down Expand Up @@ -265,17 +264,6 @@ var _ = Describe("Cache", func() {
Expect(err).To(MatchError("application config does not exist for channel 'channel-id'"))
})
})

Context("when the application config V2_0 capabilities are not enabled", func() {
BeforeEach(func() {
fakeCapabilities.LifecycleV20Returns(false)
})

It("returns an error", func() {
_, err := c.ChaincodeInfo("channel-id", "_lifecycle")
Expect(err).To(MatchError("cannot use _lifecycle without V2_0 application capabilities enabled for channel 'channel-id'"))
})
})
})

Describe("ListInstalledChaincodes", func() {
Expand Down
15 changes: 2 additions & 13 deletions core/chaincode/lifecycle/endorsement_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,12 @@ func (cei *ChaincodeEndorsementInfoSource) ChaincodeEndorsementInfo(channelID, c
}, nil
}

// return legacy cc endorsement info if V20 is not enabled
channelConfig := cei.Resources.ChannelConfigSource.GetStableChannelConfig(channelID)
if channelConfig == nil {
return nil, errors.Errorf("could not get channel config for channel '%s'", channelID)
}
ac, ok := channelConfig.ApplicationConfig()
if !ok {
return nil, errors.Errorf("could not get application config for channel '%s'", channelID)
}
if !ac.Capabilities().LifecycleV20() {
return cei.LegacyImpl.ChaincodeEndorsementInfo(channelID, chaincodeName, qe)
}

chaincodeInfo, ok, err := cei.CachedChaincodeInfo(channelID, chaincodeName, qe)
if err != nil {
return nil, err
}

// fallback to legacy lifecycle if not defined in new lifeycle
if !ok {
return cei.LegacyImpl.ChaincodeEndorsementInfo(channelID, chaincodeName, qe)
}
Expand Down
48 changes: 0 additions & 48 deletions core/chaincode/lifecycle/endorsement_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var _ = Describe("ChaincodeEndorsementInfoSource", func() {
fakeChannelConfigSource.GetStableChannelConfigReturns(fakeChannelConfig)
fakeChannelConfig.ApplicationConfigReturns(fakeAppConfig, true)
fakeAppConfig.CapabilitiesReturns(fakeCapabilities)
fakeCapabilities.LifecycleV20Returns(true)

resources = &lifecycle.Resources{
Serializer: &lifecycle.Serializer{},
Expand Down Expand Up @@ -289,51 +288,4 @@ var _ = Describe("ChaincodeEndorsementInfoSource", func() {
})
})
})

Context("when LifecycleV20 capability is not enabled", func() {
var ccEndorsementInfo *lifecycle.ChaincodeEndorsementInfo

BeforeEach(func() {
ccEndorsementInfo = &lifecycle.ChaincodeEndorsementInfo{
Version: "legacy-version",
EndorsementPlugin: "legacy-plugin",
ChaincodeID: "legacy-id",
}
fakeCapabilities.LifecycleV20Returns(false)
fakeLegacyImpl.ChaincodeEndorsementInfoReturns(ccEndorsementInfo, nil)
})

It("returns the legacy chaincode info", func() {
res, err := cei.ChaincodeEndorsementInfo("channel-id", "cc-name", fakeQueryExecutor)
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(ccEndorsementInfo))
Expect(fakeLegacyImpl.ChaincodeEndorsementInfoCallCount()).To(Equal(1))
channelID, name, qe := fakeLegacyImpl.ChaincodeEndorsementInfoArgsForCall(0)
Expect(channelID).To(Equal("channel-id"))
Expect(name).To(Equal("cc-name"))
Expect(qe).To(Equal(fakeQueryExecutor))
})
})

Context("when channel config is not found", func() {
BeforeEach(func() {
fakeChannelConfigSource.GetStableChannelConfigReturns(nil)
})

It("returns not get channel config error", func() {
_, err := cei.ChaincodeEndorsementInfo("channel-id", "cc-name", fakeQueryExecutor)
Expect(err).To(MatchError("could not get channel config for channel 'channel-id'"))
})
})

Context("when application config is not found", func() {
BeforeEach(func() {
fakeChannelConfig.ApplicationConfigReturns(nil, false)
})

It("returns not get application config error", func() {
_, err := cei.ChaincodeEndorsementInfo("channel-id", "cc-name", fakeQueryExecutor)
Expect(err).To(MatchError("could not get application config for channel 'channel-id'"))
})
})
})
1 change: 0 additions & 1 deletion core/chaincode/lifecycle/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var _ = Describe("Integration", func() {
fakeApplicationConfig = &mock.ApplicationConfig{}
fakeChannelConfig.ApplicationConfigReturns(fakeApplicationConfig, true)
fakeCapabilities = &mock.ApplicationCapabilities{}
fakeCapabilities.LifecycleV20Returns(true)
fakeApplicationConfig.CapabilitiesReturns(fakeCapabilities)
fakeACLProvider = &mock.ACLProvider{}

Expand Down
Loading

0 comments on commit 5437abd

Please sign in to comment.