Merge pull request #120 from vulcanize/logging-enhancement
Logging enhancement
This commit is contained in:
commit
a3b55bfd56
@ -39,6 +39,8 @@ var coldImportCmd = &cobra.Command{
|
|||||||
|
|
||||||
Geth must be synced over all of the desired blocks and must not be running in order to execute this command.`,
|
Geth must be synced over all of the desired blocks and must not be running in order to execute this command.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
coldImport()
|
coldImport()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -55,7 +57,7 @@ func coldImport() {
|
|||||||
ethDBConfig := ethereum.CreateDatabaseConfig(ethereum.Level, levelDbPath)
|
ethDBConfig := ethereum.CreateDatabaseConfig(ethereum.Level, levelDbPath)
|
||||||
ethDB, err := ethereum.CreateDatabase(ethDBConfig)
|
ethDB, err := ethereum.CreateDatabase(ethDBConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error connecting to ethereum db: ", err)
|
LogWithCommand.Fatal("Error connecting to ethereum db: ", err)
|
||||||
}
|
}
|
||||||
mostRecentBlockNumberInDb := ethDB.GetHeadBlockNumber()
|
mostRecentBlockNumberInDb := ethDB.GetHeadBlockNumber()
|
||||||
if syncAll {
|
if syncAll {
|
||||||
@ -63,10 +65,10 @@ func coldImport() {
|
|||||||
endingBlockNumber = mostRecentBlockNumberInDb
|
endingBlockNumber = mostRecentBlockNumberInDb
|
||||||
}
|
}
|
||||||
if endingBlockNumber < startingBlockNumber {
|
if endingBlockNumber < startingBlockNumber {
|
||||||
log.Fatal("Ending block number must be greater than starting block number for cold import.")
|
LogWithCommand.Fatal("Ending block number must be greater than starting block number for cold import.")
|
||||||
}
|
}
|
||||||
if endingBlockNumber > mostRecentBlockNumberInDb {
|
if endingBlockNumber > mostRecentBlockNumberInDb {
|
||||||
log.Fatal("Ending block number is greater than most recent block in db: ", mostRecentBlockNumberInDb)
|
LogWithCommand.Fatal("Ending block number is greater than most recent block in db: ", mostRecentBlockNumberInDb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// init pg db
|
// init pg db
|
||||||
@ -76,7 +78,7 @@ func coldImport() {
|
|||||||
nodeBuilder := cold_import.NewColdImportNodeBuilder(reader, parser)
|
nodeBuilder := cold_import.NewColdImportNodeBuilder(reader, parser)
|
||||||
coldNode, err := nodeBuilder.GetNode(genesisBlock, levelDbPath)
|
coldNode, err := nodeBuilder.GetNode(genesisBlock, levelDbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error getting node: ", err)
|
LogWithCommand.Fatal("Error getting node: ", err)
|
||||||
}
|
}
|
||||||
pgDB := utils.LoadPostgres(databaseConfig, coldNode)
|
pgDB := utils.LoadPostgres(databaseConfig, coldNode)
|
||||||
|
|
||||||
@ -90,6 +92,6 @@ func coldImport() {
|
|||||||
coldImporter := cold_import.NewColdImporter(ethDB, blockRepository, receiptRepository, blockConverter)
|
coldImporter := cold_import.NewColdImporter(ethDB, blockRepository, receiptRepository, blockConverter)
|
||||||
err = coldImporter.Execute(startingBlockNumber, endingBlockNumber, coldNode.ID)
|
err = coldImporter.Execute(startingBlockNumber, endingBlockNumber, coldNode.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error executing cold import: ", err)
|
LogWithCommand.Fatal("Error executing cold import: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,8 @@ single config file or in separate command instances using different config files
|
|||||||
Specify config location when executing the command:
|
Specify config location when executing the command:
|
||||||
./vulcanizedb compose --config=./environments/config_name.toml`,
|
./vulcanizedb compose --config=./environments/config_name.toml`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
compose()
|
compose()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -110,23 +112,25 @@ func compose() {
|
|||||||
prepConfig()
|
prepConfig()
|
||||||
|
|
||||||
// Generate code to build the plugin according to the config file
|
// Generate code to build the plugin according to the config file
|
||||||
log.Info("generating plugin")
|
LogWithCommand.Info("generating plugin")
|
||||||
generator, err := p2.NewGenerator(genConfig, databaseConfig)
|
generator, err := p2.NewGenerator(genConfig, databaseConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
LogWithCommand.Debug("initializing plugin generator failed")
|
||||||
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
err = generator.GenerateExporterPlugin()
|
err = generator.GenerateExporterPlugin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("generating plugin failed")
|
LogWithCommand.Debug("generating plugin failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
// TODO: Embed versioning info in the .so files so we know which version of vulcanizedb to run them with
|
// TODO: Embed versioning info in the .so files so we know which version of vulcanizedb to run them with
|
||||||
_, pluginPath, err := genConfig.GetPluginPaths()
|
_, pluginPath, err := genConfig.GetPluginPaths()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
LogWithCommand.Debug("getting plugin path failed")
|
||||||
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Composed plugin %s", pluginPath)
|
fmt.Printf("Composed plugin %s", pluginPath)
|
||||||
log.Info("plugin .so file output to", pluginPath)
|
LogWithCommand.Info("plugin .so file output to ", pluginPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -134,38 +138,38 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepConfig() {
|
func prepConfig() {
|
||||||
log.Info("configuring plugin")
|
LogWithCommand.Info("configuring plugin")
|
||||||
names := viper.GetStringSlice("exporter.transformerNames")
|
names := viper.GetStringSlice("exporter.transformerNames")
|
||||||
transformers := make(map[string]config.Transformer)
|
transformers := make(map[string]config.Transformer)
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
transformer := viper.GetStringMapString("exporter." + name)
|
transformer := viper.GetStringMapString("exporter." + name)
|
||||||
p, pOK := transformer["path"]
|
p, pOK := transformer["path"]
|
||||||
if !pOK || p == "" {
|
if !pOK || p == "" {
|
||||||
log.Fatal(name, "transformer config is missing `path` value")
|
LogWithCommand.Fatal(name, " transformer config is missing `path` value")
|
||||||
}
|
}
|
||||||
r, rOK := transformer["repository"]
|
r, rOK := transformer["repository"]
|
||||||
if !rOK || r == "" {
|
if !rOK || r == "" {
|
||||||
log.Fatal(name, "transformer config is missing `repository` value")
|
LogWithCommand.Fatal(name, " transformer config is missing `repository` value")
|
||||||
}
|
}
|
||||||
m, mOK := transformer["migrations"]
|
m, mOK := transformer["migrations"]
|
||||||
if !mOK || m == "" {
|
if !mOK || m == "" {
|
||||||
log.Fatal(name, "transformer config is missing `migrations` value")
|
LogWithCommand.Fatal(name, " transformer config is missing `migrations` value")
|
||||||
}
|
}
|
||||||
mr, mrOK := transformer["rank"]
|
mr, mrOK := transformer["rank"]
|
||||||
if !mrOK || mr == "" {
|
if !mrOK || mr == "" {
|
||||||
log.Fatal(name, "transformer config is missing `rank` value")
|
LogWithCommand.Fatal(name, " transformer config is missing `rank` value")
|
||||||
}
|
}
|
||||||
rank, err := strconv.ParseUint(mr, 10, 64)
|
rank, err := strconv.ParseUint(mr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(name, "migration `rank` can't be converted to an unsigned integer")
|
LogWithCommand.Fatal(name, " migration `rank` can't be converted to an unsigned integer")
|
||||||
}
|
}
|
||||||
t, tOK := transformer["type"]
|
t, tOK := transformer["type"]
|
||||||
if !tOK {
|
if !tOK {
|
||||||
log.Fatal(name, "transformer config is missing `type` value")
|
LogWithCommand.Fatal(name, " transformer config is missing `type` value")
|
||||||
}
|
}
|
||||||
transformerType := config.GetTransformerType(t)
|
transformerType := config.GetTransformerType(t)
|
||||||
if transformerType == config.UnknownTransformerType {
|
if transformerType == config.UnknownTransformerType {
|
||||||
log.Fatal(errors.New(`unknown transformer type in exporter config accepted types are "eth_event", "eth_storage"`))
|
LogWithCommand.Fatal(errors.New(`unknown transformer type in exporter config accepted types are "eth_event", "eth_storage"`))
|
||||||
}
|
}
|
||||||
|
|
||||||
transformers[name] = config.Transformer{
|
transformers[name] = config.Transformer{
|
||||||
|
@ -105,6 +105,8 @@ single config file or in separate command instances using different config files
|
|||||||
Specify config location when executing the command:
|
Specify config location when executing the command:
|
||||||
./vulcanizedb composeAndExecute --config=./environments/config_name.toml`,
|
./vulcanizedb composeAndExecute --config=./environments/config_name.toml`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
composeAndExecute()
|
composeAndExecute()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -114,44 +116,44 @@ func composeAndExecute() {
|
|||||||
prepConfig()
|
prepConfig()
|
||||||
|
|
||||||
// Generate code to build the plugin according to the config file
|
// Generate code to build the plugin according to the config file
|
||||||
log.Info("generating plugin")
|
LogWithCommand.Info("generating plugin")
|
||||||
generator, err := p2.NewGenerator(genConfig, databaseConfig)
|
generator, err := p2.NewGenerator(genConfig, databaseConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
err = generator.GenerateExporterPlugin()
|
err = generator.GenerateExporterPlugin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("generating plugin failed")
|
LogWithCommand.Debug("generating plugin failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the plugin path and load the plugin
|
// Get the plugin path and load the plugin
|
||||||
_, pluginPath, err := genConfig.GetPluginPaths()
|
_, pluginPath, err := genConfig.GetPluginPaths()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
if !genConfig.Save {
|
if !genConfig.Save {
|
||||||
defer helpers.ClearFiles(pluginPath)
|
defer helpers.ClearFiles(pluginPath)
|
||||||
}
|
}
|
||||||
log.Info("linking plugin", pluginPath)
|
LogWithCommand.Info("linking plugin ", pluginPath)
|
||||||
plug, err := plugin.Open(pluginPath)
|
plug, err := plugin.Open(pluginPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("linking plugin failed")
|
LogWithCommand.Debug("linking plugin failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the `Exporter` symbol from the plugin
|
// Load the `Exporter` symbol from the plugin
|
||||||
log.Info("loading transformers from plugin")
|
LogWithCommand.Info("loading transformers from plugin")
|
||||||
symExporter, err := plug.Lookup("Exporter")
|
symExporter, err := plug.Lookup("Exporter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("loading Exporter symbol failed")
|
LogWithCommand.Debug("loading Exporter symbol failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that the symbol is of type Exporter
|
// Assert that the symbol is of type Exporter
|
||||||
exporter, ok := symExporter.(Exporter)
|
exporter, ok := symExporter.(Exporter)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug("plugged-in symbol not of type Exporter")
|
LogWithCommand.Debug("plugged-in symbol not of type Exporter")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,8 @@ Requires a .toml config file:
|
|||||||
piping = true
|
piping = true
|
||||||
`,
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
contractWatcher()
|
contractWatcher()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -103,18 +105,18 @@ func contractWatcher() {
|
|||||||
case "full":
|
case "full":
|
||||||
t = ft.NewTransformer(con, blockChain, &db)
|
t = ft.NewTransformer(con, blockChain, &db)
|
||||||
default:
|
default:
|
||||||
log.Fatal("Invalid mode")
|
LogWithCommand.Fatal("Invalid mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := t.Init()
|
err := t.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Sprintf("Failed to initialized transformer\r\nerr: %v\r\n", err))
|
LogWithCommand.Fatal(fmt.Sprintf("Failed to initialize transformer, err: %v ", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
err = t.Execute()
|
err = t.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Execution error for transformer:", t.GetConfig().Name, err)
|
LogWithCommand.Error("Execution error for transformer: ", t.GetConfig().Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ must have been composed by the same version of vulcanizedb or else it will not b
|
|||||||
Specify config location when executing the command:
|
Specify config location when executing the command:
|
||||||
./vulcanizedb execute --config=./environments/config_name.toml`,
|
./vulcanizedb execute --config=./environments/config_name.toml`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
execute()
|
execute()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -74,29 +76,29 @@ func execute() {
|
|||||||
// Get the plugin path and load the plugin
|
// Get the plugin path and load the plugin
|
||||||
_, pluginPath, err := genConfig.GetPluginPaths()
|
_, pluginPath, err := genConfig.GetPluginPaths()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Executing plugin %s", pluginPath)
|
fmt.Printf("Executing plugin %s", pluginPath)
|
||||||
log.Info("linking plugin", pluginPath)
|
LogWithCommand.Info("linking plugin ", pluginPath)
|
||||||
plug, err := plugin.Open(pluginPath)
|
plug, err := plugin.Open(pluginPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("linking plugin failed")
|
LogWithCommand.Warn("linking plugin failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the `Exporter` symbol from the plugin
|
// Load the `Exporter` symbol from the plugin
|
||||||
log.Info("loading transformers from plugin")
|
LogWithCommand.Info("loading transformers from plugin")
|
||||||
symExporter, err := plug.Lookup("Exporter")
|
symExporter, err := plug.Lookup("Exporter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("loading Exporter symbol failed")
|
LogWithCommand.Warn("loading Exporter symbol failed")
|
||||||
log.Fatal(err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that the symbol is of type Exporter
|
// Assert that the symbol is of type Exporter
|
||||||
exporter, ok := symExporter.(Exporter)
|
exporter, ok := symExporter.(Exporter)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("plugged-in symbol not of type Exporter")
|
LogWithCommand.Fatal("plugged-in symbol not of type Exporter")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the Exporters export method to load the EventTransformerInitializer, StorageTransformerInitializer, and ContractTransformerInitializer sets
|
// Use the Exporters export method to load the EventTransformerInitializer, StorageTransformerInitializer, and ContractTransformerInitializer sets
|
||||||
@ -147,7 +149,7 @@ type Exporter interface {
|
|||||||
func watchEthEvents(w *watcher.EventWatcher, wg *syn.WaitGroup) {
|
func watchEthEvents(w *watcher.EventWatcher, wg *syn.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// Execute over the EventTransformerInitializer set using the watcher
|
// Execute over the EventTransformerInitializer set using the watcher
|
||||||
log.Info("executing event transformers")
|
LogWithCommand.Info("executing event transformers")
|
||||||
var recheck constants.TransformerExecution
|
var recheck constants.TransformerExecution
|
||||||
if recheckHeadersArg {
|
if recheckHeadersArg {
|
||||||
recheck = constants.HeaderRecheck
|
recheck = constants.HeaderRecheck
|
||||||
@ -164,7 +166,7 @@ func watchEthEvents(w *watcher.EventWatcher, wg *syn.WaitGroup) {
|
|||||||
func watchEthStorage(w *watcher.StorageWatcher, wg *syn.WaitGroup) {
|
func watchEthStorage(w *watcher.StorageWatcher, wg *syn.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// Execute over the StorageTransformerInitializer set using the storage watcher
|
// Execute over the StorageTransformerInitializer set using the storage watcher
|
||||||
log.Info("executing storage transformers")
|
LogWithCommand.Info("executing storage transformers")
|
||||||
ticker := time.NewTicker(pollingInterval)
|
ticker := time.NewTicker(pollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
@ -177,7 +179,7 @@ func watchEthStorage(w *watcher.StorageWatcher, wg *syn.WaitGroup) {
|
|||||||
func watchEthContract(w *watcher.ContractWatcher, wg *syn.WaitGroup) {
|
func watchEthContract(w *watcher.ContractWatcher, wg *syn.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// Execute over the ContractTransformerInitializer set using the contract watcher
|
// Execute over the ContractTransformerInitializer set using the contract watcher
|
||||||
log.Info("executing contract_watcher transformers")
|
LogWithCommand.Info("executing contract_watcher transformers")
|
||||||
ticker := time.NewTicker(pollingInterval)
|
ticker := time.NewTicker(pollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
|
@ -49,20 +49,21 @@ Expects ethereum node to be running and requires a .toml config:
|
|||||||
ipcPath = "/Users/user/Library/Ethereum/geth.ipc"
|
ipcPath = "/Users/user/Library/Ethereum/geth.ipc"
|
||||||
`,
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
fullSync()
|
fullSync()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(fullSyncCmd)
|
rootCmd.AddCommand(fullSyncCmd)
|
||||||
|
|
||||||
fullSyncCmd.Flags().Int64VarP(&startingBlockNumber, "starting-block-number", "s", 0, "Block number to start syncing from")
|
fullSyncCmd.Flags().Int64VarP(&startingBlockNumber, "starting-block-number", "s", 0, "Block number to start syncing from")
|
||||||
}
|
}
|
||||||
|
|
||||||
func backFillAllBlocks(blockchain core.BlockChain, blockRepository datastore.BlockRepository, missingBlocksPopulated chan int, startingBlockNumber int64) {
|
func backFillAllBlocks(blockchain core.BlockChain, blockRepository datastore.BlockRepository, missingBlocksPopulated chan int, startingBlockNumber int64) {
|
||||||
populated, err := history.PopulateMissingBlocks(blockchain, blockRepository, startingBlockNumber)
|
populated, err := history.PopulateMissingBlocks(blockchain, blockRepository, startingBlockNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("backfillAllBlocks: error in populateMissingBlocks: ", err)
|
LogWithCommand.Error("backfillAllBlocks: error in populateMissingBlocks: ", err)
|
||||||
}
|
}
|
||||||
missingBlocksPopulated <- populated
|
missingBlocksPopulated <- populated
|
||||||
}
|
}
|
||||||
@ -74,13 +75,13 @@ func fullSync() {
|
|||||||
blockChain := getBlockChain()
|
blockChain := getBlockChain()
|
||||||
lastBlock, err := blockChain.LastBlock()
|
lastBlock, err := blockChain.LastBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("fullSync: Error getting last block: ", err)
|
LogWithCommand.Error("fullSync: Error getting last block: ", err)
|
||||||
}
|
}
|
||||||
if lastBlock.Int64() == 0 {
|
if lastBlock.Int64() == 0 {
|
||||||
log.Fatal("geth initial: state sync not finished")
|
LogWithCommand.Fatal("geth initial: state sync not finished")
|
||||||
}
|
}
|
||||||
if startingBlockNumber > lastBlock.Int64() {
|
if startingBlockNumber > lastBlock.Int64() {
|
||||||
log.Fatal("fullSync: starting block number > current block number")
|
LogWithCommand.Fatal("fullSync: starting block number > current block number")
|
||||||
}
|
}
|
||||||
|
|
||||||
db := utils.LoadPostgres(databaseConfig, blockChain.Node())
|
db := utils.LoadPostgres(databaseConfig, blockChain.Node())
|
||||||
@ -94,9 +95,9 @@ func fullSync() {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
window, err := validator.ValidateBlocks()
|
window, err := validator.ValidateBlocks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("fullSync: error in validateBlocks: ", err)
|
LogWithCommand.Error("fullSync: error in validateBlocks: ", err)
|
||||||
}
|
}
|
||||||
log.Debug(window.GetString())
|
LogWithCommand.Debug(window.GetString())
|
||||||
case <-missingBlocksPopulated:
|
case <-missingBlocksPopulated:
|
||||||
go backFillAllBlocks(blockChain, blockRepository, missingBlocksPopulated, startingBlockNumber)
|
go backFillAllBlocks(blockChain, blockRepository, missingBlocksPopulated, startingBlockNumber)
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,8 @@ Expects ethereum node to be running and requires a .toml config:
|
|||||||
ipcPath = "/Users/user/Library/Ethereum/geth.ipc"
|
ipcPath = "/Users/user/Library/Ethereum/geth.ipc"
|
||||||
`,
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
SubCommand = cmd.CalledAs()
|
||||||
|
LogWithCommand = *log.WithField("SubCommand", SubCommand)
|
||||||
headerSync()
|
headerSync()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -64,7 +66,7 @@ func backFillAllHeaders(blockchain core.BlockChain, headerRepository datastore.H
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO Lots of possible errors in the call stack above. If errors occur, we still put
|
// TODO Lots of possible errors in the call stack above. If errors occur, we still put
|
||||||
// 0 in the channel, triggering another round
|
// 0 in the channel, triggering another round
|
||||||
log.Error("backfillAllHeaders: Error populating headers: ", err)
|
LogWithCommand.Error("backfillAllHeaders: Error populating headers: ", err)
|
||||||
}
|
}
|
||||||
missingBlocksPopulated <- populated
|
missingBlocksPopulated <- populated
|
||||||
}
|
}
|
||||||
@ -86,9 +88,9 @@ func headerSync() {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
window, err := validator.ValidateHeaders()
|
window, err := validator.ValidateHeaders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("headerSync: ValidateHeaders failed: ", err)
|
LogWithCommand.Error("headerSync: ValidateHeaders failed: ", err)
|
||||||
}
|
}
|
||||||
log.Debug(window.GetString())
|
LogWithCommand.Debug(window.GetString())
|
||||||
case n := <-missingBlocksPopulated:
|
case n := <-missingBlocksPopulated:
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
@ -101,12 +103,12 @@ func headerSync() {
|
|||||||
func validateArgs(blockChain *geth.BlockChain) {
|
func validateArgs(blockChain *geth.BlockChain) {
|
||||||
lastBlock, err := blockChain.LastBlock()
|
lastBlock, err := blockChain.LastBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("validateArgs: Error getting last block: ", err)
|
LogWithCommand.Error("validateArgs: Error getting last block: ", err)
|
||||||
}
|
}
|
||||||
if lastBlock.Int64() == 0 {
|
if lastBlock.Int64() == 0 {
|
||||||
log.Fatal("geth initial: state sync not finished")
|
LogWithCommand.Fatal("geth initial: state sync not finished")
|
||||||
}
|
}
|
||||||
if startingBlockNumber > lastBlock.Int64() {
|
if startingBlockNumber > lastBlock.Int64() {
|
||||||
log.Fatal("starting block number > current block number")
|
LogWithCommand.Fatal("starting block number > current block number")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
cmd/root.go
16
cmd/root.go
@ -46,6 +46,8 @@ var (
|
|||||||
syncAll bool
|
syncAll bool
|
||||||
endingBlockNumber int64
|
endingBlockNumber int64
|
||||||
recheckHeadersArg bool
|
recheckHeadersArg bool
|
||||||
|
SubCommand string
|
||||||
|
LogWithCommand log.Entry
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -66,16 +68,15 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initFuncs(cmd *cobra.Command, args []string) {
|
func initFuncs(cmd *cobra.Command, args []string) {
|
||||||
database(cmd, args)
|
setViperConfigs()
|
||||||
|
logLvlErr := logLevel()
|
||||||
logLvlErr := logLevel(cmd, args)
|
|
||||||
if logLvlErr != nil {
|
if logLvlErr != nil {
|
||||||
log.Fatal("Could not set log level: ", logLvlErr)
|
log.Fatal("Could not set log level: ", logLvlErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func database(cmd *cobra.Command, args []string) {
|
func setViperConfigs() {
|
||||||
ipc = viper.GetString("client.ipcpath")
|
ipc = viper.GetString("client.ipcpath")
|
||||||
levelDbPath = viper.GetString("client.leveldbpath")
|
levelDbPath = viper.GetString("client.leveldbpath")
|
||||||
storageDiffsPath = viper.GetString("filesystem.storageDiffsPath")
|
storageDiffsPath = viper.GetString("filesystem.storageDiffsPath")
|
||||||
@ -89,12 +90,15 @@ func database(cmd *cobra.Command, args []string) {
|
|||||||
viper.Set("database.config", databaseConfig)
|
viper.Set("database.config", databaseConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logLevel(cmd *cobra.Command, args []string) error {
|
func logLevel() error {
|
||||||
lvl, err := log.ParseLevel(viper.GetString("log.level"))
|
lvl, err := log.ParseLevel(viper.GetString("log.level"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.SetLevel(lvl)
|
log.SetLevel(lvl)
|
||||||
|
if lvl > log.InfoLevel {
|
||||||
|
log.SetReportCaller(true)
|
||||||
|
}
|
||||||
log.Info("Log level set to ", lvl.String())
|
log.Info("Log level set to ", lvl.String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -151,7 +155,7 @@ func getBlockChain() *geth.BlockChain {
|
|||||||
rawRpcClient, err := rpc.Dial(ipc)
|
rawRpcClient, err := rpc.Dial(ipc)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not dial client: ", err)
|
LogWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
rpcClient := client.NewRpcClient(rawRpcClient, ipc)
|
rpcClient := client.NewRpcClient(rawRpcClient, ipc)
|
||||||
ethClient := ethclient.NewClient(rawRpcClient)
|
ethClient := ethclient.NewClient(rawRpcClient)
|
||||||
|
4
main.go
4
main.go
@ -3,15 +3,15 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/vulcanize/vulcanizedb/cmd"
|
"github.com/vulcanize/vulcanizedb/cmd"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFormatter(&log.JSONFormatter{
|
log.SetFormatter(&log.JSONFormatter{
|
||||||
PrettyPrint: true,
|
PrettyPrint: true,
|
||||||
})
|
})
|
||||||
log.SetReportCaller(true)
|
|
||||||
file, err := os.OpenFile("vulcanizedb.log",
|
file, err := os.OpenFile("vulcanizedb.log",
|
||||||
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -42,7 +42,7 @@ func PopulateMissingHeaders(blockChain core.BlockChain, headerRepository datasto
|
|||||||
log.Debug(getBlockRangeString(blockNumbers))
|
log.Debug(getBlockRangeString(blockNumbers))
|
||||||
_, err = RetrieveAndUpdateHeaders(blockChain, headerRepository, blockNumbers)
|
_, err = RetrieveAndUpdateHeaders(blockChain, headerRepository, blockNumbers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("PopulateMissingHeaders: Error getting/updating headers:", err)
|
log.Error("PopulateMissingHeaders: Error getting/updating headers: ", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return len(blockNumbers), nil
|
return len(blockNumbers), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user