Skip to content

Commit

Permalink
core/rawdb: no need to run truncateFile for readonly mode (ethereum#2…
Browse files Browse the repository at this point in the history
…8145)

Avoid truncating files, if ancients are opened in readonly mode. With this change, we return error instead of trying (and failing)  to repair
  • Loading branch information
jsvisa authored and joeylichang committed Oct 16, 2023
1 parent d3a6f9a commit 9baffb3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func (t *freezerTable) repair() error {
}
// Ensure the index is a multiple of indexEntrySize bytes
if overflow := stat.Size() % indexEntrySize; overflow != 0 {
if t.readonly {
return fmt.Errorf("index file(path: %s, name: %s) size is not a multiple of %d", t.path, t.name, indexEntrySize)
}
truncateFreezerFile(t.index, stat.Size()-overflow) // New file can't trigger this path
}
// Retrieve the file sizes and prepare for truncation
Expand Down Expand Up @@ -278,6 +281,9 @@ func (t *freezerTable) repair() error {
// Keep truncating both files until they come in sync
contentExp = int64(lastIndex.offset)
for contentExp != contentSize {
if t.readonly {
return fmt.Errorf("freezer table(path: %s, name: %s, num: %d) is corrupted", t.path, t.name, lastIndex.filenum)
}
verbose = true
// Truncate the head file to the last offset pointer
if contentExp < contentSize {
Expand Down

0 comments on commit 9baffb3

Please sign in to comment.