diff --git a/consensus/misc/eip1559/eip1559.go b/consensus/misc/eip1559/eip1559.go index cbbb1e048d..0a88bd66a1 100644 --- a/consensus/misc/eip1559/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -66,14 +66,12 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, time uint64) } }() - // If this is the cel2 transition block and the parent block has a base fee - // then use that. - if config.Cel2Time != nil && *config.Cel2Time == time && parent.BaseFee != nil { - return parent.BaseFee - } - // If the current block is the first EIP-1559 block, return the InitialBaseFee. - if !config.IsLondon(parent.Number) { + // For cel2 the london hardfork is enabled at the transition block, but we want to smoothly continue + // using our existing base fee and simply transition the calculation logic across to the real eip1559 logic + // I.E. stop using original celo logic defined in a smart contract. So if gingerbread was active for the parent + // block we don't set the base fee to the InitialBaseFee, and instead use the normal calculation logic. + if !config.IsLondon(parent.Number) && !config.IsGingerbread(parent.Number) { return new(big.Int).SetUint64(params.InitialBaseFee) } diff --git a/consensus/misc/eip1559/eip1559_test.go b/consensus/misc/eip1559/eip1559_test.go index fb6a7c5332..726440ce39 100644 --- a/consensus/misc/eip1559/eip1559_test.go +++ b/consensus/misc/eip1559/eip1559_test.go @@ -212,20 +212,3 @@ func TestCalcBaseFeeCeloFloor(t *testing.T) { } } } - -// TestCalcBaseFeeCeloBlockActivation tests the base fee calculation for the celo block activation, mantaining the same base fee as the parent block -func TestCalcBaseFeeCeloBlockActivation(t *testing.T) { - config := celoConfig() - // Before activation - // usage above target - parent := &types.Header{ - Number: common.Big32, - GasLimit: 20000000, - GasUsed: 15000000, - BaseFee: big.NewInt(params.InitialBaseFee * 3), - Time: *config.Cel2Time - 2, - } - if have, want := CalcBaseFee(config, parent, parent.Time+2), big.NewInt(params.InitialBaseFee*3); have.Cmp(want) != 0 { - t.Errorf("have %d want %d, ", have, want) - } -} diff --git a/contracts/addresses/addresses.go b/contracts/addresses/addresses.go index 9bc556252d..0801db43e8 100644 --- a/contracts/addresses/addresses.go +++ b/contracts/addresses/addresses.go @@ -5,7 +5,7 @@ import "github.com/ethereum/go-ethereum/common" var ( CeloTokenAddress = common.HexToAddress("0x471ece3750da237f93b8e339c536989b8978a438") FeeHandlerAddress = common.HexToAddress("0xcd437749e43a154c07f3553504c68fbfd56b8778") - FeeCurrencyDirectoryAddress = common.HexToAddress("0x71ffbd48e34bdd5a87c3c683e866dc63b8b2a685") + FeeCurrencyDirectoryAddress = common.HexToAddress("0x9212Fb72ae65367A7c887eC4Ad9bE310BAC611BF") CeloTokenAlfajoresAddress = common.HexToAddress("0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9") FeeHandlerAlfajoresAddress = common.HexToAddress("0xEAaFf71AB67B5d0eF34ba62Ea06Ac3d3E2dAAA38") diff --git a/e2e_test/shared.sh b/e2e_test/shared.sh index 0b946fa0f4..060f46c69c 100644 --- a/e2e_test/shared.sh +++ b/e2e_test/shared.sh @@ -9,7 +9,7 @@ export ACC_ADDR=0x42cf1bbc38BaAA3c4898ce8790e21eD2738c6A4a export ACC_PRIVKEY=0x2771aff413cac48d9f8c114fabddd9195a2129f3c2c436caa07e27bb7f58ead5 export REGISTRY_ADDR=0x000000000000000000000000000000000000ce10 export TOKEN_ADDR=0x471ece3750da237f93b8e339c536989b8978a438 -export FEE_CURRENCY_DIRECTORY_ADDR=0x71ffbd48e34bdd5a87c3c683e866dc63b8b2a685 +export FEE_CURRENCY_DIRECTORY_ADDR=0x9212Fb72ae65367A7c887eC4Ad9bE310BAC611BF export FEE_CURRENCY=0x000000000000000000000000000000000000ce16 export FEE_HANDLER=0xcd437749e43a154c07f3553504c68fbfd56b8778 export ORACLE3=0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0003 diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 39f3c79b98..2ccea3061f 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -146,6 +146,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe emptyBlobVHash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit) ) config.LondonBlock = londonBlock + config.GingerbreadBlock = londonBlock config.ArrowGlacierBlock = londonBlock config.GrayGlacierBlock = londonBlock var engine consensus.Engine = beacon.New(ethash.NewFaker()) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 8cfd666545..26d82dac86 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -22,7 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "math/big" "os" "runtime" "sync" @@ -443,7 +442,7 @@ func (api *API) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, return nil, err } - if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) { + if api.backend.ChainConfig().IsPreCel2(block.Time()) { if api.backend.HistoricalRPCService() != nil { var histResult []*txTraceResult err = api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceBlockByNumber", number, config) @@ -467,7 +466,7 @@ func (api *API) TraceBlockByHash(ctx context.Context, hash common.Hash, config * return nil, err } - if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) { + if api.backend.ChainConfig().IsPreCel2(block.Time()) { if api.backend.HistoricalRPCService() != nil { var histResult []*txTraceResult err = api.backend.HistoricalRPCService().CallContext(ctx, &histResult, "debug_traceBlockByHash", hash, config) @@ -883,7 +882,12 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * return nil, ethapi.NewTxIndexingError() } - if api.backend.ChainConfig().IsOptimismPreBedrock(new(big.Int).SetUint64(blockNumber)) { + block, err := api.blockByHash(ctx, blockHash) + if err != nil { + 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_traceTransaction", hash, config) @@ -903,10 +907,6 @@ 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 @@ -961,8 +961,16 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc return nil, err } - if api.backend.ChainConfig().IsOptimismPreBedrock(block.Number()) { - return nil, errors.New("l2geth does not have a debug_traceCall method") + 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 } // try to recompute the state diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 9dc98efc6f..51f6dec003 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -546,6 +546,15 @@ 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) { @@ -691,6 +700,15 @@ 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) { diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go index 795f3797d7..0fd52a7cd7 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/ethclient_test.go @@ -295,6 +295,14 @@ 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() diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9c7ca9a24f..6ec4599fdc 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -671,7 +671,7 @@ func (api *BlockChainAPI) GetBalance(ctx context.Context, address common.Address return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Big err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getBalance", address, blockNrOrHash) @@ -728,7 +728,7 @@ func (api *BlockChainAPI) GetProof(ctx context.Context, address common.Address, if err != nil { return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res AccountResult err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getProof", address, storageKeys, blockNrOrHash) @@ -950,7 +950,7 @@ func (api *BlockChainAPI) GetCode(ctx context.Context, address common.Address, b return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Bytes err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getCode", address, blockNrOrHash) @@ -981,7 +981,7 @@ func (api *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Addre return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Bytes err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getStorageAt", address, hexKey, blockNrOrHash) @@ -1262,7 +1262,7 @@ func (api *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockN return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Bytes err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_call", args, blockNrOrHash, overrides) @@ -1363,7 +1363,7 @@ func (api *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, return 0, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Uint64 err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_estimateGas", args, blockNrOrHash) @@ -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().IsOptimismPreBedrock(header.Number) { + if err == nil && header != nil && api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res accessListResult err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_createAccessList", args, blockNrOrHash) @@ -1898,7 +1898,7 @@ func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address comm return nil, err } - if api.b.ChainConfig().IsOptimismPreBedrock(header.Number) { + if api.b.ChainConfig().IsPreCel2(header.Time) { if api.b.HistoricalRPCService() != nil { var res hexutil.Uint64 err := api.b.HistoricalRPCService().CallContext(ctx, &res, "eth_getTransactionCount", address, blockNrOrHash) diff --git a/params/config.go b/params/config.go index 3cb9eeec72..f0b1845700 100644 --- a/params/config.go +++ b/params/config.go @@ -769,6 +769,10 @@ 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) diff --git a/rpc/errors.go b/rpc/errors.go index 67c523d11a..a9323717eb 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -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-bedrock) execution request" + return "no historical RPC is available for this historical (pre-cel2) execution request" } type methodNotFoundError struct{ method string }