diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-11-13 19:47:27 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-01-03 20:45:35 +0800 |
commit | 6f69cdd109b1dd692b8dfb15e7c53d2051fbc946 (patch) | |
tree | c92974f8b82209073ad1ee3faec6e149f834bf69 /consensus | |
parent | b8caba97099ee5eed33c3b80dd4ea540722e7d8f (diff) | |
download | dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.gz dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.zst dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.zip |
all: switch gas limits from big.Int to uint64
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 { |