Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions protocol/app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
sending "github.com/dydxprotocol/v4-chain/protocol/x/sending/types"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/store/cachemulti"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

memiavlcachemulti "github.com/crypto-org-chain/cronos/store/cachemulti"
customante "github.com/dydxprotocol/v4-chain/protocol/app/ante"
"github.com/dydxprotocol/v4-chain/protocol/lib"
libante "github.com/dydxprotocol/v4-chain/protocol/lib/ante"
Expand Down Expand Up @@ -249,7 +249,7 @@ func (h *lockingAnteHandler) clobAnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
return ctx, err
}

cacheMs = ctx.MultiStore().(cachemulti.Store).CacheMultiStoreWithLocking(map[storetypes.StoreKey][][]byte{
cacheMs = ctx.MultiStore().(memiavlcachemulti.Store).CacheMultiStoreWithLocking(map[storetypes.StoreKey][][]byte{
h.authStoreKey: signers,
})
defer cacheMs.(storetypes.LockingStore).Unlock()
Expand Down Expand Up @@ -407,7 +407,7 @@ func (h *lockingAnteHandler) otherMsgAnteHandle(ctx sdk.Context, tx sdk.Tx, simu
return ctx, err
}

cacheMs = ctx.MultiStore().(cachemulti.Store).CacheMultiStoreWithLocking(map[storetypes.StoreKey][][]byte{
cacheMs = ctx.MultiStore().(memiavlcachemulti.Store).CacheMultiStoreWithLocking(map[storetypes.StoreKey][][]byte{
h.authStoreKey: signers,
})
defer cacheMs.(storetypes.LockingStore).Unlock()
Expand Down
22 changes: 20 additions & 2 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"math/big"
Expand Down Expand Up @@ -91,6 +92,8 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
memiavlstore "github.com/crypto-org-chain/cronos/store"
memiavlrootmulti "github.com/crypto-org-chain/cronos/store/rootmulti"
antetypes "github.com/dydxprotocol/v4-chain/protocol/app/ante/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -412,6 +415,16 @@ func New(
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

// Conditionally enable MemIAVL
cacheSize := cast.ToInt(appOpts.Get(memiavlstore.FlagCacheSize))
homePath := cast.ToString(appOpts.Get(cosmosflags.FlagHome))
if cast.ToBool(appOpts.Get(memiavlstore.FlagMemIAVL)) {
logger.Info("********************MemIAVL enabled *************************", "cacheSize", cacheSize)
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, cacheSize, baseAppOptions)
} else {
logger.Info("****************** MemIAVL disabled; using standard IAVL")
}

// Enable optimistic block execution.
if appFlags.OptimisticExecutionEnabled {
logger.Info("optimistic execution is enabled.")
Expand All @@ -429,6 +442,9 @@ func New(
}

bApp := baseapp.NewBaseApp(appconstants.AppName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
logger.Info("DEBUG store type",
"cmsType", fmt.Sprintf("%T", bApp.CommitMultiStore()),
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down Expand Up @@ -620,7 +636,6 @@ func New(
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
homePath := cast.ToString(appOpts.Get(cosmosflags.FlagHome))
// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
Expand Down Expand Up @@ -2023,10 +2038,13 @@ func (app *App) setAnteHandler(txConfig client.TxConfig) {

// Close invokes an ordered shutdown of routines.
func (app *App) Close() error {
app.BaseApp.Close()
err := app.BaseApp.Close()
if app.oraclePrometheusServer != nil {
app.oraclePrometheusServer.Close()
}
if cms, ok := app.CommitMultiStore().(*memiavlrootmulti.Store); ok {
return errors.Join(err, cms.Close())
}
return app.closeOnce()
}

Expand Down
15 changes: 14 additions & 1 deletion protocol/cmd/dydxprotocold/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
oracleconfig "github.com/dydxprotocol/slinky/oracle/config"
assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"

// MemIAVL config
memiavlcfg "github.com/crypto-org-chain/cronos/store/config"
)

const (
Expand All @@ -26,6 +29,10 @@ const (
// DydxAppConfig specifies dYdX app specific config.
type DydxAppConfig struct {
serverconfig.Config

// MemIAVL section in app.toml: [memiavl]
MemIAVL memiavlcfg.MemIAVLConfig `mapstructure:"memiavl"`

Oracle oracleconfig.AppConfig `mapstructure:"oracle"`
}

Expand All @@ -34,6 +41,7 @@ type DydxAppConfig struct {
// initAppConfig helps to override default appConfig template and configs.
// return "", nil if no custom configuration is required for the application.
func initAppConfig() (string, *DydxAppConfig) {

// Optionally allow the chain developer to overwrite the SDK's default
// server config.
srvCfg := serverconfig.DefaultConfig()
Expand All @@ -54,6 +62,8 @@ func initAppConfig() (string, *DydxAppConfig) {

appConfig := DydxAppConfig{
Config: *srvCfg,
// Default MemIAVL config (disabled by default; enable via app.toml)
MemIAVL: memiavlcfg.DefaultMemIAVLConfig(),
Oracle: oracleconfig.AppConfig{
Enabled: true,
OracleAddress: "localhost:8080",
Expand All @@ -73,7 +83,10 @@ func initAppConfig() (string, *DydxAppConfig) {
// GRPC.
appConfig.GRPC.Address = "0.0.0.0:9090"

appTemplate := serverconfig.DefaultConfigTemplate + oracleconfig.DefaultConfigTemplate
// Include MemIAVL config template so it shows up in app.toml
appTemplate := serverconfig.DefaultConfigTemplate +
oracleconfig.DefaultConfigTemplate +
memiavlcfg.DefaultConfigTemplate

return appTemplate, &appConfig
}
Expand Down
8 changes: 6 additions & 2 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
Expand Down Expand Up @@ -209,13 +210,16 @@ func initRootCmd(
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
confixcmd.ConfigCommand(),
snapshot.Cmd(newApp),
)

server.AddCommands(
rootCmd,
dydxapp.DefaultNodeHome,
func(logger log.Logger, db dbm.DB, writer io.Writer, options servertypes.AppOptions) servertypes.Application {
return appInterceptor(newApp(logger, db, writer, options))
//TODO: cleanup app appInterceptor
app := newApp(logger, db, writer, options)
return appInterceptor(app.(*dydxapp.App))
},
appExport,
func(cmd *cobra.Command) {
Expand Down Expand Up @@ -351,7 +355,7 @@ func newApp(
db dbm.DB,
traceStore io.Writer,
appOpts servertypes.AppOptions,
) *dydxapp.App {
) servertypes.Application {
var cache storetypes.MultiStorePersistentCache

if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
Expand Down
Loading