Skip to content

Commit

Permalink
Revert historical rpc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy committed Oct 2, 2024
1 parent 13f6cb6 commit 9fb0fe6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 57 deletions.
28 changes: 10 additions & 18 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -442,7 +443,7 @@ func (api *API) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber,
return nil, err
}

if api.backend.ChainConfig().IsPreCel2(block.Time()) {
if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) {
if api.backend.HistoricalRPCService() != nil {
var histResult []*txTraceResult
err = api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceBlockByNumber", number, config)
Expand All @@ -466,7 +467,7 @@ func (api *API) TraceBlockByHash(ctx context.Context, hash common.Hash, config *
return nil, err
}

if api.backend.ChainConfig().IsPreCel2(block.Time()) {
if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) {
if api.backend.HistoricalRPCService() != nil {
var histResult []*txTraceResult
err = api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceBlockByHash", hash, config)
Expand Down Expand Up @@ -882,12 +883,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
return nil, ethapi.NewTxIndexingError()
}

block, err := api.blockByHash(ctx, blockHash)
if err != nil {
return nil, err
}

if api.backend.ChainConfig().IsPreCel2(block.Time()) {
if api.backend.ChainConfig().IsOptimismPreBedrock(new(big.Int).SetUint64(blockNumber)) {
if api.backend.HistoricalRPCService() != nil {
var histResult json.RawMessage
err := api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceTransaction", hash, config)
Expand All @@ -907,6 +903,10 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
if config != nil && config.Reexec != nil {
reexec = *config.Reexec
}
block, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(blockNumber), blockHash)
if err != nil {
return nil, err
}
tx, vmctx, statedb, release, err := api.backend.StateAtTransaction(ctx, block, int(index), reexec)
if err != nil {
return nil, err
Expand Down Expand Up @@ -961,16 +961,8 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
return nil, err
}

if api.backend.ChainConfig().IsPreCel2(block.Time()) {
if api.backend.HistoricalRPCService() != nil {
var histResult json.RawMessage
err := api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceCall", args, blockNrOrHash, config)
if err != nil {
return nil, fmt.Errorf("historical backend error: %w", err)
}
return histResult, nil
}
return nil, rpc.ErrNoHistoricalFallback
if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) {
return nil, errors.New("l2geth does not have a debug_traceCall method")
}

// try to recompute the state
Expand Down
18 changes: 0 additions & 18 deletions eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,6 @@ func TestTraceTransactionHistorical(t *testing.T) {
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
},
}

// Set Cel2Time so that we are in the pre-migration case
var cel2Time uint64 = 10000
genesis.Config.Cel2Time = &cel2Time
// These two changes are a workaround to compensate for the Cel2Time
// check in Genesis.ToBlock(). Ideally we remove this and fix it there.
genesis.GasLimit = params.GenesisGasLimit
genesis.Difficulty = params.GenesisDifficulty

target := common.Hash{}
signer := types.HomesteadSigner{}
backend := newTestBackend(t, 1, genesis, func(i int, b *core.BlockGen) {
Expand Down Expand Up @@ -700,15 +691,6 @@ func TestTraceBlockHistorical(t *testing.T) {
accounts[2].addr: {Balance: big.NewInt(params.Ether)},
},
}

// Set Cel2Time so that we are in the pre-migration case
var cel2Time uint64 = 10000
genesis.Config.Cel2Time = &cel2Time
// These two changes are a workaround to compensate for the Cel2Time
// check in Genesis.ToBlock(). Ideally we remove this and fix it there.
genesis.GasLimit = params.GenesisGasLimit
genesis.Difficulty = params.GenesisDifficulty

genBlocks := 10
signer := types.HomesteadSigner{}
backend := newTestBackend(t, genBlocks, genesis, func(i int, b *core.BlockGen) {
Expand Down
8 changes: 0 additions & 8 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,6 @@ func newTestBackend(t *testing.T, enableHistoricalState bool) (*node.Node, []*ty
actualGenesis = genesisForHistorical
consensusEngine = beacon.New(ethash.NewFaker())
chainLength = 10

// Set Cel2Time so that we are in the pre-migration case
var cel2Time uint64 = 10000
actualGenesis.Config.Cel2Time = &cel2Time
// These two changes are a workaround to compensate for the Cel2Time
// check in Genesis.ToBlock(). Ideally we remove this and fix it there.
actualGenesis.GasLimit = params.GenesisGasLimit
actualGenesis.Difficulty = params.GenesisDifficulty
} else {
actualGenesis = genesis
consensusEngine = ethash.NewFaker()
Expand Down
16 changes: 8 additions & 8 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (api *BlockChainAPI) GetBalance(ctx context.Context, address common.Address
return nil, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Big
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getBalance", address, blockNrOrHash)
Expand Down Expand Up @@ -728,7 +728,7 @@ func (api *BlockChainAPI) GetProof(ctx context.Context, address common.Address,
if err != nil {
return nil, err
}
if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res AccountResult
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getProof", address, storageKeys, blockNrOrHash)
Expand Down Expand Up @@ -950,7 +950,7 @@ func (api *BlockChainAPI) GetCode(ctx context.Context, address common.Address, b
return nil, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Bytes
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getCode", address, blockNrOrHash)
Expand Down Expand Up @@ -981,7 +981,7 @@ func (api *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Addre
return nil, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Bytes
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getStorageAt", address, hexKey, blockNrOrHash)
Expand Down Expand Up @@ -1262,7 +1262,7 @@ func (api *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockN
return nil, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Bytes
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_call", args, blockNrOrHash, overrides)
Expand Down Expand Up @@ -1363,7 +1363,7 @@ func (api *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs,
return 0, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Uint64
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_estimateGas", args, blockNrOrHash)
Expand Down Expand Up @@ -1725,7 +1725,7 @@ func (api *BlockChainAPI) CreateAccessList(ctx context.Context, args Transaction
}

header, err := headerByNumberOrHash(ctx, api.b, bNrOrHash)
if err == nil && header != nil && api.b.ChainConfig().IsPreCel2(header.Time) {
if err == nil && header != nil && api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res accessListResult
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_createAccessList", args, blockNrOrHash)
Expand Down Expand Up @@ -1898,7 +1898,7 @@ func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address comm
return nil, err
}

if api.b.ChainConfig().IsPreCel2(header.Time) {
if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) {
if api.b.HistoricalRPCService() != nil {
var res hexutil.Uint64
err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getTransactionCount", address, blockNrOrHash)
Expand Down
4 changes: 0 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,6 @@ func (c *ChainConfig) IsCel2(time uint64) bool {
return isTimestampForked(c.Cel2Time, time)
}

func (c *ChainConfig) IsPreCel2(time uint64) bool {
return c.Cel2Time != nil && !c.IsCel2(time)
}

// IsGingerbread returns whether num represents a block number after the Gingerbread fork
func (c *ChainConfig) IsGingerbread(num *big.Int) bool {
return isBlockForked(c.GingerbreadBlock, num)
Expand Down
2 changes: 1 addition & 1 deletion rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type NoHistoricalFallbackError struct{}
func (e NoHistoricalFallbackError) ErrorCode() int { return -32801 }

func (e NoHistoricalFallbackError) Error() string {
return "no historical RPC is available for this historical (pre-cel2) execution request"
return "no historical RPC is available for this historical (pre-bedrock) execution request"
}

type methodNotFoundError struct{ method string }
Expand Down

0 comments on commit 9fb0fe6

Please sign in to comment.