Skip to content

Commit 8f43c97

Browse files
authored
Merge pull request #16207 from karalabe/drop-go1.7
travis, build, consensus: drop support for Go 1.7
2 parents 98ec5e5 + 17b0e22 commit 8f43c97

8 files changed

Lines changed: 64 additions & 169 deletions

File tree

‎.travis.yml‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@ go_import_path: github.com/ethereum/go-ethereum
33
sudo: false
44
matrix:
55
include:
6-
- os: linux
7-
dist: trusty
8-
sudo: required
9-
go: 1.7.x
10-
script:
11-
- sudo modprobe fuse
12-
- sudo chmod 666 /dev/fuse
13-
- sudo chown root:$USER /etc/fuse.conf
14-
- go run build/ci.go install
15-
- go run build/ci.go test -coverage
16-
176
- os: linux
187
dist: trusty
198
sudo: required

‎build/ci.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ func doInstall(cmdline []string) {
182182
// Check Go version. People regularly open issues about compilation
183183
// failure with outdated Go. This should save them the trouble.
184184
if !strings.Contains(runtime.Version(), "devel") {
185-
// Figure out the minor version number since we can't textually compare (1.10 < 1.7)
185+
// Figure out the minor version number since we can't textually compare (1.10 < 1.8)
186186
var minor int
187187
fmt.Sscanf(strings.TrimPrefix(runtime.Version(), "go1."), "%d", &minor)
188188

189-
if minor < 7 {
189+
if minor < 8 {
190190
log.Println("You have Go version", runtime.Version())
191-
log.Println("go-ethereum requires at least Go version 1.7 and cannot")
191+
log.Println("go-ethereum requires at least Go version 1.8 and cannot")
192192
log.Println("be compiled with an earlier version. Please upgrade your Go installation.")
193193
os.Exit(1)
194194
}

‎consensus/ethash/algorithm.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ethash
1919
import (
2020
"encoding/binary"
2121
"hash"
22+
"math/big"
2223
"reflect"
2324
"runtime"
2425
"sync"
@@ -47,6 +48,48 @@ const (
4748
loopAccesses = 64 // Number of accesses in hashimoto loop
4849
)
4950

51+
// cacheSize returns the size of the ethash verification cache that belongs to a certain
52+
// block number.
53+
func cacheSize(block uint64) uint64 {
54+
epoch := int(block / epochLength)
55+
if epoch < maxEpoch {
56+
return cacheSizes[epoch]
57+
}
58+
return calcCacheSize(epoch)
59+
}
60+
61+
// calcCacheSize calculates the cache size for epoch. The cache size grows linearly,
62+
// however, we always take the highest prime below the linearly growing threshold in order
63+
// to reduce the risk of accidental regularities leading to cyclic behavior.
64+
func calcCacheSize(epoch int) uint64 {
65+
size := cacheInitBytes + cacheGrowthBytes*uint64(epoch) - hashBytes
66+
for !new(big.Int).SetUint64(size / hashBytes).ProbablyPrime(1) { // Always accurate for n < 2^64
67+
size -= 2 * hashBytes
68+
}
69+
return size
70+
}
71+
72+
// datasetSize returns the size of the ethash mining dataset that belongs to a certain
73+
// block number.
74+
func datasetSize(block uint64) uint64 {
75+
epoch := int(block / epochLength)
76+
if epoch < maxEpoch {
77+
return datasetSizes[epoch]
78+
}
79+
return calcDatasetSize(epoch)
80+
}
81+
82+
// calcDatasetSize calculates the dataset size for epoch. The dataset size grows linearly,
83+
// however, we always take the highest prime below the linearly growing threshold in order
84+
// to reduce the risk of accidental regularities leading to cyclic behavior.
85+
func calcDatasetSize(epoch int) uint64 {
86+
size := datasetInitBytes + datasetGrowthBytes*uint64(epoch) - mixBytes
87+
for !new(big.Int).SetUint64(size / mixBytes).ProbablyPrime(1) { // Always accurate for n < 2^64
88+
size -= 2 * mixBytes
89+
}
90+
return size
91+
}
92+
5093
// hasher is a repetitive hasher allowing the same hash data structures to be
5194
// reused between hash runs instead of requiring new ones to be created.
5295
type hasher func(dest []byte, data []byte)

‎consensus/ethash/algorithm_go1.7.go‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎consensus/ethash/algorithm_go1.8.go‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎consensus/ethash/algorithm_go1.8_test.go‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎consensus/ethash/algorithm_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ import (
3030
"github.com/ethereum/go-ethereum/core/types"
3131
)
3232

33+
// Tests whether the dataset size calculator works correctly by cross checking the
34+
// hard coded lookup table with the value generated by it.
35+
func TestSizeCalculations(t *testing.T) {
36+
// Verify all the cache and dataset sizes from the lookup table.
37+
for epoch, want := range cacheSizes {
38+
if size := calcCacheSize(epoch); size != want {
39+
t.Errorf("cache %d: cache size mismatch: have %d, want %d", epoch, size, want)
40+
}
41+
}
42+
for epoch, want := range datasetSizes {
43+
if size := calcDatasetSize(epoch); size != want {
44+
t.Errorf("dataset %d: dataset size mismatch: have %d, want %d", epoch, size, want)
45+
}
46+
}
47+
}
48+
3349
// Tests that verification caches can be correctly generated.
3450
func TestCacheGeneration(t *testing.T) {
3551
tests := []struct {

‎consensus/ethash/consensus.go‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ var (
5353
errDuplicateUncle = errors.New("duplicate uncle")
5454
errUncleIsAncestor = errors.New("uncle is ancestor")
5555
errDanglingUncle = errors.New("uncle's parent is not ancestor")
56-
errNonceOutOfRange = errors.New("nonce out of range")
5756
errInvalidDifficulty = errors.New("non-positive difficulty")
5857
errInvalidMixDigest = errors.New("invalid mix digest")
5958
errInvalidPoW = errors.New("invalid proof-of-work")
@@ -474,18 +473,13 @@ func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Head
474473
if ethash.shared != nil {
475474
return ethash.shared.VerifySeal(chain, header)
476475
}
477-
// Sanity check that the block number is below the lookup table size (60M blocks)
478-
number := header.Number.Uint64()
479-
if number/epochLength >= maxEpoch {
480-
// Go < 1.7 cannot calculate new cache/dataset sizes (no fast prime check)
481-
return errNonceOutOfRange
482-
}
483476
// Ensure that we have a valid difficulty for the block
484477
if header.Difficulty.Sign() <= 0 {
485478
return errInvalidDifficulty
486479
}
487-
488480
// Recompute the digest and PoW value and verify against the header
481+
number := header.Number.Uint64()
482+
489483
cache := ethash.cache(number)
490484
size := datasetSize(number)
491485
if ethash.config.PowMode == ModeTest {

0 commit comments

Comments
 (0)