Skip to content

Commit

Permalink
consensus/ethash: pr feedback from @mdempsky, makes a copy of dest su…
Browse files Browse the repository at this point in the history
…ch that is not mutated
  • Loading branch information
prestonvanloon committed Jul 24, 2020
1 parent adb1bce commit f3b468f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions consensus/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
logFn("Generated ethash verification cache", "elapsed", common.PrettyDuration(elapsed))
}()
// Convert our destination slice to a byte buffer
header := (*reflect.SliceHeader)(unsafe.Pointer(&dest))
header.Len *= 4
header.Cap *= 4
cache := *(*[]byte)(unsafe.Pointer(header))
var cache []byte
cacheHdr := (*reflect.SliceHeader)(unsafe.Pointer(&cache))
dstHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dest))
cacheHdr.Data = dstHdr.Data
cacheHdr.Len = dstHdr.Len * 4
cacheHdr.Cap = dstHdr.Cap * 4
cache = *(*[]byte)(unsafe.Pointer(cacheHdr))

This comment has been minimized.

Copy link
@mdempsky

mdempsky Jul 25, 2020

This last assignment isn't necessary. cacheHdr is pointing to cache, so the assignments on line 157--159 already updated cache.


// Calculate the number of theoretical rows (we'll store in one buffer nonetheless)
size := uint64(len(cache))
Expand Down

0 comments on commit f3b468f

Please sign in to comment.