Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create db for kvindexer in AppCreator #50

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ type MinitiaApp struct {
func NewMinitiaApp(
logger log.Logger,
db dbm.DB,
kvindexerDB dbm.DB,
traceStore io.Writer,
loadLatest bool,
moveConfig moveconfig.MoveConfig,
Expand Down Expand Up @@ -770,7 +771,7 @@ func NewMinitiaApp(
marketmap.NewAppModule(appCodec, app.MarketMapKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
if err := app.setupIndexer(appOpts, kvindexerDB, ac, vc, appCodec); err != nil {
panic(err)
}

Expand Down Expand Up @@ -1267,7 +1268,7 @@ func (app *MinitiaApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
func (app *MinitiaApp) TxConfig() client.TxConfig {
return app.txConfig
}
func (app *MinitiaApp) setupIndexer(appOpts servertypes.AppOptions, homePath string, ac, vc address.Codec, appCodec codec.Codec) error {
func (app *MinitiaApp) setupIndexer(appOpts servertypes.AppOptions, kvindexerDB dbm.DB, ac, vc address.Codec, appCodec codec.Codec) error {
// initialize the indexer fake-keeper
indexerConfig, err := indexerconfig.NewConfig(appOpts)
if err != nil {
Expand All @@ -1276,7 +1277,7 @@ func (app *MinitiaApp) setupIndexer(appOpts servertypes.AppOptions, homePath str
app.indexerKeeper = indexerkeeper.NewKeeper(
appCodec,
"move",
homePath,
kvindexerDB,
indexerConfig,
ac,
vc,
Expand Down
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewLogger(os.Stdout)
app := NewMinitiaApp(
logger, db, nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
logger, db, dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestGetKey(t *testing.T) {
db := dbm.NewMemDB()
app := NewMinitiaApp(
log.NewLogger(os.Stdout),
db, nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
db, dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
require.NotEmpty(t, app.GetMemKey(capabilitytypes.MemStoreKey))
Expand Down
7 changes: 4 additions & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
db "github.com/cosmos/cosmos-db"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client/flags"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
Expand All @@ -16,7 +17,7 @@
)

func MakeEncodingConfig() params.EncodingConfig {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), db.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Codec: tempApp.AppCodec(),
Expand All @@ -28,7 +29,7 @@
}

func AutoCliOpts() autocli.AppOptions {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), db.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})

Check warning on line 32 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L32

Added line #L32 was not covered by tests
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range tempApp.ModuleManager.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
Expand All @@ -49,7 +50,7 @@
}

func BasicManager() module.BasicManager {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), EmptyAppOptions{})

Check warning on line 53 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L53

Added line #L53 was not covered by tests
return tempApp.BasicModuleManager
}

Expand Down
1 change: 1 addition & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func setup(db *dbm.DB, withGenesis bool) (*MinitiaApp, GenesisState) {
app := NewMinitiaApp(
log.NewNopLogger(),
getOrCreateMemDB(db),
getOrCreateMemDB(nil),
nil,
true,
moveconfig.DefaultMoveConfig(),
Expand Down
37 changes: 34 additions & 3 deletions cmd/minitiad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"io"
"os"
"path"
"path/filepath"

"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -41,6 +43,9 @@
minitiaapp "github.com/initia-labs/minimove/app"

opchildcli "github.com/initia-labs/OPinit/x/opchild/client/cli"
kvindexerconfig "github.com/initia-labs/kvindexer/config"
kvindexerstore "github.com/initia-labs/kvindexer/store"
kvindexerkeeper "github.com/initia-labs/kvindexer/x/kvindexer/keeper"
)

// NewRootCmd creates a new root command for initiad. It is called once in the
Expand Down Expand Up @@ -260,8 +265,14 @@
return func(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
baseappOptions := server.DefaultBaseappOptions(appOpts)

dbDir, kvdbConfig := getDBConfig(appOpts)
kvindexerDB, err := kvindexerstore.OpenDB(dbDir, kvindexerkeeper.StoreName, kvdbConfig.BackendConfig)
if err != nil {
panic(err)

Check warning on line 271 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L268-L271

Added lines #L268 - L271 were not covered by tests
}

app := minitiaapp.NewMinitiaApp(
logger, db, traceStore, true,
logger, db, kvindexerDB, traceStore, true,

Check warning on line 275 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L275

Added line #L275 was not covered by tests
moveconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
Expand Down Expand Up @@ -296,13 +307,13 @@

var initiaApp *minitiaapp.MinitiaApp
if height != -1 {
initiaApp = minitiaapp.NewMinitiaApp(logger, db, traceStore, false, moveconfig.DefaultMoveConfig(), appOpts)
initiaApp = minitiaapp.NewMinitiaApp(logger, db, dbm.NewMemDB(), traceStore, false, moveconfig.DefaultMoveConfig(), appOpts)

Check warning on line 310 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L310

Added line #L310 was not covered by tests

if err := initiaApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
initiaApp = minitiaapp.NewMinitiaApp(logger, db, traceStore, true, moveconfig.DefaultMoveConfig(), appOpts)
initiaApp = minitiaapp.NewMinitiaApp(logger, db, dbm.NewMemDB(), traceStore, true, moveconfig.DefaultMoveConfig(), appOpts)

Check warning on line 316 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L316

Added line #L316 was not covered by tests
}

return initiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down Expand Up @@ -351,3 +362,23 @@

return clientCtx, nil
}

// getDBConfig returns the database configuration for the EVM indexer
func getDBConfig(appOpts servertypes.AppOptions) (string, *kvindexerconfig.IndexerConfig) {
rootDir := cast.ToString(appOpts.Get("home"))
dbDir := cast.ToString(appOpts.Get("db_dir"))
dbBackend, err := kvindexerconfig.NewConfig(appOpts)
if err != nil {
panic(err)

Check warning on line 372 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L367-L372

Added lines #L367 - L372 were not covered by tests
}

return rootify(dbDir, rootDir), dbBackend

Check warning on line 375 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L375

Added line #L375 was not covered by tests
}

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
if filepath.IsAbs(path) {
return path
}
return filepath.Join(root, path)

Check warning on line 383 in cmd/minitiad/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/minitiad/root.go#L379-L383

Added lines #L379 - L383 were not covered by tests
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/initia-labs/OPinit v0.3.2
github.com/initia-labs/initia v0.3.4
github.com/initia-labs/kvindexer v0.1.3
github.com/initia-labs/kvindexer v0.1.5
github.com/initia-labs/kvindexer/submodules/block v0.1.0
github.com/initia-labs/kvindexer/submodules/move-nft v0.1.3
github.com/initia-labs/kvindexer/submodules/pair v0.1.1
Expand Down Expand Up @@ -63,6 +63,7 @@ require (
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/IGLOU-EU/go-wildcard v1.0.3 // indirect
github.com/allegro/bigcache/v3 v3.1.0 // indirect
github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.44.312 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk=
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down Expand Up @@ -800,8 +802,8 @@ github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c h1:FDwh5zZbm
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/initia-labs/initia v0.3.4 h1:i2fwTx9WDwGp2nyX64r6jtdtgfJmRqKAXGdxbHBRg9s=
github.com/initia-labs/initia v0.3.4/go.mod h1:nwtnVe3obacErGb7w6tq8Ych3U0d2f59rsgpVUeMnmM=
github.com/initia-labs/kvindexer v0.1.3 h1:TLkgJjp5TiPnH+OzYfk7ZKQTKqGOfSte59Y3gasob+o=
github.com/initia-labs/kvindexer v0.1.3/go.mod h1:rvAmgCAmEs4KM8sRRPcyTqNNwi8s2JiHybiFkYfp4KE=
github.com/initia-labs/kvindexer v0.1.5 h1:YLR4d237dNkGR8pe2zRGxx3CFB2CU6hhUmeJsshUw/0=
github.com/initia-labs/kvindexer v0.1.5/go.mod h1:OV85HaQ9KVrg+zGPUlxT9RF9nAaM3Yq4/3MoHqGqhWk=
github.com/initia-labs/kvindexer/submodules/block v0.1.0 h1:y+EXnksd/I2F96mzIoQA64nZUZON2P+99YrSzeLCLoY=
github.com/initia-labs/kvindexer/submodules/block v0.1.0/go.mod h1:4c+c59wVAnjuaJv/pcDYaUkeVmOqVV+orqEjya/RIjo=
github.com/initia-labs/kvindexer/submodules/move-nft v0.1.3 h1:0Gx1x2ZeIa8/UQ6aSUx/ePDHNCOd3HS8EL3WIQGf1lU=
Expand Down
Loading