Skip to content

Commit 756304b

Browse files
committed
params,internal/ethapi: add current, next, and last to eth_config
1 parent f370035 commit 756304b

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

internal/ethapi/api.go

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/ethereum/go-ethereum/consensus"
3535
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
3636
"github.com/ethereum/go-ethereum/core"
37+
"github.com/ethereum/go-ethereum/core/forkid"
3738
"github.com/ethereum/go-ethereum/core/state"
3839
"github.com/ethereum/go-ethereum/core/types"
3940
"github.com/ethereum/go-ethereum/core/vm"
@@ -1139,28 +1140,60 @@ type config struct {
11391140
ActivationTime uint64 `json:"activationTime"`
11401141
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
11411142
ChainId *hexutil.Big `json:"chainId"`
1143+
ForkId hexutil.Bytes `json:"forkId"`
11421144
Precompiles map[common.Address]string `json:"precompiles"`
11431145
SystemContracts map[string]common.Address `json:"systemContracts"`
11441146
}
11451147

1148+
type configResponse struct {
1149+
Current *config `json:"current"`
1150+
Next *config `json:"next"`
1151+
Last *config `json:"last"`
1152+
}
1153+
11461154
// Config implements the EIP-7910 eth_config method.
1147-
func (api *BlockChainAPI) Config(ctx context.Context) config {
1155+
func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
1156+
genesis, err := api.b.BlockByNumber(ctx, 0)
1157+
if err != nil {
1158+
return nil, fmt.Errorf("unable to load genesis: %w", err)
1159+
}
1160+
assemble := func(c *params.ChainConfig, ts *uint64) *config {
1161+
if ts == nil {
1162+
return nil
1163+
}
1164+
t := *ts
1165+
1166+
var (
1167+
rules = c.Rules(c.LondonBlock, true, t)
1168+
precompiles = make(map[common.Address]string)
1169+
)
1170+
for addr, c := range vm.ActivePrecompiledContracts(rules) {
1171+
precompiles[addr] = c.Name()
1172+
}
1173+
forkid := forkid.NewID(c, genesis, ^uint64(0), t).Hash
1174+
return &config{
1175+
ActivationTime: t,
1176+
BlobSchedule: c.BlobConfig(c.LatestFork(t)),
1177+
ChainId: (*hexutil.Big)(c.ChainID),
1178+
ForkId: forkid[:],
1179+
Precompiles: precompiles,
1180+
SystemContracts: c.ActiveSystemContracts(t),
1181+
}
1182+
}
11481183
var (
1149-
c = api.b.ChainConfig()
1150-
h = api.b.CurrentBlock()
1151-
rules = c.Rules(h.Number, true, h.Time)
1152-
precompiles = make(map[common.Address]string)
1184+
c = api.b.ChainConfig()
1185+
t = api.b.CurrentHeader().Time
11531186
)
1154-
for addr, c := range vm.ActivePrecompiledContracts(rules) {
1155-
precompiles[addr] = c.Name()
1187+
resp := configResponse{
1188+
Next: assemble(c, c.Timestamp(c.LatestFork(t)+1)),
1189+
Current: assemble(c, c.Timestamp(c.LatestFork(t))),
1190+
Last: assemble(c, c.Timestamp(c.LatestFork(^uint64(0)))),
11561191
}
1157-
return config{
1158-
ActivationTime: c.NextForkTime(h.Time),
1159-
BlobSchedule: c.BlobConfig(c.LatestFork(h.Time)),
1160-
ChainId: (*hexutil.Big)(c.ChainID),
1161-
Precompiles: precompiles,
1162-
SystemContracts: c.ActiveSystemContracts(h.Time),
1192+
// Nil out last if no future-fork is configured.
1193+
if resp.Next == nil {
1194+
resp.Last = nil
11631195
}
1196+
return &resp, nil
11641197
}
11651198

11661199
// AccessList creates an access list for the given transaction.

params/config.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -985,31 +985,6 @@ func (c *ChainConfig) LatestFork(time uint64) forks.Fork {
985985
}
986986
}
987987

988-
// NextFork returns the next fork to activate or nil if the last defined fork is
989-
// active.
990-
func (c *ChainConfig) NextForkTime(time uint64) uint64 {
991-
// Assume last non-time-based fork has passed.
992-
london := c.LondonBlock
993-
next := newUint64(0)
994-
995-
switch {
996-
case c.IsOsaka(london, time):
997-
next = c.OsakaTime
998-
case c.IsPrague(london, time):
999-
next = c.OsakaTime
1000-
case c.IsCancun(london, time):
1001-
next = c.PragueTime
1002-
case c.IsShanghai(london, time):
1003-
next = c.CancunTime
1004-
default:
1005-
next = c.ShanghaiTime
1006-
}
1007-
if next == nil {
1008-
return 0
1009-
}
1010-
return *next
1011-
}
1012-
1013988
// BlobConfig returns the blob config associated with the provided fork.
1014989
func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig {
1015990
switch fork {

0 commit comments

Comments
 (0)