Skip to content

Commit 4271e3e

Browse files
committed
params,internal: add eth_config
1 parent 4f60e7a commit 4271e3e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

internal/ethapi/api.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,34 @@ func (api *BlockChainAPI) CreateAccessList(ctx context.Context, args Transaction
11351135
return result, nil
11361136
}
11371137

1138+
type config struct {
1139+
ActivationTime uint64 `json:"activationTime"`
1140+
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
1141+
ChainId *hexutil.Big `json:"chainId"`
1142+
Precompiles map[common.Address]string `json:"precompiles"`
1143+
SystemContracts map[string]common.Address `json:"systemContracts"`
1144+
}
1145+
1146+
// Config implements the EIP-7910 eth_config method.
1147+
func (api *BlockChainAPI) Config(ctx context.Context) config {
1148+
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)
1153+
)
1154+
for addr, c := range vm.ActivePrecompiledContracts(rules) {
1155+
precompiles[addr] = c.Name()
1156+
}
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),
1163+
}
1164+
}
1165+
11381166
// AccessList creates an access list for the given transaction.
11391167
// If the accesslist creation fails an error is returned.
11401168
// If the transaction itself fails, an vmErr is returned.

internal/jsre/deps/web3.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,6 +5490,10 @@ var properties = function () {
54905490
new Property({
54915491
name: 'protocolVersion',
54925492
getter: 'eth_protocolVersion'
5493+
}),
5494+
new Property({
5495+
name: 'config',
5496+
getter: 'eth_config'
54935497
})
54945498
];
54955499
};

params/config.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,65 @@ 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+
1013+
// BlobConfig returns the blob config associated with the provided fork.
1014+
func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig {
1015+
switch fork {
1016+
case forks.Osaka:
1017+
return DefaultOsakaBlobConfig
1018+
case forks.Prague:
1019+
return DefaultPragueBlobConfig
1020+
case forks.Cancun:
1021+
return DefaultCancunBlobConfig
1022+
default:
1023+
return nil
1024+
}
1025+
}
1026+
1027+
// ActiveSystemContracts returns the currently active system contracts at the
1028+
// given timestamp.
1029+
func (c *ChainConfig) ActiveSystemContracts(time uint64) map[string]common.Address {
1030+
fork := c.LatestFork(time)
1031+
active := make(map[string]common.Address)
1032+
if fork >= forks.Osaka {
1033+
// no new system contracts
1034+
}
1035+
if fork >= forks.Prague {
1036+
active["CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS"] = ConsolidationQueueAddress
1037+
active["DEPOSIT_CONTRACT_ADDRESS"] = c.DepositContractAddress
1038+
active["HISTORY_STORAGE_ADDRESS"] = HistoryStorageAddress
1039+
active["WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS"] = WithdrawalQueueAddress
1040+
}
1041+
if fork >= forks.Cancun {
1042+
active["BEACON_ROOTS_ADDRESS"] = BeaconRootsAddress
1043+
}
1044+
return active
1045+
}
1046+
9881047
// Timestamp returns the timestamp associated with the fork or returns nil if
9891048
// the fork isn't defined or isn't a time-based fork.
9901049
func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 {

0 commit comments

Comments
 (0)