Skip to content

Commit

Permalink
Merge PR: correct auto repair behavior (#2911)
Browse files Browse the repository at this point in the history
* close block index store after repair to avoid resource racing

* fix config error

* update import sequence

Co-authored-by: xiangjianmeng <[email protected]>
  • Loading branch information
lisuxiaoqi and xiangjianmeng authored Jan 12, 2023
1 parent 12f66f9 commit c94fce4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/repair_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func RepairState(ctx *server.Context, onStart bool) {
return
}

config.RegisterDynamicConfig(ctx.Logger.With("module", "config"))
// create proxy app
proxyApp, repairApp, err := createRepairApp(ctx)
panicError(err)
Expand Down Expand Up @@ -178,14 +179,14 @@ func newRepairApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer) *repairA
func doRepair(ctx *server.Context, state sm.State, stateStoreDB dbm.DB,
proxyApp proxy.AppConns, startHeight, latestHeight int64, dataDir string) {
stateCopy := state.Copy()
config.RegisterDynamicConfig(ctx.Logger.With("module", "config"))

ctx.Logger.Debug("stateCopy", "state", fmt.Sprintf("%+v", stateCopy))
// construct state for repair
state = constructStartState(state, stateStoreDB, startHeight)
ctx.Logger.Debug("constructStartState", "state", fmt.Sprintf("%+v", state))
// repair state
eventBus := types.NewEventBus()
txStore, txindexServer, err := startEventBusAndIndexerService(ctx.Config, eventBus, ctx.Logger)
txStore, blockIndexStore, txindexServer, err := startEventBusAndIndexerService(ctx.Config, eventBus, ctx.Logger)
panicError(err)
blockExec := sm.NewBlockExecutor(stateStoreDB, ctx.Logger, proxyApp.Consensus(), mock.Mempool{}, sm.MockEvidencePool{})
blockExec.SetEventBus(eventBus)
Expand All @@ -208,6 +209,10 @@ func doRepair(ctx *server.Context, state sm.State, stateStoreDB dbm.DB,
err := txStore.Close()
panicError(err)
}
if blockIndexStore != nil {
err := blockIndexStore.Close()
panicError(err)
}
}()

global.SetGlobalHeight(startHeight + 1)
Expand All @@ -225,10 +230,10 @@ func doRepair(ctx *server.Context, state sm.State, stateStoreDB dbm.DB,
}
}

func startEventBusAndIndexerService(config *cfg.Config, eventBus *types.EventBus, logger tmlog.Logger) (txStore dbm.DB, indexerService *txindex.IndexerService, err error) {
func startEventBusAndIndexerService(config *cfg.Config, eventBus *types.EventBus, logger tmlog.Logger) (txStore dbm.DB, blockIndexStore dbm.DB, indexerService *txindex.IndexerService, err error) {
eventBus.SetLogger(logger.With("module", "events"))
if err := eventBus.Start(); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
// Transaction indexing
var txIndexer txindex.TxIndexer
Expand All @@ -237,11 +242,11 @@ func startEventBusAndIndexerService(config *cfg.Config, eventBus *types.EventBus
case "kv":
txStore, err = sdk.NewDB(txIndexDB, filepath.Join(config.RootDir, "data"))
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
blockIndexStore, err := sdk.NewDB(blockIndexDb, filepath.Join(config.RootDir, "data"))
blockIndexStore, err = sdk.NewDB(blockIndexDb, filepath.Join(config.RootDir, "data"))
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
switch {
case config.TxIndex.IndexKeys != "":
Expand All @@ -267,9 +272,9 @@ func startEventBusAndIndexerService(config *cfg.Config, eventBus *types.EventBus
txStore.Close()
}

return nil, nil, err
return nil, nil, nil, err
}
return txStore, indexerService, nil
return txStore, blockIndexStore, indexerService, nil
}

// splitAndTrimEmpty slices s into all subslices separated by sep and returns a
Expand Down

0 comments on commit c94fce4

Please sign in to comment.