@@ -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.
0 commit comments