Populate transaction hash database if the database has not been set up before

This commit is contained in:
Geoff Stuart
2023-01-30 16:33:04 -05:00
parent af72e6f6ac
commit e0326d9d39
3 changed files with 76 additions and 13 deletions
+15 -1
View File
@@ -2,6 +2,7 @@ package modules
import (
"context"
"os"
"path/filepath"
"go.uber.org/fx"
@@ -24,7 +25,13 @@ func EthModuleAPI(cfg config.FevmConfig) func(helpers.MetricsCtx, repo.LockedRep
return nil, err
}
transactionHashLookup, err := ethhashlookup.NewTransactionHashLookup(filepath.Join(sqlitePath, "txhash.db"))
dbPath := filepath.Join(sqlitePath, "txhash.db")
// Check if the db exists, if not, we'll back-fill some entries
_, err = os.Stat(dbPath)
dbAlreadyExists := err == nil
transactionHashLookup, err := ethhashlookup.NewTransactionHashLookup(dbPath)
if err != nil {
return nil, err
}
@@ -40,6 +47,13 @@ func EthModuleAPI(cfg config.FevmConfig) func(helpers.MetricsCtx, repo.LockedRep
TransactionHashLookup: transactionHashLookup,
}
if !dbAlreadyExists {
err = ethTxHashManager.PopulateExistingMappings(mctx, 0)
if err != nil {
return nil, err
}
}
const ChainHeadConfidence = 1
ctx := helpers.LifecycleCtx(mctx, lc)