Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Jan 18, 2025
1 parent 75ecb8d commit e3ca8b4
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ func (f *forkGraphDisk) DumpBeaconStateOnDisk(blockRoot libcommon.Hash, bs *stat
return
}
f.stateDumpLock.Lock()
unlockOnDefer := true
defer func() {
if unlockOnDefer {
f.stateDumpLock.Unlock()
}
}()
defer f.stateDumpLock.Unlock()
// Truncate and then grow the buffer to the size of the state.
f.sszBuffer, err = bs.EncodeSSZ(f.sszBuffer[:0])
if err != nil {
Expand Down Expand Up @@ -170,25 +165,23 @@ func (f *forkGraphDisk) DumpBeaconStateOnDisk(blockRoot libcommon.Hash, bs *stat
log.Error("failed to sync dumped file", "err", err)
return
}
unlockOnDefer = false
go func() {
cacheFile, err := f.fs.OpenFile(getBeaconStateCacheFilename(blockRoot), os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0o755)
if err != nil {
log.Error("failed to open cache file", "err", err)
return
}
defer cacheFile.Close()
defer f.stateDumpLock.Unlock()

if _, err = cacheFile.Write(b.Bytes()); err != nil {
log.Error("failed to write cache file", "err", err)
return
}
if err = cacheFile.Sync(); err != nil {
log.Error("failed to sync cache file", "err", err)
return
}
}()

cacheFile, err := f.fs.OpenFile(getBeaconStateCacheFilename(blockRoot), os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0o755)
if err != nil {
log.Error("failed to open cache file", "err", err)
return
}
defer cacheFile.Close()
defer f.stateDumpLock.Unlock()

if _, err = cacheFile.Write(b.Bytes()); err != nil {
log.Error("failed to write cache file", "err", err)
return
}
if err = cacheFile.Sync(); err != nil {
log.Error("failed to sync cache file", "err", err)
return
}

return
}

0 comments on commit e3ca8b4

Please sign in to comment.