diff --git a/consensus/XDPoS/api.go b/consensus/XDPoS/api.go index 10f9e949ebcf..b951f35f2692 100644 --- a/consensus/XDPoS/api.go +++ b/consensus/XDPoS/api.go @@ -51,7 +51,7 @@ type V2BlockInfo struct { ParentHash common.Hash Committed bool Miner common.Hash - Timestamp *big.Int + Timestamp uint64 EncodedRLP string Error string } @@ -297,7 +297,7 @@ func (api *API) GetV2BlockByHeader(header *types.Header, uncle bool) *V2BlockInf Round: round, Committed: committed, Miner: header.Coinbase.Hash(), - Timestamp: new(big.Int).SetUint64(header.Time), + Timestamp: header.Time, EncodedRLP: base64.StdEncoding.EncodeToString(encodeBytes), } return block diff --git a/core/evm.go b/core/evm.go index bbf6249cd57f..d65ac2a30517 100644 --- a/core/evm.go +++ b/core/evm.go @@ -60,7 +60,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common GetHash: GetHashFn(header, chain), Coinbase: beneficiary, BlockNumber: new(big.Int).Set(header.Number), - Time: new(big.Int).SetUint64(header.Time), + Time: header.Time, Difficulty: new(big.Int).Set(header.Difficulty), BaseFee: baseFee, GasLimit: header.GasLimit, diff --git a/core/vm/evm.go b/core/vm/evm.go index 1b1283dba060..b215ff9d72f2 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -72,7 +72,7 @@ type BlockContext struct { Coinbase common.Address // Provides information for COINBASE GasLimit uint64 // Provides information for GASLIMIT BlockNumber *big.Int // Provides information for NUMBER - Time *big.Int // Provides information for TIME + Time uint64 // Provides information for TIME Difficulty *big.Int // Provides information for DIFFICULTY BaseFee *big.Int // Provides information for BASEFEE (0 if vm runs with NoBaseFee flag and 0 gas price) Random *common.Hash // Provides information for PREVRANDAO diff --git a/core/vm/instructions.go b/core/vm/instructions.go index e29513a7faf7..5f83525b5bda 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -464,8 +464,7 @@ func opCoinbase(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ } func opTimestamp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { - v, _ := uint256.FromBig(interpreter.evm.Context.Time) - scope.Stack.push(v) + scope.Stack.push(new(uint256.Int).SetUint64(interpreter.evm.Context.Time)) return nil, nil } diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 757498ce5df5..b0d14ebfe8b4 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -19,7 +19,6 @@ package runtime import ( "math" "math/big" - "time" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core/rawdb" @@ -38,7 +37,7 @@ type Config struct { Origin common.Address Coinbase common.Address BlockNumber *big.Int - Time *big.Int + Time uint64 GasLimit uint64 GasPrice *big.Int Value *big.Int @@ -77,9 +76,6 @@ func setDefaults(cfg *Config) { if cfg.Difficulty == nil { cfg.Difficulty = new(big.Int) } - if cfg.Time == nil { - cfg.Time = big.NewInt(time.Now().Unix()) - } if cfg.GasLimit == 0 { cfg.GasLimit = math.MaxUint64 } diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index 386b42b5bcdb..ce1cdeca94af 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -43,9 +43,6 @@ func TestDefaults(t *testing.T) { t.Error("expected difficulty to be non nil") } - if cfg.Time == nil { - t.Error("expected time to be non nil") - } if cfg.GasLimit == 0 { t.Error("didn't expect gaslimit to be zero") } @@ -171,7 +168,7 @@ func benchmarkEVM_Create(bench *testing.B, code string) { State: statedb, GasLimit: 10000000, Difficulty: big.NewInt(0x200000), - Time: new(big.Int).SetUint64(0), + Time: 0, Coinbase: common.Address{}, BlockNumber: new(big.Int).SetUint64(1), ChainConfig: ¶ms.ChainConfig{ diff --git a/eth/tracers/testing/calltrace_test.go b/eth/tracers/testing/calltrace_test.go index f770b34a5e83..46af70e411a8 100644 --- a/eth/tracers/testing/calltrace_test.go +++ b/eth/tracers/testing/calltrace_test.go @@ -104,7 +104,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) { Transfer: core.Transfer, Coinbase: test.Context.Miner, BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)), - Time: new(big.Int).SetUint64(uint64(test.Context.Time)), + Time: uint64(test.Context.Time), Difficulty: (*big.Int)(test.Context.Difficulty), GasLimit: uint64(test.Context.GasLimit), } @@ -214,7 +214,7 @@ func benchTracer(tracerName string, test *callTracerTest, b *testing.B) { Transfer: core.Transfer, Coinbase: test.Context.Miner, BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)), - Time: new(big.Int).SetUint64(uint64(test.Context.Time)), + Time: uint64(test.Context.Time), Difficulty: (*big.Int)(test.Context.Difficulty), GasLimit: uint64(test.Context.GasLimit), } @@ -286,7 +286,7 @@ func testContractTracer(tracerName string, dirPath string, t *testing.T) { Transfer: core.Transfer, Coinbase: test.Context.Miner, BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)), - Time: new(big.Int).SetUint64(uint64(test.Context.Time)), + Time: uint64(test.Context.Time), Difficulty: (*big.Int)(test.Context.Difficulty), GasLimit: uint64(test.Context.GasLimit), } diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go index 845a3aee60cf..136a39641d39 100644 --- a/eth/tracers/tracers_test.go +++ b/eth/tracers/tracers_test.go @@ -127,7 +127,7 @@ func TestZeroValueToNotExitCall(t *testing.T) { Transfer: core.Transfer, Coinbase: common.Address{}, BlockNumber: new(big.Int).SetUint64(8000000), - Time: new(big.Int).SetUint64(5), + Time: 5, Difficulty: big.NewInt(0x30000), GasLimit: uint64(6000000), } @@ -211,7 +211,7 @@ func TestPrestateTracerCreate2(t *testing.T) { Transfer: core.Transfer, Coinbase: common.Address{}, BlockNumber: new(big.Int).SetUint64(8000000), - Time: new(big.Int).SetUint64(5), + Time: 5, Difficulty: big.NewInt(0x30000), GasLimit: uint64(6000000), } @@ -304,7 +304,7 @@ func BenchmarkTransactionTrace(b *testing.B) { Transfer: core.Transfer, Coinbase: common.Address{}, BlockNumber: new(big.Int).SetUint64(uint64(5)), - Time: new(big.Int).SetUint64(uint64(5)), + Time: 5, Difficulty: big.NewInt(0xffffffff), GasLimit: gas, BaseFee: big.NewInt(8), diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index e4a5b1ef8e64..a4bbc36a6866 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -143,7 +143,7 @@ func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM { GetHash: vmTestBlockHash, Coinbase: t.json.Env.Coinbase, BlockNumber: new(big.Int).SetUint64(t.json.Env.Number), - Time: new(big.Int).SetUint64(t.json.Env.Timestamp), + Time: t.json.Env.Timestamp, GasLimit: t.json.Env.GasLimit, Difficulty: t.json.Env.Difficulty, }