params,internal: add eth_config

This commit is contained in:
lightclient 2025-07-18 08:55:20 -06:00
parent 4726af0f83
commit 1d4b72d0e6
No known key found for this signature in database
GPG key ID: 657913021EF45A6A
3 changed files with 91 additions and 0 deletions

View file

@ -1153,6 +1153,34 @@ func (api *BlockChainAPI) CreateAccessList(ctx context.Context, args Transaction
return result, nil 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. // AccessList creates an access list for the given transaction.
// If the accesslist creation fails an error is returned. // If the accesslist creation fails an error is returned.
// If the transaction itself fails, an vmErr is returned. // If the transaction itself fails, an vmErr is returned.

View file

@ -5490,6 +5490,10 @@ var properties = function () {
new Property({ new Property({
name: 'protocolVersion', name: 'protocolVersion',
getter: 'eth_protocolVersion' getter: 'eth_protocolVersion'
}),
new Property({
name: 'config',
getter: 'eth_config'
}) })
]; ];
}; };

View file

@ -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 // Timestamp returns the timestamp associated with the fork or returns nil if
// the fork isn't defined or isn't a time-based fork. // the fork isn't defined or isn't a time-based fork.
func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 { func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 {