Skip to content

Commit c95a097

Browse files
committed
core/vm: make time field use uint64 ethereum#26474
1 parent b82b9cd commit c95a097

File tree

9 files changed

+14
-22
lines changed

9 files changed

+14
-22
lines changed

consensus/XDPoS/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type V2BlockInfo struct {
5151
ParentHash common.Hash
5252
Committed bool
5353
Miner common.Hash
54-
Timestamp *big.Int
54+
Timestamp uint64
5555
EncodedRLP string
5656
Error string
5757
}
@@ -297,7 +297,7 @@ func (api *API) GetV2BlockByHeader(header *types.Header, uncle bool) *V2BlockInf
297297
Round: round,
298298
Committed: committed,
299299
Miner: header.Coinbase.Hash(),
300-
Timestamp: new(big.Int).SetUint64(header.Time),
300+
Timestamp: header.Time,
301301
EncodedRLP: base64.StdEncoding.EncodeToString(encodeBytes),
302302
}
303303
return block

core/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewEVMBlockContext(header *types.Header, chain consensus.ChainContext, auth
5050
GetHash: GetHashFn(header, chain),
5151
Coinbase: beneficiary,
5252
BlockNumber: new(big.Int).Set(header.Number),
53-
Time: new(big.Int).SetUint64(header.Time),
53+
Time: header.Time,
5454
Difficulty: new(big.Int).Set(header.Difficulty),
5555
BaseFee: baseFee,
5656
GasLimit: header.GasLimit,

core/vm/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type BlockContext struct {
7272
Coinbase common.Address // Provides information for COINBASE
7373
GasLimit uint64 // Provides information for GASLIMIT
7474
BlockNumber *big.Int // Provides information for NUMBER
75-
Time *big.Int // Provides information for TIME
75+
Time uint64 // Provides information for TIME
7676
Difficulty *big.Int // Provides information for DIFFICULTY
7777
BaseFee *big.Int // Provides information for BASEFEE (0 if vm runs with NoBaseFee flag and 0 gas price)
7878
Random *common.Hash // Provides information for PREVRANDAO

core/vm/instructions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ func opCoinbase(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
469469
}
470470

471471
func opTimestamp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
472-
v, _ := uint256.FromBig(interpreter.evm.Context.Time)
473-
scope.Stack.push(v)
472+
scope.Stack.push(new(uint256.Int).SetUint64(interpreter.evm.Context.Time))
474473
return nil, nil
475474
}
476475

core/vm/runtime/runtime.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package runtime
1919
import (
2020
"math"
2121
"math/big"
22-
"time"
2322

2423
"github.com/XinFinOrg/XDPoSChain/common"
2524
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
@@ -38,7 +37,7 @@ type Config struct {
3837
Origin common.Address
3938
Coinbase common.Address
4039
BlockNumber *big.Int
41-
Time *big.Int
40+
Time uint64
4241
GasLimit uint64
4342
GasPrice *big.Int
4443
Value *big.Int
@@ -77,9 +76,6 @@ func setDefaults(cfg *Config) {
7776
if cfg.Difficulty == nil {
7877
cfg.Difficulty = new(big.Int)
7978
}
80-
if cfg.Time == nil {
81-
cfg.Time = big.NewInt(time.Now().Unix())
82-
}
8379
if cfg.GasLimit == 0 {
8480
cfg.GasLimit = math.MaxUint64
8581
}

core/vm/runtime/runtime_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ func TestDefaults(t *testing.T) {
4343
t.Error("expected difficulty to be non nil")
4444
}
4545

46-
if cfg.Time == nil {
47-
t.Error("expected time to be non nil")
48-
}
4946
if cfg.GasLimit == 0 {
5047
t.Error("didn't expect gaslimit to be zero")
5148
}
@@ -171,7 +168,7 @@ func benchmarkEVM_Create(bench *testing.B, code string) {
171168
State: statedb,
172169
GasLimit: 10000000,
173170
Difficulty: big.NewInt(0x200000),
174-
Time: new(big.Int).SetUint64(0),
171+
Time: 0,
175172
Coinbase: common.Address{},
176173
BlockNumber: new(big.Int).SetUint64(1),
177174
ChainConfig: &params.ChainConfig{

eth/tracers/testing/calltrace_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
104104
Transfer: core.Transfer,
105105
Coinbase: test.Context.Miner,
106106
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
107-
Time: new(big.Int).SetUint64(uint64(test.Context.Time)),
107+
Time: uint64(test.Context.Time),
108108
Difficulty: (*big.Int)(test.Context.Difficulty),
109109
GasLimit: uint64(test.Context.GasLimit),
110110
}
@@ -214,7 +214,7 @@ func benchTracer(tracerName string, test *callTracerTest, b *testing.B) {
214214
Transfer: core.Transfer,
215215
Coinbase: test.Context.Miner,
216216
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
217-
Time: new(big.Int).SetUint64(uint64(test.Context.Time)),
217+
Time: uint64(test.Context.Time),
218218
Difficulty: (*big.Int)(test.Context.Difficulty),
219219
GasLimit: uint64(test.Context.GasLimit),
220220
}
@@ -286,7 +286,7 @@ func testContractTracer(tracerName string, dirPath string, t *testing.T) {
286286
Transfer: core.Transfer,
287287
Coinbase: test.Context.Miner,
288288
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
289-
Time: new(big.Int).SetUint64(uint64(test.Context.Time)),
289+
Time: uint64(test.Context.Time),
290290
Difficulty: (*big.Int)(test.Context.Difficulty),
291291
GasLimit: uint64(test.Context.GasLimit),
292292
}

eth/tracers/tracers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestZeroValueToNotExitCall(t *testing.T) {
127127
Transfer: core.Transfer,
128128
Coinbase: common.Address{},
129129
BlockNumber: new(big.Int).SetUint64(8000000),
130-
Time: new(big.Int).SetUint64(5),
130+
Time: 5,
131131
Difficulty: big.NewInt(0x30000),
132132
GasLimit: uint64(6000000),
133133
}
@@ -211,7 +211,7 @@ func TestPrestateTracerCreate2(t *testing.T) {
211211
Transfer: core.Transfer,
212212
Coinbase: common.Address{},
213213
BlockNumber: new(big.Int).SetUint64(8000000),
214-
Time: new(big.Int).SetUint64(5),
214+
Time: 5,
215215
Difficulty: big.NewInt(0x30000),
216216
GasLimit: uint64(6000000),
217217
}
@@ -304,7 +304,7 @@ func BenchmarkTransactionTrace(b *testing.B) {
304304
Transfer: core.Transfer,
305305
Coinbase: common.Address{},
306306
BlockNumber: new(big.Int).SetUint64(uint64(5)),
307-
Time: new(big.Int).SetUint64(uint64(5)),
307+
Time: 5,
308308
Difficulty: big.NewInt(0xffffffff),
309309
GasLimit: gas,
310310
BaseFee: big.NewInt(8),

tests/vm_test_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM {
143143
GetHash: vmTestBlockHash,
144144
Coinbase: t.json.Env.Coinbase,
145145
BlockNumber: new(big.Int).SetUint64(t.json.Env.Number),
146-
Time: new(big.Int).SetUint64(t.json.Env.Timestamp),
146+
Time: t.json.Env.Timestamp,
147147
GasLimit: t.json.Env.GasLimit,
148148
Difficulty: t.json.Env.Difficulty,
149149
}

0 commit comments

Comments
 (0)