Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consensus/ethash: fix usage of *reflect.SliceHeader #21372

Merged
merged 4 commits into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions consensus/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ 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

// Calculate the number of theoretical rows (we'll store in one buffer nonetheless)
size := uint64(len(cache))
Expand Down Expand Up @@ -283,10 +285,12 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
swapped := !isLittleEndian()

// Convert our destination slice to a byte buffer
header := *(*reflect.SliceHeader)(unsafe.Pointer(&dest))
header.Len *= 4
header.Cap *= 4
dataset := *(*[]byte)(unsafe.Pointer(&header))
var dataset []byte
datasetHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dataset))
destHdr := (*reflect.SliceHeader)(unsafe.Pointer(&dest))
datasetHdr.Data = destHdr.Data
datasetHdr.Len = destHdr.Len * 4
datasetHdr.Cap = destHdr.Cap * 4

// Generate the dataset on many goroutines since it takes a while
threads := runtime.NumCPU()
Expand Down