From 1d4b72d0e647e7494ff678513e237b9f0fbfb02d Mon Sep 17 00:00:00 2001 From: lightclient Date: Fri, 18 Jul 2025 08:55:20 -0600 Subject: [PATCH] params,internal: add eth_config --- internal/ethapi/api.go | 28 ++++++++++++++++++ internal/jsre/deps/web3.js | 4 +++ params/config.go | 59 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 362125dd63..f2c7345186 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1153,6 +1153,34 @@ func (api *BlockChainAPI) CreateAccessList(ctx context.Context, args Transaction return result, nil } +type config struct { + ActivationTime uint64 `json:"activationTime"` + BlobSchedule *params.BlobConfig `json:"blobSchedule"` + ChainId *hexutil.Big `json:"chainId"` + Precompiles map[common.Address]string `json:"precompiles"` + SystemContracts map[string]common.Address `json:"systemContracts"` +} + +// Config implements the EIP-7910 eth_config method. +func (api *BlockChainAPI) Config(ctx context.Context) config { + var ( + c = api.b.ChainConfig() + h = api.b.CurrentBlock() + rules = c.Rules(h.Number, true, h.Time) + 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)), + ChainId: (*hexutil.Big)(c.ChainID), + Precompiles: precompiles, + SystemContracts: c.ActiveSystemContracts(h.Time), + } +} + // AccessList creates an access list for the given transaction. // If the accesslist creation fails an error is returned. // If the transaction itself fails, an vmErr is returned. diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 3a19dce06c..91a05eda75 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -5490,6 +5490,10 @@ var properties = function () { new Property({ name: 'protocolVersion', getter: 'eth_protocolVersion' + }), + new Property({ + name: 'config', + getter: 'eth_config' }) ]; }; diff --git a/params/config.go b/params/config.go index 85619bbe22..f53709b5f3 100644 --- a/params/config.go +++ b/params/config.go @@ -985,6 +985,65 @@ 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 { + case forks.Osaka: + return DefaultOsakaBlobConfig + case forks.Prague: + return DefaultPragueBlobConfig + case forks.Cancun: + return DefaultCancunBlobConfig + default: + return nil + } +} + +// ActiveSystemContracts returns the currently active system contracts at the +// given timestamp. +func (c *ChainConfig) ActiveSystemContracts(time uint64) map[string]common.Address { + fork := c.LatestFork(time) + active := make(map[string]common.Address) + if fork >= forks.Osaka { + // no new system contracts + } + if fork >= forks.Prague { + active["CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS"] = ConsolidationQueueAddress + active["DEPOSIT_CONTRACT_ADDRESS"] = c.DepositContractAddress + active["HISTORY_STORAGE_ADDRESS"] = HistoryStorageAddress + active["WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS"] = WithdrawalQueueAddress + } + if fork >= forks.Cancun { + active["BEACON_ROOTS_ADDRESS"] = BeaconRootsAddress + } + return active +} + // Timestamp returns the timestamp associated with the fork or returns nil if // the fork isn't defined or isn't a time-based fork. func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 {