diff options
Diffstat (limited to 'consensus')
-rw-r--r-- | consensus/ethash/algorithm_test.go | 4 | ||||
-rw-r--r-- | consensus/ethash/consensus.go | 24 |
2 files changed, 14 insertions, 14 deletions
diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go index 7765ff9fe..a54f3b582 100644 --- a/consensus/ethash/algorithm_test.go +++ b/consensus/ethash/algorithm_test.go @@ -688,8 +688,8 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) { TxHash: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), ReceiptHash: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), Difficulty: big.NewInt(167925187834220), - GasLimit: big.NewInt(4015682), - GasUsed: big.NewInt(0), + GasLimit: 4015682, + GasUsed: 0, Time: big.NewInt(1488928920), Extra: []byte("www.bw.com"), MixDigest: common.HexToHash("0x3e140b0784516af5e5ec6730f2fb20cca22f32be399b9e4ad77d32541f798cd0"), diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 0a2f1520e..0af68c31a 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -246,24 +246,24 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent * return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected) } // Verify that the gas limit is <= 2^63-1 - if header.GasLimit.Cmp(math.MaxBig63) > 0 { - return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, math.MaxBig63) + cap := uint64(0x7fffffffffffffff) + if header.GasLimit > cap { + return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, cap) } // Verify that the gasUsed is <= gasLimit - if header.GasUsed.Cmp(header.GasLimit) > 0 { - return fmt.Errorf("invalid gasUsed: have %v, gasLimit %v", header.GasUsed, header.GasLimit) + if header.GasUsed > header.GasLimit { + return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit) } // Verify that the gas limit remains within allowed bounds - diff := new(big.Int).Set(parent.GasLimit) - diff = diff.Sub(diff, header.GasLimit) - diff.Abs(diff) - - limit := new(big.Int).Set(parent.GasLimit) - limit = limit.Div(limit, params.GasLimitBoundDivisor) + diff := int64(parent.GasLimit) - int64(header.GasLimit) + if diff < 0 { + diff *= -1 + } + limit := parent.GasLimit / params.GasLimitBoundDivisor - if diff.Cmp(limit) >= 0 || header.GasLimit.Cmp(params.MinGasLimit) < 0 { - return fmt.Errorf("invalid gas limit: have %v, want %v += %v", header.GasLimit, parent.GasLimit, limit) + if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit { + return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit) } // Verify that the block number is parent's +1 if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 { |