From 6fdc619413980f90770f13339a5d79a4672779ae Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Tue, 2 Aug 2022 18:03:23 +0530 Subject: [PATCH] consensus/ethash: remove temp files created during DAG generation (#25381) This makes it remove not only the actual DAG file, but also the temporary file which the DAG data is written to while generating. --- consensus/ethash/ethash.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 0efb3590f089d..dfe00d4b93c06 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -278,8 +278,11 @@ func (c *cache) generate(dir string, limit int, lock bool, test bool) { // Iterate over all previous instances and delete old ones for ep := int(c.epoch) - limit; ep >= 0; ep-- { seed := seedHash(uint64(ep)*epochLength + 1) - path := filepath.Join(dir, fmt.Sprintf("cache-R%d-%x%s", algorithmRevision, seed[:8], endian)) - os.Remove(path) + path := filepath.Join(dir, fmt.Sprintf("cache-R%d-%x%s*", algorithmRevision, seed[:8], endian)) + files, _ := filepath.Glob(path) // find also the temp files that are generated. + for _, file := range files { + os.Remove(file) + } } }) }