Skip to content

Commit

Permalink
Merge pull request #637 from etclabscore/merge/foundation-release/1.1…
Browse files Browse the repository at this point in the history
…3.15-p2p-lint

Fix lint issue SA1019 reflect.SliceHeader
  • Loading branch information
meowsbits authored Jun 6, 2024
2 parents 549da55 + 850db88 commit 6c483de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
15 changes: 2 additions & 13 deletions consensus/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/binary"
"hash"
"math/big"
"reflect"
"runtime"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -176,12 +175,7 @@ func generateCache(dest []uint32, epoch uint64, epochLength uint64, seed []byte)
logFn("Generated ethash verification cache", "epochLength", epochLength, "elapsed", common.PrettyDuration(elapsed))
}()
// Convert our destination slice to a byte buffer
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 := unsafe.Slice((*byte)(unsafe.Pointer(&dest[0])), len(dest)*4)

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

// Convert our destination slice to a byte buffer
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
dataset := unsafe.Slice((*byte)(unsafe.Pointer(&dest[0])), len(dest)*4)

// Generate the dataset on many goroutines since it takes a while
threads := runtime.NumCPU()
Expand Down
7 changes: 1 addition & 6 deletions consensus/ethash/ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"math/rand"
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"sync"
Expand Down Expand Up @@ -144,11 +143,7 @@ func memoryMapFile(file *os.File, write bool) (mmap.MMap, []uint32, error) {
return nil, nil, err
}
// The file is now memory-mapped. Create a []uint32 view of the file.
var view []uint32
header := (*reflect.SliceHeader)(unsafe.Pointer(&view))
header.Data = (*reflect.SliceHeader)(unsafe.Pointer(&mem)).Data
header.Cap = len(mem) / 4
header.Len = header.Cap
view := unsafe.Slice((*uint32)(unsafe.Pointer(&mem[0])), len(mem)/4)
return mem, view, nil
}

Expand Down

0 comments on commit 6c483de

Please sign in to comment.