params,internal/ethapi: add current, next, and last to eth_config

This commit is contained in:
lightclient 2025-08-19 15:21:26 -06:00
parent 5de62c7279
commit 42c3141489
No known key found for this signature in database
GPG key ID: 657913021EF45A6A
2 changed files with 46 additions and 38 deletions

View file

@ -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 (
c = api.b.ChainConfig()
h = api.b.CurrentBlock()
rules = c.Rules(h.Number, true, h.Time)
rules = c.Rules(c.LondonBlock, true, t)
precompiles = make(map[common.Address]string)
)
for addr, c := range vm.ActivePrecompiledContracts(rules) {
precompiles[addr] = c.Name()
}
return config{
ActivationTime: c.NextForkTime(h.Time),
BlobSchedule: c.BlobConfig(c.LatestFork(h.Time)),
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(h.Time),
SystemContracts: c.ActiveSystemContracts(t),
}
}
var (
c = api.b.ChainConfig()
t = api.b.CurrentHeader().Time
)
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)))),
}
// 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.

View file

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