Skip to content

Commit

Permalink
chore: deprecate x/bankplus by moving deprecation logic to simapp
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Mar 19, 2024
1 parent e1ba3f4 commit 503ac51
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 1,644 deletions.
14 changes: 0 additions & 14 deletions proto/lbm/bankplus/v1/bankplus.proto

This file was deleted.

2 changes: 1 addition & 1 deletion simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
_ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
Expand All @@ -74,7 +75,6 @@ import (

collectionmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/collection/module/v1"
foundationmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/foundation/module/v1"
_ "github.com/Finschia/finschia-sdk/x/bankplus/module" // import for side-effects
"github.com/Finschia/finschia-sdk/x/collection"
_ "github.com/Finschia/finschia-sdk/x/collection/module" // import for side-effects
"github.com/Finschia/finschia-sdk/x/foundation"
Expand Down
5 changes: 2 additions & 3 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
cosmossdk.io/x/upgrade v0.1.1
github.com/Finschia/finschia-sdk/api v0.0.0-20231227090232-78fde403b78c
github.com/Finschia/finschia-sdk/x/collection v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/bankplus v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.38.3
github.com/cosmos/cosmos-db v1.0.0
Expand All @@ -33,6 +32,8 @@ require (
google.golang.org/protobuf v1.32.0
)

require github.com/gogo/protobuf v1.3.2

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
Expand Down Expand Up @@ -94,7 +95,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down Expand Up @@ -218,7 +218,6 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Simapp always use the latest version of the finschia-sdk
github.com/Finschia/finschia-sdk/api => ../api
github.com/Finschia/finschia-sdk/x/bankplus => ../x/bankplus
github.com/Finschia/finschia-sdk/x/collection => ../x/collection
github.com/Finschia/finschia-sdk/x/foundation => ../x/foundation
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions x/bankplus/keeper/deprecator.go → simapp/internal/deprecator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keeper
package internal

import (
"context"
Expand All @@ -17,18 +17,17 @@ func inactiveAddrKey(addr sdk.AccAddress) []byte {
return append(inactiveAddrsKeyPrefix, addr.Bytes()...)
}

// DeprecateBankPlus performs in-place store migrations for bankplus v1
// migration includes:
//
// - Remove all the state(inactive addresses)
func DeprecateBankPlus(ctx context.Context, keeper BaseKeeper) error {
kvStore := keeper.storeService.OpenKVStore(ctx)
adapter := runtime.KVStoreAdapter(kvStore)
iterator := storetypes.KVStorePrefixIterator(adapter, inactiveAddrsKeyPrefix)
defer iterator.Close()
// DeprecateBankPlus performs remove logic for bankplus v1.
// This will remove all the state(inactive addresses)
func DeprecateBankPlus(ctx context.Context, bankKey *storetypes.KVStoreKey) error {
kss := runtime.NewKVStoreService(bankKey)
ks := kss.OpenKVStore(ctx)
adapter := runtime.KVStoreAdapter(ks)
iter := storetypes.KVStorePrefixIterator(adapter, inactiveAddrsKeyPrefix)
defer iter.Close()

for ; iterator.Valid(); iterator.Next() {
err := kvStore.Delete(iterator.Key())
for ; iter.Valid(); iter.Next() {
err := ks.Delete(iter.Key())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keeper
package internal

import (
"context"
Expand All @@ -20,8 +20,6 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/Finschia/finschia-sdk/x/bankplus/types"
)

func TestDeprecateTestSuite(t *testing.T) {
Expand All @@ -33,11 +31,12 @@ type DeprecationTestSuite struct {
ctx sdk.Context
cdc codec.Codec
storeService store.KVStoreService
key *storetypes.KVStoreKey
}

func (s *DeprecationTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(banktypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
s.key = storetypes.NewKVStoreKey(banktypes.StoreKey)
testCtx := testutil.DefaultContextWithDB(s.T(), s.key, storetypes.NewTransientStoreKey("transient_test"))
s.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
encCfg := moduletestutil.MakeTestEncodingConfig()
encCfg.Codec = codectestutil.CodecOptions{
Expand All @@ -46,7 +45,7 @@ func (s *DeprecationTestSuite) SetupTest() {
}.NewCodec()
s.cdc = encCfg.Codec

storeService := runtime.NewKVStoreService(key)
storeService := runtime.NewKVStoreService(s.key)
s.storeService = storeService
}

Expand All @@ -62,7 +61,7 @@ func (s *DeprecationTestSuite) TestDeprecateBankPlus() {
s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress()))
s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, anotherOldAcc.GetAddress()))

err := DeprecateBankPlus(s.ctx, BaseKeeper{storeService: s.storeService})
err := DeprecateBankPlus(s.ctx, s.key)

s.Require().NoError(err)
s.Require().False(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress()))
Expand All @@ -84,7 +83,7 @@ func addToInactiveAddr(ctx context.Context, storeService store.KVStoreService, c
panic(err)
}

blockedCAddr := types.InactiveAddr{Address: addrString}
blockedCAddr := InactiveAddr{Address: addrString}
bz := cdc.MustMarshal(&blockedCAddr)
if err := kvStore.Set(inactiveAddrKey(address), bz); err != nil {
panic(err)
Expand Down
17 changes: 17 additions & 0 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package simapp

import (
"context"
"fmt"

storetypes "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/types/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/Finschia/finschia-sdk/simapp/internal"
)

// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
Expand All @@ -22,6 +26,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.deprecateBankPlusFromSimapp(ctx)
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)
Expand All @@ -42,3 +47,15 @@ func (app SimApp) RegisterUpgradeHandlers() {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// deprecateBankPlusFromSimapp remove all the states of x/bankplus module for deprecation
func (app SimApp) deprecateBankPlusFromSimapp(ctx context.Context) {
for _, key := range app.kvStoreKeys() {
if key.Name() == banktypes.StoreKey {
err := internal.DeprecateBankPlus(ctx, key)
if err != nil {
panic(fmt.Errorf("failed to deprecate x/bankplus: %w", err))
}
}
}
}
8 changes: 3 additions & 5 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ require (
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Finschia/finschia-sdk/api v0.0.0-20231227090232-78fde403b78c // indirect
github.com/Finschia/finschia-sdk/x/bankplus v0.0.0-00010101000000-000000000000 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
Expand Down Expand Up @@ -227,10 +226,9 @@ replace (
)

replace (
github.com/cometbft/cometbft => github.com/Finschia/cometbft v0.0.0-20231127181424-2aacfbe9832d
github.com/cosmos/cosmos-sdk => github.com/Finschia/cosmos-sdk v0.0.0-20231211060251-d8fb76d4c267
github.com/Finschia/finschia-sdk/x/collection => ./../x/collection

github.com/Finschia/finschia-sdk/x/foundation => ./../x/foundation
github.com/Finschia/finschia-sdk/x/collection => ./../x/collection
github.com/Finschia/finschia-sdk/x/bankplus => ../x/bankplus
github.com/cometbft/cometbft => github.com/Finschia/cometbft v0.0.0-20231127181424-2aacfbe9832d
github.com/cosmos/cosmos-sdk => github.com/Finschia/cosmos-sdk v0.0.0-20231211060251-d8fb76d4c267
)
159 changes: 0 additions & 159 deletions x/bankplus/go.mod

This file was deleted.

Loading

0 comments on commit 503ac51

Please sign in to comment.