From 369521becb0489d56ad8083874f417e2a07008f0 Mon Sep 17 00:00:00 2001 From: Yorick Downe <71337066+yorickdowne@users.noreply.github.com> Date: Wed, 3 Jun 2026 18:48:45 +0100 Subject: [PATCH] cmd/utils: avoid extra newlines when reading era checksums (#35104) The checksum count during EraE import is off by one when `checksums.txt` ends its last line on a newline, as the pandaops file does. The current code would result in one empty string after the final `\n`, something like ``` []string{ "line1", "line2", "line3", "", } ``` Trim off the final `\n`, if it exists: `return strings.Split(strings.TrimRight(string(b), "\n"), "\n"), nil` --------- Co-authored-by: lightclient --- cmd/utils/cmd.go | 14 ++++++++++++-- cmd/utils/history_test.go | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index e490f613b3..3cb97ff947 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -242,11 +242,21 @@ func ImportChain(chain *core.BlockChain, fn string) error { } func readList(filename string) ([]string, error) { - b, err := os.ReadFile(filename) + f, err := os.Open(filename) if err != nil { return nil, err } - return strings.Split(string(b), "\n"), nil + defer f.Close() + + var lines []string + scanner := bufio.NewScanner(f) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + if err := scanner.Err(); err != nil { + return nil, err + } + return lines, nil } // ImportHistory imports Era1 files containing historical block information, diff --git a/cmd/utils/history_test.go b/cmd/utils/history_test.go index 56375f9ff5..e11068ae15 100644 --- a/cmd/utils/history_test.go +++ b/cmd/utils/history_test.go @@ -106,10 +106,14 @@ func TestHistoryImportAndExport(t *testing.T) { } // Read checksums. - b, err := os.ReadFile(filepath.Join(dir, "checksums.txt")) + checksumsFile := filepath.Join(dir, "checksums.txt") + b, err := os.ReadFile(checksumsFile) if err != nil { t.Fatalf("failed to read checksums: %v", err) } + + // Add a trailing newline to ensure checksum handling is defensive. + _ = os.WriteFile(checksumsFile, append(b, '\n'), 0644) checksums := strings.Split(string(b), "\n") // Verify each Era.