mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
params,internal/ethapi: add current, next, and last to eth_config
This commit is contained in:
parent
5de62c7279
commit
42c3141489
2 changed files with 46 additions and 38 deletions
|
|
@ -34,6 +34,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
|
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/core/forkid"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
|
|
@ -1157,28 +1158,60 @@ type config struct {
|
||||||
ActivationTime uint64 `json:"activationTime"`
|
ActivationTime uint64 `json:"activationTime"`
|
||||||
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
|
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
|
||||||
ChainId *hexutil.Big `json:"chainId"`
|
ChainId *hexutil.Big `json:"chainId"`
|
||||||
|
ForkId hexutil.Bytes `json:"forkId"`
|
||||||
Precompiles map[common.Address]string `json:"precompiles"`
|
Precompiles map[common.Address]string `json:"precompiles"`
|
||||||
SystemContracts map[string]common.Address `json:"systemContracts"`
|
SystemContracts map[string]common.Address `json:"systemContracts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type configResponse struct {
|
||||||
|
Current *config `json:"current"`
|
||||||
|
Next *config `json:"next"`
|
||||||
|
Last *config `json:"last"`
|
||||||
|
}
|
||||||
|
|
||||||
// Config implements the EIP-7910 eth_config method.
|
// Config implements the EIP-7910 eth_config method.
|
||||||
func (api *BlockChainAPI) Config(ctx context.Context) config {
|
func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
|
||||||
|
genesis, err := api.b.BlockByNumber(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to load genesis: %w", err)
|
||||||
|
}
|
||||||
|
assemble := func(c *params.ChainConfig, ts *uint64) *config {
|
||||||
|
if ts == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
t := *ts
|
||||||
|
|
||||||
var (
|
var (
|
||||||
c = api.b.ChainConfig()
|
rules = c.Rules(c.LondonBlock, true, t)
|
||||||
h = api.b.CurrentBlock()
|
|
||||||
rules = c.Rules(h.Number, true, h.Time)
|
|
||||||
precompiles = make(map[common.Address]string)
|
precompiles = make(map[common.Address]string)
|
||||||
)
|
)
|
||||||
for addr, c := range vm.ActivePrecompiledContracts(rules) {
|
for addr, c := range vm.ActivePrecompiledContracts(rules) {
|
||||||
precompiles[addr] = c.Name()
|
precompiles[addr] = c.Name()
|
||||||
}
|
}
|
||||||
return config{
|
forkid := forkid.NewID(c, genesis, ^uint64(0), t).Hash
|
||||||
ActivationTime: c.NextForkTime(h.Time),
|
return &config{
|
||||||
BlobSchedule: c.BlobConfig(c.LatestFork(h.Time)),
|
ActivationTime: t,
|
||||||
|
BlobSchedule: c.BlobConfig(c.LatestFork(t)),
|
||||||
ChainId: (*hexutil.Big)(c.ChainID),
|
ChainId: (*hexutil.Big)(c.ChainID),
|
||||||
|
ForkId: forkid[:],
|
||||||
Precompiles: precompiles,
|
Precompiles: precompiles,
|
||||||
SystemContracts: c.ActiveSystemContracts(h.Time),
|
SystemContracts: c.ActiveSystemContracts(t),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
c = api.b.ChainConfig()
|
||||||
|
t = api.b.CurrentHeader().Time
|
||||||
|
)
|
||||||
|
resp := configResponse{
|
||||||
|
Next: assemble(c, c.Timestamp(c.LatestFork(t)+1)),
|
||||||
|
Current: assemble(c, c.Timestamp(c.LatestFork(t))),
|
||||||
|
Last: assemble(c, c.Timestamp(c.LatestFork(^uint64(0)))),
|
||||||
|
}
|
||||||
|
// Nil out last if no future-fork is configured.
|
||||||
|
if resp.Next == nil {
|
||||||
|
resp.Last = nil
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccessList creates an access list for the given transaction.
|
// AccessList creates an access list for the given transaction.
|
||||||
|
|
|
||||||
|
|
@ -985,31 +985,6 @@ 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.
|
// BlobConfig returns the blob config associated with the provided fork.
|
||||||
func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig {
|
func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig {
|
||||||
switch fork {
|
switch fork {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue