Skip to content

Commit

Permalink
Merge branch 'master' into itest-light-node-state-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Nov 27, 2024
2 parents 19ef470 + b233383 commit cc1f425
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cmd/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func runImporter(c *cfg) error {
return err
}
defer cpfClose()
defer func() { // Debug.
if mpfErr := configureMemProfile(c.memProfilePath); mpfErr != nil {
zap.S().Errorf("Failed to configure memory profile: %v", mpfErr)
}
}()

// https://godoc.org/github.com/coocood/freecache#NewCache
debug.SetGCPercent(20)
Expand Down Expand Up @@ -213,38 +218,39 @@ func runImporter(c *cfg) error {
}

start := time.Now()
defer func() {
elapsed := time.Since(start)
zap.S().Infof("Import took %s", elapsed)
}()
if impErr := importer.ApplyFromFile(ctx, params, st, uint64(c.nBlocks), height); impErr != nil {
currentHeight, hErr := st.Height()
if hErr != nil {
zap.S().Fatalf("Failed to get current height: %v", hErr)
}
handleError(impErr, currentHeight)
if resErr := handleError(impErr, currentHeight); resErr != nil {
return resErr
}
}
elapsed := time.Since(start)
zap.S().Infof("Import took %s", elapsed)

if len(c.balancesPath) != 0 {
if balErr := importer.CheckBalances(st, c.balancesPath); balErr != nil {
return fmt.Errorf("failed to check balances: %w", balErr)
}
}

// Debug.
if mpfErr := configureMemProfile(c.memProfilePath); mpfErr != nil {
return mpfErr
}

return nil
}

func handleError(err error, height uint64) {
func handleError(err error, height uint64) error {
switch {
case errors.Is(err, context.Canceled):
zap.S().Infof("Interrupted by user, height %d", height)
return nil
case errors.Is(err, io.EOF):
zap.S().Infof("End of blockchain file reached, height %d", height)
return nil
default:
zap.S().Fatalf("Failed to apply blocks after height %d: %v", height, err)
return fmt.Errorf("failed to apply blocks after height %d: %w", height, err)
}
}

Expand Down

0 comments on commit cc1f425

Please sign in to comment.