Skip to content

Commit 915d9d9

Browse files
jsvisafjl
andauthored
cmd: ctrl-c to halt the whole import process (#31360)
When I press Ctrl-C during the import of multiple files, the import process will still attempt to import the subsequent files. However, in normal circumstances, users would expect the import to stop immediately upon pressing Ctrl-C. And because the current file was not finished importing, subsequent import tasks often fail due to an `unknown ancestor` error. --------- Signed-off-by: jsvisa <[email protected]> Co-authored-by: Felix Lange <[email protected]>
1 parent eb879a7 commit 915d9d9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

cmd/geth/chaincmd.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
103103
utils.StateHistoryFlag,
104104
}, utils.DatabaseFlags),
105105
Description: `
106-
The import command imports blocks from an RLP-encoded form. The form can be one file
107-
with several RLP-encoded blocks, or several files can be used.
106+
The import command allows the import of blocks from an RLP-encoded format. This format can be a single file
107+
containing multiple RLP-encoded blocks, or multiple files can be given.
108108
109-
If only one file is used, import error will result in failure. If several files are used,
110-
processing will proceed even if an individual RLP-file import failure occurs.`,
109+
If only one file is used, an import error will result in the entire import process failing. If
110+
multiple files are processed, the import process will continue even if an individual RLP file fails
111+
to import successfully.`,
111112
}
112113
exportCommand = &cli.Command{
113114
Action: exportChain,
@@ -319,6 +320,9 @@ func importChain(ctx *cli.Context) error {
319320
if err := utils.ImportChain(chain, arg); err != nil {
320321
importErr = err
321322
log.Error("Import error", "file", arg, "err", err)
323+
if err == utils.ErrImportInterrupted {
324+
break
325+
}
322326
}
323327
}
324328
}

cmd/utils/cmd.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const (
5555
importBatchSize = 2500
5656
)
5757

58+
// ErrImportInterrupted is returned when the user interrupts the import process.
59+
var ErrImportInterrupted = errors.New("interrupted")
60+
5861
// Fatalf formats a message to standard error and exits the program.
5962
// The message is also printed to standard output if standard error
6063
// is redirected to a different file.
@@ -191,7 +194,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
191194
for batch := 0; ; batch++ {
192195
// Load a batch of RLP blocks.
193196
if checkInterrupt() {
194-
return errors.New("interrupted")
197+
return ErrImportInterrupted
195198
}
196199
i := 0
197200
for ; i < importBatchSize; i++ {

0 commit comments

Comments
 (0)