Skip to content

Commit

Permalink
Revert historical rpc (#247)
Browse files Browse the repository at this point in the history
This reverts the changes made to trigger the historical RPC based on the cel2
block time. (although we retain support for historical execution for
debug_traceCall)

The reason for this is that there are [tests] in optimism
(https://github.com/celo-org/optimism/blob/78d41a3be3c1759e32965a9eb2e69c146eda02b6/op-e2e/op_geth_test.go#L232)
that test pre and post time based forks. These test were failing on this PR:

* celo-org/optimism#243

The function used to [construct the
genesis](https://github.com/celo-org/optimism/blob/78d41a3be3c1759e32965a9eb2e69c146eda02b6/op-chain-ops/genesis/genesis.go#L25)
assumes that the time based forks take the time of the L1 start block and sets
all time based forks to the L1 start block time. If we set the Cel2Time to the
L1 start block time and then try to test some pre fork execution behaviour, the
op-geth RPC api will interpret that request as a request that needs to be
proxied but in these tests no proxy is set so the tests fail.

Previously the test relied on the fact that the bedrock block defaults to zero,
and since the old RPC implementation only proxies requests older than bedrock
it ensures that no requests need proxying.

It turns out that we can use the bedrock block as well, since we always set the
bedrock block to be the same block as the migration block. So simply removing
the changes made for historical RPC actually works well, and fixes the tests in
the aforementioned PR.
  • Loading branch information
piersy authored Oct 3, 2024
1 parent 4eb43bc commit fd593f2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 48 deletions.
18 changes: 9 additions & 9 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,7 +961,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
return nil, err
}

if api.backend.ChainConfig().IsPreCel2(block.Time()) {
if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) {
if api.backend.HistoricalRPCService() != nil {
var histResult json.RawMessage
err := api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceCall", args, blockNrOrHash, config)
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 fd593f2

Please sign in to comment.