Skip to content

Commit

Permalink
consensus/ethash: more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ziogaschr committed Jun 6, 2024
1 parent cfada26 commit 850db88
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
8 changes: 1 addition & 7 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 @@ -305,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 850db88

Please sign in to comment.