From 42c3141489ca8b3f5f04b7b6c270a375785320ee Mon Sep 17 00:00:00 2001 From: lightclient Date: Tue, 19 Aug 2025 15:21:26 -0600 Subject: [PATCH] params,internal/ethapi: add current, next, and last to eth_config --- internal/ethapi/api.go | 59 ++++++++++++++++++++++++++++++++---------- params/config.go | 25 ------------------ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f2c7345186..f5472e0c74 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/forkid" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -1157,28 +1158,60 @@ type config struct { ActivationTime uint64 `json:"activationTime"` BlobSchedule *params.BlobConfig `json:"blobSchedule"` ChainId *hexutil.Big `json:"chainId"` + ForkId hexutil.Bytes `json:"forkId"` Precompiles map[common.Address]string `json:"precompiles"` SystemContracts map[string]common.Address `json:"systemContracts"` } +type configResponse struct { + Current *config `json:"current"` + Next *config `json:"next"` + Last *config `json:"last"` +} + // Config implements the EIP-7910 eth_config method. -func (api *BlockChainAPI) Config(ctx context.Context) config { +func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) { + genesis, err := api.b.BlockByNumber(ctx, 0) + if err != nil { + return nil, fmt.Errorf("unable to load genesis: %w", err) + } + assemble := func(c *params.ChainConfig, ts *uint64) *config { + if ts == nil { + return nil + } + t := *ts + + var ( + rules = c.Rules(c.LondonBlock, true, t) + precompiles = make(map[common.Address]string) + ) + for addr, c := range vm.ActivePrecompiledContracts(rules) { + precompiles[addr] = c.Name() + } + forkid := forkid.NewID(c, genesis, ^uint64(0), t).Hash + return &config{ + ActivationTime: t, + BlobSchedule: c.BlobConfig(c.LatestFork(t)), + ChainId: (*hexutil.Big)(c.ChainID), + ForkId: forkid[:], + Precompiles: precompiles, + SystemContracts: c.ActiveSystemContracts(t), + } + } var ( - c = api.b.ChainConfig() - h = api.b.CurrentBlock() - rules = c.Rules(h.Number, true, h.Time) - precompiles = make(map[common.Address]string) + c = api.b.ChainConfig() + t = api.b.CurrentHeader().Time ) - for addr, c := range vm.ActivePrecompiledContracts(rules) { - precompiles[addr] = c.Name() + resp := configResponse{ + Next: assemble(c, c.Timestamp(c.LatestFork(t)+1)), + Current: assemble(c, c.Timestamp(c.LatestFork(t))), + Last: assemble(c, c.Timestamp(c.LatestFork(^uint64(0)))), } - return config{ - ActivationTime: c.NextForkTime(h.Time), - BlobSchedule: c.BlobConfig(c.LatestFork(h.Time)), - ChainId: (*hexutil.Big)(c.ChainID), - Precompiles: precompiles, - SystemContracts: c.ActiveSystemContracts(h.Time), + // Nil out last if no future-fork is configured. + if resp.Next == nil { + resp.Last = nil } + return &resp, nil } // AccessList creates an access list for the given transaction. diff --git a/params/config.go b/params/config.go index f53709b5f3..7576170d26 100644 --- a/params/config.go +++ b/params/config.go @@ -985,31 +985,6 @@ func (c *ChainConfig) LatestFork(time uint64) forks.Fork { } } -// NextFork returns the next fork to activate or nil if the last defined fork is -// active. -func (c *ChainConfig) NextForkTime(time uint64) uint64 { - // Assume last non-time-based fork has passed. - london := c.LondonBlock - next := newUint64(0) - - switch { - case c.IsOsaka(london, time): - next = c.OsakaTime - case c.IsPrague(london, time): - next = c.OsakaTime - case c.IsCancun(london, time): - next = c.PragueTime - case c.IsShanghai(london, time): - next = c.CancunTime - default: - next = c.ShanghaiTime - } - if next == nil { - return 0 - } - return *next -} - // BlobConfig returns the blob config associated with the provided fork. func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig { switch fork {