Skip to content

Commit

Permalink
create db for kvindexer in AppCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
Vritra4 committed Jul 16, 2024
1 parent edf9bc1 commit 42faa66
Show file tree
Hide file tree
Showing 8 changed files with 621 additions and 16 deletions.
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func NewMinitiaApp(
logger log.Logger,
db dbm.DB,
indexerDB dbm.DB,
kvindexerDB dbm.DB,
traceStore io.Writer,
loadLatest bool,
evmConfig evmconfig.EVMConfig,
Expand Down Expand Up @@ -769,7 +770,7 @@ func NewMinitiaApp(
marketmap.NewAppModule(appCodec, app.MarketMapKeeper),
)

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

Expand Down Expand Up @@ -1270,7 +1271,7 @@ func VerifyAddressLen() func(addr []byte) error {
}
}

func (app *MinitiaApp) setupIndexer(indexerDB dbm.DB, appOpts servertypes.AppOptions, homePath string, ac, vc address.Codec, appCodec codec.Codec) error {
func (app *MinitiaApp) setupIndexer(appOpts servertypes.AppOptions, indexerDB dbm.DB, 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 @@ -1279,7 +1280,7 @@ func (app *MinitiaApp) setupIndexer(indexerDB dbm.DB, appOpts servertypes.AppOpt
app.indexerKeeper = indexerkeeper.NewKeeper(
appCodec,
"evm",
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 @@ -65,7 +65,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewLogger(os.Stdout)
app := NewMinitiaApp(
logger, db, dbm.NewMemDB(),
logger, db, dbm.NewMemDB(), dbm.NewMemDB(),
nil, true, evmconfig.DefaultEVMConfig(),
EmptyAppOptions{},
)
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestGetKey(t *testing.T) {
db := dbm.NewMemDB()
app := NewMinitiaApp(
log.NewLogger(os.Stdout),
db, dbm.NewMemDB(), nil, true,
db, dbm.NewMemDB(), dbm.NewMemDB(), nil, true,
evmconfig.DefaultEVMConfig(),
EmptyAppOptions{},
)
Expand Down
6 changes: 3 additions & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), dbm.NewMemDB(), nil, true, evmconfig.DefaultEVMConfig(), EmptyAppOptions{})
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), dbm.NewMemDB(), dbm.NewMemDB(), nil, true, evmconfig.DefaultEVMConfig(), EmptyAppOptions{})
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Codec: tempApp.AppCodec(),
Expand All @@ -30,7 +30,7 @@ func MakeEncodingConfig() params.EncodingConfig {
}

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

Check warning on line 33 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L33

Added line #L33 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 @@ -51,7 +51,7 @@ func AutoCliOpts() autocli.AppOptions {
}

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

Check warning on line 54 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L54

Added line #L54 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 @@ -57,6 +57,7 @@ func setup(db *dbm.DB, withGenesis bool) (*MinitiaApp, GenesisState) {
log.NewNopLogger(),
getOrCreateMemDB(db),
dbm.NewMemDB(),
dbm.NewMemDB(),
nil,
true,
evmconfig.DefaultEVMConfig(),
Expand Down
25 changes: 22 additions & 3 deletions cmd/minitiad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import (
minitiaapp "github.com/initia-labs/minievm/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 @@ -276,9 +279,15 @@ func (a *appCreator) AppCreator() servertypes.AppCreator {
if err != nil {
panic(err)
}
kvdbConfig := getKVIndexerDBConfig(appOpts)

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

app := minitiaapp.NewMinitiaApp(
logger, db, indexerDB, traceStore, true,
logger, db, indexerDB, kvindexerDB, traceStore, true,
evmconfig.GetConfig(appOpts),
appOpts,
baseappOptions...,
Expand Down Expand Up @@ -314,13 +323,13 @@ func (a appCreator) appExport(

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

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

return initiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down Expand Up @@ -379,6 +388,16 @@ func getDBConfig(appOpts servertypes.AppOptions) (string, dbm.BackendType) {
return rootify(dbDir, rootDir), dbBackend
}

// getKVIndexerDBConfig returns the database configuration for the KV indexer
func getKVIndexerDBConfig(appOpts servertypes.AppOptions) *kvindexerconfig.IndexerConfig {
dbBackend, err := kvindexerconfig.NewConfig(appOpts)
if err != nil {
panic(err)
}

return dbBackend
}

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
if filepath.IsAbs(path) {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/holiman/uint256 v1.2.4
github.com/initia-labs/OPinit v0.3.2
github.com/initia-labs/initia v0.3.5
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/pair v0.1.1
github.com/initia-labs/kvindexer/submodules/tx v0.1.0
Expand Down Expand Up @@ -74,6 +74,7 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/allegro/bigcache/v3 v3.1.0 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.44.312 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
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 @@ -822,8 +824,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.5 h1:JsO0OZ+ZRQjzFusXSA2f7U1LNO6nApaCr+U6idJ+Pko=
github.com/initia-labs/initia v0.3.5/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/pair v0.1.1 h1:o151gA4jIbqEl+pWTOCizkiOPgkA5ANuNbHfqAQijoE=
Expand Down
Loading

0 comments on commit 42faa66

Please sign in to comment.