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 7ee74a6
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 1,653 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.

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

import (
"context"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -17,18 +16,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,27 +1,24 @@
package keeper
package internal

import (
"context"
"testing"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/stretchr/testify/suite"

"cosmossdk.io/core/address"
"cosmossdk.io/core/store"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttime "github.com/cometbft/cometbft/types/time"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
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/stretchr/testify/suite"

"github.com/Finschia/finschia-sdk/x/bankplus/types"
"cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestDeprecateTestSuite(t *testing.T) {
Expand All @@ -33,11 +30,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 +44,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 +60,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 +82,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
18 changes: 17 additions & 1 deletion simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ 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 +25,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 +46,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
)
Loading

0 comments on commit 7ee74a6

Please sign in to comment.