cmd/geth: stop if import interrupted with multi files

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-03-12 08:37:41 +00:00
parent eb879a76cf
commit 0fa1940dc0
2 changed files with 7 additions and 1 deletions

View file

@ -319,6 +319,9 @@ func importChain(ctx *cli.Context) error {
if err := utils.ImportChain(chain, arg); err != nil { if err := utils.ImportChain(chain, arg); err != nil {
importErr = err importErr = err
log.Error("Import error", "file", arg, "err", err) log.Error("Import error", "file", arg, "err", err)
if err == utils.ErrImportInterrupted {
break
}
} }
} }
} }

View file

@ -55,6 +55,9 @@ const (
importBatchSize = 2500 importBatchSize = 2500
) )
// ErrImportInterrupted is returned when the user interrupts the import process.
var ErrImportInterrupted = errors.New("interrupted")
// Fatalf formats a message to standard error and exits the program. // Fatalf formats a message to standard error and exits the program.
// The message is also printed to standard output if standard error // The message is also printed to standard output if standard error
// is redirected to a different file. // is redirected to a different file.
@ -191,7 +194,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
for batch := 0; ; batch++ { for batch := 0; ; batch++ {
// Load a batch of RLP blocks. // Load a batch of RLP blocks.
if checkInterrupt() { if checkInterrupt() {
return errors.New("interrupted") return ErrImportInterrupted
} }
i := 0 i := 0
for ; i < importBatchSize; i++ { for ; i < importBatchSize; i++ {