Skip to content

Commit

Permalink
core/rawdb, triedb/pathdb: fix freezer read-only option (ethereum#29823)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 authored May 28, 2024
1 parent 61932e4 commit b88051e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions core/rawdb/freezer_resettable.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ type freezerOpenFunc = func() (*Freezer, error)
// resettableFreezer is a wrapper of the freezer which makes the
// freezer resettable.
type resettableFreezer struct {
freezer *Freezer
opener freezerOpenFunc
datadir string
lock sync.RWMutex
readOnly bool
freezer *Freezer
opener freezerOpenFunc
datadir string
lock sync.RWMutex
}

// newResettableFreezer creates a resettable freezer, note freezer is
Expand All @@ -60,9 +61,10 @@ func newResettableFreezer(datadir string, namespace string, readonly bool, maxTa
return nil, err
}
return &resettableFreezer{
freezer: freezer,
opener: opener,
datadir: datadir,
readOnly: readonly,
freezer: freezer,
opener: opener,
datadir: datadir,
}, nil
}

Expand All @@ -74,6 +76,9 @@ func (f *resettableFreezer) Reset() error {
f.lock.Lock()
defer f.lock.Unlock()

if f.readOnly {
return errReadOnly
}
if err := f.freezer.Close(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (db *Database) repairHistory() error {
// all of them. Fix the tests first.
return nil
}
freezer, err := rawdb.NewStateFreezer(ancient, false)
freezer, err := rawdb.NewStateFreezer(ancient, db.readOnly)
if err != nil {
log.Crit("Failed to open state history freezer", "err", err)
}
Expand Down

0 comments on commit b88051e

Please sign in to comment.