Skip to content

Commit 2b57a27

Browse files
holimanfjl
andauthored
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>
1 parent 59a48e0 commit 2b57a27

File tree

27 files changed

+100
-82
lines changed

27 files changed

+100
-82
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
138138
Transfer: core.Transfer,
139139
Coinbase: pre.Env.Coinbase,
140140
BlockNumber: new(big.Int).SetUint64(pre.Env.Number),
141-
Time: new(big.Int).SetUint64(pre.Env.Timestamp),
141+
Time: pre.Env.Timestamp,
142142
Difficulty: pre.Env.Difficulty,
143143
GasLimit: pre.Env.GasLimit,
144144
GetHash: getHash,

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func Transaction(ctx *cli.Context) error {
140140
}
141141
// Check intrinsic gas
142142
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
143-
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int))); err != nil {
143+
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(0)); err != nil {
144144
r.Error = err
145145
results = append(results, r)
146146
continue
@@ -172,7 +172,7 @@ func Transaction(ctx *cli.Context) error {
172172
r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits")
173173
}
174174
// Check whether the init code size has been exceeded.
175-
if chainConfig.IsShanghai(new(big.Int)) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
175+
if chainConfig.IsShanghai(0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
176176
r.Error = errors.New("max initcode size exceeded")
177177
}
178178
results = append(results, r)

cmd/evm/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func runCmd(ctx *cli.Context) error {
209209
GasPrice: flags.GlobalBig(ctx, PriceFlag.Name),
210210
Value: flags.GlobalBig(ctx, ValueFlag.Name),
211211
Difficulty: genesisConfig.Difficulty,
212-
Time: new(big.Int).SetUint64(genesisConfig.Timestamp),
212+
Time: genesisConfig.Timestamp,
213213
Coinbase: genesisConfig.Coinbase,
214214
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
215215
EVMConfig: vm.Config{

cmd/geth/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
159159
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
160160
stack, cfg := makeConfigNode(ctx)
161161
if ctx.IsSet(utils.OverrideShanghai.Name) {
162-
cfg.Eth.OverrideShanghai = flags.GlobalBig(ctx, utils.OverrideShanghai.Name)
162+
v := ctx.Uint64(utils.OverrideShanghai.Name)
163+
cfg.Eth.OverrideShanghai = &v
163164
}
164165
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
165166

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ var (
267267
Value: 2048,
268268
Category: flags.EthCategory,
269269
}
270-
OverrideShanghai = &flags.BigFlag{
270+
OverrideShanghai = &cli.Uint64Flag{
271271
Name: "override.shanghai",
272272
Usage: "Manually specify the Shanghai fork timestamp, overriding the bundled setting",
273273
Category: flags.EthCategory,

core/blockchain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4275,7 +4275,7 @@ func TestEIP3651(t *testing.T) {
42754275

42764276
gspec.Config.BerlinBlock = common.Big0
42774277
gspec.Config.LondonBlock = common.Big0
4278-
gspec.Config.ShanghaiTime = common.Big0
4278+
gspec.Config.ShanghaiTime = u64(0)
42794279
signer := types.LatestSigner(gspec.Config)
42804280

42814281
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {

core/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
6161
GetHash: GetHashFn(header, chain),
6262
Coinbase: beneficiary,
6363
BlockNumber: new(big.Int).Set(header.Number),
64-
Time: new(big.Int).SetUint64(header.Time),
64+
Time: header.Time,
6565
Difficulty: new(big.Int).Set(header.Difficulty),
6666
BaseFee: baseFee,
6767
GasLimit: header.GasLimit,

core/forkid/forkid.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
244244
// Gather all the fork block numbers via reflection
245245
kind := reflect.TypeOf(params.ChainConfig{})
246246
conf := reflect.ValueOf(config).Elem()
247-
247+
x := uint64(0)
248248
var (
249249
forksByBlock []uint64
250250
forksByTime []uint64
@@ -257,15 +257,15 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
257257
if !time && !strings.HasSuffix(field.Name, "Block") {
258258
continue
259259
}
260-
if field.Type != reflect.TypeOf(new(big.Int)) {
261-
continue
262-
}
260+
263261
// Extract the fork rule block number or timestamp and aggregate it
264-
rule := conf.Field(i).Interface().(*big.Int)
265-
if rule != nil {
266-
if time {
267-
forksByTime = append(forksByTime, rule.Uint64())
268-
} else {
262+
if field.Type == reflect.TypeOf(&x) {
263+
if rule := conf.Field(i).Interface().(*uint64); rule != nil {
264+
forksByTime = append(forksByTime, *rule)
265+
}
266+
}
267+
if field.Type == reflect.TypeOf(new(big.Int)) {
268+
if rule := conf.Field(i).Interface().(*big.Int); rule != nil {
269269
forksByBlock = append(forksByBlock, rule.Uint64())
270270
}
271271
}

core/forkid/forkid_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ package forkid
1919
import (
2020
"bytes"
2121
"math"
22-
"math/big"
2322
"testing"
2423

2524
"github.com/ethereum/go-ethereum/common"
2625
"github.com/ethereum/go-ethereum/params"
2726
"github.com/ethereum/go-ethereum/rlp"
2827
)
2928

29+
func u64(val uint64) *uint64 { return &val }
30+
3031
// TestCreation tests that different genesis and fork rule combinations result in
3132
// the correct fork ID.
3233
func TestCreation(t *testing.T) {
3334
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
3435
timestampedConfig := *params.MainnetChainConfig
35-
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
36+
timestampedConfig.ShanghaiTime = u64(1668000000)
3637

3738
type testcase struct {
3839
head uint64
@@ -201,7 +202,7 @@ func TestCreation(t *testing.T) {
201202
func TestValidation(t *testing.T) {
202203
// Temporary non-existent scenario TODO(karalabe): delete when Shanghai is enabled
203204
timestampedConfig := *params.MainnetChainConfig
204-
timestampedConfig.ShanghaiTime = big.NewInt(1668000000)
205+
timestampedConfig.ShanghaiTime = u64(1668000000)
205206

206207
tests := []struct {
207208
config *params.ChainConfig

core/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (e *GenesisMismatchError) Error() string {
269269

270270
// ChainOverrides contains the changes to chain config.
271271
type ChainOverrides struct {
272-
OverrideShanghai *big.Int
272+
OverrideShanghai *uint64
273273
}
274274

275275
// SetupGenesisBlock writes or updates the genesis block in db.

0 commit comments

Comments
 (0)