Skip to content

Commit

Permalink
Merge branch 'celo8' into piersy/rpc-api-compatibility-test
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy authored Sep 25, 2024
2 parents 48b7406 + ea21749 commit 82afafd
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 45 deletions.
12 changes: 5 additions & 7 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
17 changes: 0 additions & 17 deletions consensus/misc/eip1559/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion contracts/addresses/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion e2e_test/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
28 changes: 18 additions & 10 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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().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)
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().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)
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().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)
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().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)
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().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)
Expand Down Expand Up @@ -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)
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().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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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-bedrock) execution request"
return "no historical RPC is available for this historical (pre-cel2) execution request"
}

type methodNotFoundError struct{ method string }
Expand Down

0 comments on commit 82afafd

Please sign in to comment.