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 bab18d6
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 1,648 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
2 changes: 0 additions & 2 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 Down Expand Up @@ -218,7 +217,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))
}
}
}
}
1 change: 0 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,4 @@ replace (

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
)
159 changes: 0 additions & 159 deletions x/bankplus/go.mod

This file was deleted.

Loading

0 comments on commit bab18d6

Please sign in to comment.