From e3ca8b47d7e9b460c7d88d0194a39cde1098cee6 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 18 Jan 2025 19:42:54 +0100 Subject: [PATCH] save --- .../fork_graph/fork_graph_disk_fs.go | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go index 7f32c315129..8b908686831 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go @@ -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 { @@ -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 }