Skip to content

Commit

Permalink
Final code cleanup and revision.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshutr committed Apr 17, 2022
1 parent b6e05f9 commit 5b2b0dc
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint
# Lint runs golangci-lint over the entire Gaia repository
# Lint runs golangci-lint over the entire repository
# This workflow is run on every pull request and push to master
# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified.
on:
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ifeq ($(LEDGER_ENABLED),true)
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(GAIA_BUILD_OPTIONS)))
ifeq (cleveldb,$(findstring cleveldb,$(APP_BUILD_OPTIONS)))
build_tags += gcc cleveldb
endif
build_tags += $(BUILD_TAGS)
Expand All @@ -67,18 +67,18 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=AssetMantle \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(GAIA_BUILD_OPTIONS)))
ifeq (cleveldb,$(findstring cleveldb,$(APP_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq (,$(findstring nostrip,$(GAIA_BUILD_OPTIONS)))
ifeq (,$(findstring nostrip,$(APP_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(GAIA_BUILD_OPTIONS)))
ifeq (,$(findstring nostrip,$(APP_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

Expand Down Expand Up @@ -122,9 +122,9 @@ lint:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs goimports -w -local github.com/cosmos/cosmos-sdk

.PHONY: all build-linux install format lint \
go-mod-cache clean build
82 changes: 31 additions & 51 deletions application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"fmt"
"io"
stdLog "log"
"net/http"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -93,8 +91,6 @@ import (
portTypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibcHost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibcKeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"github.com/strangelove-ventures/packet-forward-middleware/v2/router"
routerKeeper "github.com/strangelove-ventures/packet-forward-middleware/v2/router/keeper"
Expand All @@ -109,7 +105,7 @@ import (
)

var (
// DefaultNodeHome default home directories for the application daemon
// DefaultNodeHome default home directories for the application daemon.
DefaultNodeHome string

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -158,14 +154,14 @@ var (
)

var (
_ simapp.App = (*GaiaApp)(nil)
_ serverTypes.Application = (*GaiaApp)(nil)
_ simapp.App = (*App)(nil)
_ serverTypes.Application = (*App)(nil)
)

// GaiaApp extends an ABCI application, but with most of its parameters exported.
// App extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type GaiaApp struct { // nolint: golint
type App struct { // nolint: golint
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
Expand Down Expand Up @@ -221,8 +217,8 @@ func init() {
DefaultNodeHome = filepath.Join(userHomeDir, ".mantleNode")
}

// NewGaiaApp returns a reference to an initialized Gaia.
func NewGaiaApp(
// NewApp returns a reference to an initialized application.
func NewApp(
logger log.Logger,
db dbm.DB, traceStore io.Writer,
loadLatest bool,
Expand All @@ -232,8 +228,7 @@ func NewGaiaApp(
encodingConfig applicationParameters.EncodingConfig,
appOpts serverTypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *GaiaApp {

) *App {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -253,7 +248,7 @@ func NewGaiaApp(
transientStoreKeys := sdk.NewTransientStoreKeys(paramsTypes.TStoreKey)
memoryStoreKeys := sdk.NewMemoryStoreKeys(capabilityTypes.MemStoreKey)

app := &GaiaApp{
app := &App{
BaseApp: bApp,
legacyAmino: legacyAmino,
appCodec: appCodec,
Expand Down Expand Up @@ -674,20 +669,20 @@ func NewGaiaApp(
}

// Name returns the name of the App
func (app *GaiaApp) Name() string { return app.BaseApp.Name() }
func (app *App) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
func (app *App) BeginBlocker(ctx sdk.Context, req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}

// EndBlocker application updates every end block
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abciTypes.RequestEndBlock) abciTypes.ResponseEndBlock {
func (app *App) EndBlocker(ctx sdk.Context, req abciTypes.RequestEndBlock) abciTypes.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}

// InitChainer application update at chain initialization
func (app *GaiaApp) InitChainer(ctx sdk.Context, req abciTypes.RequestInitChain) abciTypes.ResponseInitChain {
func (app *App) InitChainer(ctx sdk.Context, req abciTypes.RequestInitChain) abciTypes.ResponseInitChain {
var genesisState GenesisState
if err := tendermintJSON.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
Expand All @@ -699,12 +694,12 @@ func (app *GaiaApp) InitChainer(ctx sdk.Context, req abciTypes.RequestInitChain)
}

// LoadHeight loads a particular height
func (app *GaiaApp) LoadHeight(height int64) error {
func (app *App) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// ModuleAccountAddrs returns all the application's module account addresses.
func (app *GaiaApp) ModuleAccountAddrs() map[string]bool {
func (app *App) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range moduleAccountPermissions {
modAccAddrs[authTypes.NewModuleAddress(acc).String()] = true
Expand All @@ -713,64 +708,64 @@ func (app *GaiaApp) ModuleAccountAddrs() map[string]bool {
return modAccAddrs
}

// LegacyAmino returns GaiaApp's amino codec.
// LegacyAmino returns App's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *GaiaApp) LegacyAmino() *codec.LegacyAmino {
func (app *App) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

// AppCodec returns Gaia's application codec.
// AppCodec returns application codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *GaiaApp) AppCodec() codec.Codec {
func (app *App) AppCodec() codec.Codec {
return app.appCodec
}

// InterfaceRegistry returns Gaia's InterfaceRegistry
func (app *GaiaApp) InterfaceRegistry() types.InterfaceRegistry {
// InterfaceRegistry returns InterfaceRegistry
func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *GaiaApp) GetKey(storeKey string) *sdk.KVStoreKey {
func (app *App) GetKey(storeKey string) *sdk.KVStoreKey {
return app.storeKeys[storeKey]
}

// GetTKey returns the TransientStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *GaiaApp) GetTKey(storeKey string) *sdk.TransientStoreKey {
func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey {
return app.transientStoreKeys[storeKey]
}

// GetMemKey returns the MemStoreKey for the provided mem key.
//
// NOTE: This is solely used for testing purposes.
func (app *GaiaApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
return app.memoryStoreKeys[storeKey]
}

// GetSubspace returns a param subspace for a given module name.
//
// NOTE: This is solely to be used for testing purposes.
func (app *GaiaApp) GetSubspace(moduleName string) paramsTypes.Subspace {
func (app *App) GetSubspace(moduleName string) paramsTypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}

// SimulationManager implements the SimulationApp interface
func (app *GaiaApp) SimulationManager() *module.SimulationManager {
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *GaiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
clientCtx := apiSvr.ClientCtx
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
// Register legacy tx routes.
Expand All @@ -784,33 +779,18 @@ func (app *GaiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(apiSvr.Router)
}
}

// RegisterTxService implements the Application.RegisterTxService method.
func (app *GaiaApp) RegisterTxService(clientCtx client.Context) {
// RegisterTxService implements the App.RegisterTxService method.
func (app *App) RegisterTxService(clientCtx client.Context) {
authTx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *GaiaApp) RegisterTendermintService(clientCtx client.Context) {
// RegisterTendermintService implements the App.RegisterTendermintService method.
func (app *App) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
panic(err)
}

staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, storeKey, transientStoreKey sdk.StoreKey) paramsKeeper.Keeper {
ParamsKeeper := paramsKeeper.NewKeeper(appCodec, legacyAmino, storeKey, transientStoreKey)
Expand Down
6 changes: 1 addition & 5 deletions application/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package application

const (
appName = "mantleNode"
upgradeName = "v7-Theta"
upgradeName = "v0.3.0"

authzMsgExec = "/cosmos.authz.v1beta1.MsgExec"
authzMsgGrant = "/cosmos.authz.v1beta1.MsgGrant"
Expand All @@ -26,8 +26,4 @@ const (
stakingMsgCreateValidator = "/cosmos.staking.v1beta1.MsgCreateValidator"
vestingMsgCreateVestingAccount = "/cosmos.vesting.v1beta1.MsgCreateVestingAccount"
transferMsgTransfer = "/ibc.applications.transfer.v1.MsgTransfer"
liquidityMsgCreatePool = "/tendermint.liquidity.v1beta1.MsgCreatePool"
liquidityMsgSwapWithinBatch = "/tendermint.liquidity.v1beta1.MsgSwapWithinBatch"
liquidityMsgDepositWithinBatch = "/tendermint.liquidity.v1beta1.MsgDepositWithinBatch"
liquidityMsgWithdrawWithinBatch = "/tendermint.liquidity.v1beta1.MsgWithdrawWithinBatch"
)
4 changes: 2 additions & 2 deletions application/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *GaiaApp) ExportAppStateAndValidators(
func (app *App) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
) (serverTypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
Expand Down Expand Up @@ -46,7 +46,7 @@ func (app *GaiaApp) ExportAppStateAndValidators(
// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

// check if there is an allowed address list
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package helpers

// SimAppChainID hardcoded chainID for simulation
const (
SimAppChainID = "gaia-application"
SimAppChainID = "sim-application"
)
6 changes: 3 additions & 3 deletions application/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
}

// Profile with:
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/GaiaApp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/App -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
if err != nil {
Expand All @@ -46,7 +46,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
}()

app := application.NewGaiaApp(logger, db, nil, true, map[int64]bool{}, application.DefaultNodeHome, simapp.FlagPeriodValue, application.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())
app := application.NewApp(logger, db, nil, true, map[int64]bool{}, application.DefaultNodeHome, simapp.FlagPeriodValue, application.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())

// Run randomized simulation:w
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := application.NewGaiaApp(logger, db, nil, true, map[int64]bool{}, application.DefaultNodeHome, simapp.FlagPeriodValue, application.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())
app := application.NewApp(logger, db, nil, true, map[int64]bool{}, application.DefaultNodeHome, simapp.FlagPeriodValue, application.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ go 1.17
require (
github.com/cosmos/cosmos-sdk v0.45.1
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/gorilla/mux v1.8.0
github.com/gravity-devs/liquidity v1.5.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.3.0
github.com/strangelove-ventures/packet-forward-middleware/v2 v2.1.1
Expand Down Expand Up @@ -47,6 +44,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
Expand All @@ -55,10 +53,10 @@ require (
github.com/google/btree v1.0.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.1 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down Expand Up @@ -89,6 +87,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.29.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.7.0 // indirect
Expand Down
Loading

0 comments on commit 5b2b0dc

Please sign in to comment.