Skip to content

Commit

Permalink
refactor: off ics (#186)
Browse files Browse the repository at this point in the history
* refactor: off ics

* fix lint and update go.mod

* refactor golangci
  • Loading branch information
hoank101 authored Mar 26, 2024
1 parent 29359d7 commit 5d22450
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 393 deletions.
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ run:
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata
skip-files:
- server/grpc/gogoreflection/fix_registration.go
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.\\.go$"
- ".*\\.pulsar\\.go$"


linters:
disable-all: true
Expand Down
98 changes: 19 additions & 79 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ import (
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ccvconsumer "github.com/cosmos/interchain-security/v5/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types"
ccvdistr "github.com/cosmos/interchain-security/v5/x/ccv/democracy/distribution"
ccvgov "github.com/cosmos/interchain-security/v5/x/ccv/democracy/governance"
ccvstaking "github.com/cosmos/interchain-security/v5/x/ccv/democracy/staking"
"github.com/osmosis-labs/tokenfactory"
"github.com/osmosis-labs/tokenfactory/bindings"
tokenfactorykeeper "github.com/osmosis-labs/tokenfactory/keeper"
Expand Down Expand Up @@ -120,6 +114,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand All @@ -143,6 +138,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

Expand Down Expand Up @@ -188,15 +184,13 @@ var (

// module account permissions
var maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
ccvconsumertypes.ConsumerRedistributeName: nil,
ccvconsumertypes.ConsumerToSendToProviderName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
nft.ModuleName: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
nft.ModuleName: nil,
// non sdk modules
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
Expand Down Expand Up @@ -250,7 +244,6 @@ type EveApp struct {
TransferKeeper ibctransferkeeper.Keeper
Wasm08Keeper wasm08keeper.Keeper
WasmKeeper wasmkeeper.Keeper
ConsumerKeeper ccvconsumerkeeper.Keeper

IBCHooksKeeper ibchookskeeper.Keeper

Expand All @@ -259,7 +252,6 @@ type EveApp struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedCCVConsumerKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

TokenFactoryKeeper tokenfactorykeeper.Keeper
Expand Down Expand Up @@ -318,7 +310,6 @@ func NewEveApp(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey,
ccvconsumertypes.StoreKey,
circuittypes.StoreKey,
authzkeeper.StoreKey,
nftkeeper.StoreKey,
Expand Down Expand Up @@ -379,8 +370,6 @@ func NewEveApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
scopedCCVConsumerKeeper := app.CapabilityKeeper.ScopeToModule(ccvconsumertypes.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers

Expand Down Expand Up @@ -427,15 +416,15 @@ func NewEveApp(
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
ccvconsumertypes.ConsumerRedistributeName,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
runtime.NewKVStoreService(keys[slashingtypes.StoreKey]),
&app.ConsumerKeeper,
&app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -458,12 +447,6 @@ func NewEveApp(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
appCodec,
keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
)

app.CircuitKeeper = circuitkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[circuittypes.StoreKey]),
Expand Down Expand Up @@ -525,7 +508,7 @@ func NewEveApp(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
&app.ConsumerKeeper,
&app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand All @@ -540,16 +523,6 @@ func NewEveApp(
bApp.GRPCQueryRouter(),
)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
&app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
appCodec,
app.keys[tokenfactorytypes.StoreKey],
Expand Down Expand Up @@ -604,39 +577,14 @@ func NewEveApp(
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[evidencetypes.StoreKey]),
&app.ConsumerKeeper,
&app.StakingKeeper,
app.SlashingKeeper,
app.AccountKeeper.AddressCodec(),
runtime.ProvideCometInfoService(),
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

// Create CCV consumer and modules
app.ConsumerKeeper = ccvconsumerkeeper.NewKeeper(
appCodec,
keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
scopedCCVConsumerKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ClientKeeper,
app.SlashingKeeper,
app.BankKeeper,
app.AccountKeeper,
&app.TransferKeeper,
app.IBCKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
)
app.ConsumerKeeper.SetStandaloneStakingKeeper(app.StakingKeeper)
// register slashing module StakingHooks to the consumer keeper
app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks())

consumerModule := ccvconsumer.NewAppModule(app.ConsumerKeeper, app.GetSubspace(ccvconsumertypes.ModuleName))
// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
Expand Down Expand Up @@ -668,9 +616,7 @@ func NewEveApp(
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ccvconsumertypes.ModuleName, consumerModule)

AddRoute(icahosttypes.SubModuleName, icaHostStack)
app.IBCKeeper.SetRouter(ibcRouter)

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
Expand Down Expand Up @@ -771,12 +717,11 @@ func NewEveApp(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
ccvgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, IsProposalWhitelisted, app.GetSubspace(govtypes.ModuleName), IsModuleWhiteList),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry),
ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, app.GetSubspace(distrtypes.ModuleName)),

ccvstaking.NewAppModule(appCodec, &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
Expand All @@ -796,7 +741,6 @@ func NewEveApp(
ibctm.AppModule{},
// sdk
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them,
consumerModule,
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
)

Expand Down Expand Up @@ -839,7 +783,6 @@ func NewEveApp(
govtypes.ModuleName,
crisistypes.ModuleName,
// additional non simd modules
ccvconsumertypes.ModuleName,
capabilitytypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
Expand All @@ -859,7 +802,6 @@ func NewEveApp(
feegrant.ModuleName,
group.ModuleName,
// additional non simd modules
ccvconsumertypes.ModuleName,
capabilitytypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
Expand Down Expand Up @@ -903,7 +845,6 @@ func NewEveApp(
circuittypes.ModuleName,
ibcexported.ModuleName,
// additional non simd modules
ccvconsumertypes.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
Expand Down Expand Up @@ -984,7 +925,6 @@ func NewEveApp(
app.ScopedWasmKeeper = scopedWasmKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedCCVConsumerKeeper = scopedCCVConsumerKeeper

app.setPostHandler()

Expand Down Expand Up @@ -1014,6 +954,7 @@ func NewEveApp(
// if err := wasm08keeper.InitializePinnedCodes(ctx); err != nil {
// panic(fmt.Sprintf("failed initialize pinned codes %s", err))
// }
app.CapabilityKeeper.Seal()
}

return app
Expand Down Expand Up @@ -1304,6 +1245,5 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
paramsKeeper.Subspace(tokenfactorytypes.ModuleName).WithKeyTable(tokenfactorytypes.ParamKeyTable())
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(ccvconsumertypes.ModuleName)
return paramsKeeper
}
Loading

0 comments on commit 5d22450

Please sign in to comment.