all: make timestamp-based fork checks based on uint64 (#26474)
This PR changes the API so that uint64 is used for fork timestamps. It's a good choice because types.Header also uses uint64 for time. Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
co-authored by
Felix Lange
parent
59a48e0289
commit
2b57a27d9e
@@ -4275,7 +4275,7 @@ func TestEIP3651(t *testing.T) {
|
||||
|
||||
gspec.Config.BerlinBlock = common.Big0
|
||||
gspec.Config.LondonBlock = common.Big0
|
||||
gspec.Config.ShanghaiTime = common.Big0
|
||||
gspec.Config.ShanghaiTime = u64(0)
|
||||
signer := types.LatestSigner(gspec.Config)
|
||||
|
||||
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
|
||||
|
||||
+1
-1
@@ -61,7 +61,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,
|
||||
|
||||
@@ -244,7 +244,7 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
|
||||
// Gather all the fork block numbers via reflection
|
||||
kind := reflect.TypeOf(params.ChainConfig{})
|
||||
conf := reflect.ValueOf(config).Elem()
|
||||
|
||||
x := uint64(0)
|
||||
var (
|
||||
forksByBlock []uint64
|
||||
forksByTime []uint64
|
||||
@@ -257,15 +257,15 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
|
||||
if !time && !strings.HasSuffix(field.Name, "Block") {
|
||||
continue
|
||||
}
|
||||
if field.Type != reflect.TypeOf(new(big.Int)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Extract the fork rule block number or timestamp and aggregate it
|
||||
rule := conf.Field(i).Interface().(*big.Int)
|
||||
if rule != nil {
|
||||
if time {
|
||||
forksByTime = append(forksByTime, rule.Uint64())
|
||||
} else {
|
||||
if field.Type == reflect.TypeOf(&x) {
|
||||
if rule := conf.Field(i).Interface().(*uint64); rule != nil {
|
||||
forksByTime = append(forksByTime, *rule)
|
||||
}
|
||||
}
|
||||
if field.Type == reflect.TypeOf(new(big.Int)) {
|
||||
if rule := conf.Field(i).Interface().(*big.Int); rule != nil {
|
||||
forksByBlock = append(forksByBlock, rule.Uint64())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package forkid
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -27,12 +26,14 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
func u64(val uint64) *uint64 { return &val }
|
||||
|
||||
// TestCreation tests that different genesis and fork rule combinations result in
|
||||
// the correct fork ID.
|
||||
func TestCreation(t *testing.T) {
|
||||
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
|
||||
timestampedConfig := *params.MainnetChainConfig
|
||||
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
|
||||
timestampedConfig.ShanghaiTime = u64(1668000000)
|
||||
|
||||
type testcase struct {
|
||||
head uint64
|
||||
@@ -201,7 +202,7 @@ func TestCreation(t *testing.T) {
|
||||
func TestValidation(t *testing.T) {
|
||||
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
|
||||
timestampedConfig := *params.MainnetChainConfig
|
||||
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
|
||||
timestampedConfig.ShanghaiTime = u64(1668000000)
|
||||
|
||||
tests := []struct {
|
||||
config *params.ChainConfig
|
||||
|
||||
+1
-1
@@ -269,7 +269,7 @@ func (e *GenesisMismatchError) Error() string {
|
||||
|
||||
// ChainOverrides contains the changes to chain config.
|
||||
type ChainOverrides struct {
|
||||
OverrideShanghai *big.Int
|
||||
OverrideShanghai *uint64
|
||||
}
|
||||
|
||||
// SetupGenesisBlock writes or updates the genesis block in db.
|
||||
|
||||
@@ -35,6 +35,8 @@ import (
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
func u64(val uint64) *uint64 { return &val }
|
||||
|
||||
// TestStateProcessorErrors tests the output from the 'core' errors
|
||||
// as defined in core/error.go. These errors are generated when the
|
||||
// blockchain imports bad blocks, meaning blocks which have valid headers but
|
||||
@@ -327,7 +329,7 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||
ArrowGlacierBlock: big.NewInt(0),
|
||||
GrayGlacierBlock: big.NewInt(0),
|
||||
MergeNetsplitBlock: big.NewInt(0),
|
||||
ShanghaiTime: big.NewInt(0),
|
||||
ShanghaiTime: u64(0),
|
||||
},
|
||||
Alloc: GenesisAlloc{
|
||||
common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): GenesisAccount{
|
||||
|
||||
@@ -1312,7 +1312,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
|
||||
pool.istanbul = pool.chainconfig.IsIstanbul(next)
|
||||
pool.eip2718 = pool.chainconfig.IsBerlin(next)
|
||||
pool.eip1559 = pool.chainconfig.IsLondon(next)
|
||||
pool.shanghai = pool.chainconfig.IsShanghai(big.NewInt(time.Now().Unix()))
|
||||
pool.shanghai = pool.chainconfig.IsShanghai(uint64(time.Now().Unix()))
|
||||
}
|
||||
|
||||
// promoteExecutables moves transactions that have become processable from the
|
||||
|
||||
+1
-1
@@ -71,7 +71,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
|
||||
Random *common.Hash // Provides information for PREVRANDAO
|
||||
|
||||
@@ -460,8 +460,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
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package runtime
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
@@ -37,7 +36,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
|
||||
@@ -74,9 +73,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
|
||||
}
|
||||
|
||||
@@ -48,9 +48,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")
|
||||
}
|
||||
@@ -174,7 +171,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{
|
||||
|
||||
Reference in New Issue
Block a user