Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Jul 12, 2024
1 parent f042c74 commit caa96cd
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 136 deletions.
64 changes: 16 additions & 48 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server/api"
Expand All @@ -35,17 +34,11 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -63,8 +56,6 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
interchaintxstypes "github.com/neutron-org/neutron/v4/x/interchaintxs/types"

transferSudo "github.com/neutron-org/neutron/v4/x/transfer"
)

const (
Expand All @@ -90,6 +81,8 @@ func init() {
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+appparams.Name)

appparams.GetDefaultConfig()
}

// App extends an ABCI application, but with most of its parameters exported.
Expand All @@ -100,15 +93,13 @@ type App struct {
keepers.AppKeepers

cdc *codec.LegacyAmino
txConfig client.TxConfig
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
encodingConfig EncodingConfig
invCheckPeriod uint

// the module manager
mm *module.Manager
BasicModuleManager module.BasicManager
mm *module.Manager

// simulation manager
sm *module.SimulationManager
Expand All @@ -124,10 +115,13 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
encodingConfig := MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
Expand All @@ -137,17 +131,16 @@ func New(
app := &App{
BaseApp: bApp,
AppKeepers: keepers.AppKeepers{},
cdc: encodingConfig.Amino,
txConfig: encodingConfig.TxConfig,
appCodec: encodingConfig.Marshaler,
interfaceRegistry: encodingConfig.InterfaceRegistry,
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
encodingConfig: EncodingConfig(encodingConfig),
}

app.NewAppKeepers(
logger,
encodingConfig.Marshaler,
appCodec,
bApp,
encodingConfig.Amino,
encodingConfig.InterfaceRegistry,
Expand Down Expand Up @@ -185,27 +178,6 @@ func New(
// must be passed by reference here.
app.mm = module.NewManager(appModules(app, encodingConfig, skipGenesisInvariants)...)

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
// Additionally, app module basics can be overwritten by passing them as argument.
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
),
// TODO: Decide if neutron-transfer module should have a separate key
// Manually register the transfer module since we dont use a native ibc-go transfer module but a custom implementation
ibctransfertypes.ModuleName: transferSudo.AppModuleBasic{},
},
)
app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino)
app.BasicModuleManager.RegisterInterfaces(encodingConfig.InterfaceRegistry)

app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
)
Expand Down Expand Up @@ -440,9 +412,9 @@ func (app *App) AutoCliOpts() autocli.AppOptions {
return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules),
AddressCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

Expand Down Expand Up @@ -483,7 +455,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register new tendermint queries routes from grpc-gateway.
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register nodeservice grpc-gateway routes.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
Expand Down Expand Up @@ -515,7 +487,3 @@ func GetMaccPerms() map[string][]string {
func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

func (app *App) TxConfig() client.TxConfig {
return app.txConfig
}
9 changes: 4 additions & 5 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/gogoproto/proto"
)
Expand All @@ -24,7 +25,6 @@ type EncodingConfig struct {
// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func makeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
// signingOptions :=
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
Expand Down Expand Up @@ -56,12 +56,11 @@ func makeEncodingConfig() EncodingConfig {
}

// MakeEncodingConfig creates an EncodingConfig for testing.
func MakeEncodingConfig() EncodingConfig {
func MakeEncodingConfig(moduleBasics module.BasicManager) EncodingConfig {
encodingConfig := makeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
moduleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
moduleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}

// EncodingConfig returns the encoding config of the App.
func (app *App) EncodingConfig() EncodingConfig { return app.encodingConfig }
4 changes: 2 additions & 2 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import (
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func (a *App) NewDefaultGenesisState(encConfig EncodingConfig) GenesisState {
return a.BasicModuleManager.DefaultGenesis(encConfig.Marshaler)
func NewDefaultGenesisState(encConfig EncodingConfig) GenesisState {
return ModuleBasics.DefaultGenesis(encConfig.Marshaler)
}
81 changes: 46 additions & 35 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
Expand All @@ -27,34 +28,44 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
sdkparams "github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/cosmos/ibc-go/modules/capability"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/Nolus-Protocol/nolus-core/x/mint"
minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types"
"github.com/Nolus-Protocol/nolus-core/x/tax"
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
"github.com/Nolus-Protocol/nolus-core/x/vestings"
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/neutron-org/neutron/v4/x/contractmanager"
contractmanagermoduletypes "github.com/neutron-org/neutron/v4/x/contractmanager/types"
"github.com/neutron-org/neutron/v4/x/feerefunder"
feetypes "github.com/neutron-org/neutron/v4/x/feerefunder/types"
"github.com/neutron-org/neutron/v4/x/interchainqueries"
interchainqueriestypes "github.com/neutron-org/neutron/v4/x/interchainqueries/types"
"github.com/neutron-org/neutron/v4/x/interchaintxs"
interchaintxstypes "github.com/neutron-org/neutron/v4/x/interchaintxs/types"
transferSudo "github.com/neutron-org/neutron/v4/x/transfer"
)

// module account permissions.
Expand All @@ -76,40 +87,40 @@ var maccPerms = map[string][]string{
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
// var ModuleBasics = module.NewBasicManager(
// genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
// auth.AppModuleBasic{},
// bank.AppModuleBasic{},
// capability.AppModuleBasic{},
// staking.AppModuleBasic{},
// mint.AppModuleBasic{},
// distribution.AppModuleBasic{},
// gov.NewAppModuleBasic(
// []govclient.ProposalHandler{
// paramsclient.ProposalHandler,
// },
// ),
// sdkparams.AppModuleBasic{},
// crisis.AppModuleBasic{},
// slashing.AppModuleBasic{},
// feegrantmodule.AppModuleBasic{},
// ibc.AppModuleBasic{},
// upgrade.AppModuleBasic{},
// evidence.AppModuleBasic{},
// transferSudo.AppModuleBasic{},
// vesting.AppModuleBasic{},
// wasm.AppModuleBasic{},
// vestings.AppModuleBasic{},
// tax.AppModuleBasic{},
// ica.AppModuleBasic{},
// interchaintxs.AppModuleBasic{},
// interchainqueries.AppModuleBasic{},
// feerefunder.AppModuleBasic{},
// contractmanager.AppModuleBasic{},
// authzmodule.AppModuleBasic{},
// consensus.AppModuleBasic{},
// ibctm.AppModuleBasic{},
// )
var ModuleBasics = module.NewBasicManager(
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
auth.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distribution.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
),
sdkparams.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transferSudo.AppModuleBasic{},
vesting.AppModuleBasic{},
wasm.AppModuleBasic{},
vestings.AppModuleBasic{},
tax.AppModuleBasic{},
ica.AppModuleBasic{},
interchaintxs.AppModuleBasic{},
interchainqueries.AppModuleBasic{},
feerefunder.AppModuleBasic{},
contractmanager.AppModuleBasic{},
authzmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
ibctm.AppModuleBasic{},
)

func appModules(
app *App,
Expand Down
11 changes: 7 additions & 4 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
encConfig := MakeEncodingConfig()
encConfig := MakeEncodingConfig(ModuleBasics)
newApp := New(
logger,
db,
Expand All @@ -139,6 +139,7 @@ func TestAppStateDeterminism(t *testing.T) {
map[int64]bool{},
DefaultNodeHome,
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
Expand All @@ -154,7 +155,7 @@ func TestAppStateDeterminism(t *testing.T) {
t,
os.Stdout,
newApp.BaseApp,
simtestutil.AppStateFn(newApp.AppCodec(), newApp.SimulationManager(), newApp.NewDefaultGenesisState(encConfig)),
simtestutil.AppStateFn(newApp.AppCodec(), newApp.SimulationManager(), NewDefaultGenesisState(encConfig)),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simtestutil.SimulationOperations(newApp, newApp.AppCodec(), config),
newApp.BlockedAddrs(),
Expand Down Expand Up @@ -197,7 +198,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

encConf := MakeEncodingConfig()
encConfig := MakeEncodingConfig(ModuleBasics)
nolusApp := New(
logger,
db,
Expand All @@ -206,6 +207,7 @@ func TestAppImportExport(t *testing.T) {
map[int64]bool{},
dir,
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
Expand All @@ -217,7 +219,7 @@ func TestAppImportExport(t *testing.T) {
t,
os.Stdout,
nolusApp.BaseApp,
simtestutil.AppStateFn(nolusApp.AppCodec(), nolusApp.SimulationManager(), nolusApp.NewDefaultGenesisState(encConf)),
simtestutil.AppStateFn(nolusApp.AppCodec(), nolusApp.SimulationManager(), NewDefaultGenesisState(encConfig)),
simtypes.RandomAccounts,
simtestutil.SimulationOperations(nolusApp, nolusApp.AppCodec(), config),
nolusApp.ModuleAccountAddrs(),
Expand Down Expand Up @@ -256,6 +258,7 @@ func TestAppImportExport(t *testing.T) {
map[int64]bool{},
DefaultNodeHome,
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
Expand Down
Loading

0 comments on commit caa96cd

Please sign in to comment.