core/vm: make time field use uint64 #26474 (#1319)

This commit is contained in:
Daniel Liu 2025-08-20 15:22:06 +08:00 committed by GitHub
parent 4ec6e8cd58
commit 9c6816eab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 14 additions and 22 deletions

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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: &params.ChainConfig{

View file

@ -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),
}

View file

@ -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),

View file

@ -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,
}