From 0f7439099439dac0fcc8b8d00b7121636206a763 Mon Sep 17 00:00:00 2001 From: mralj Date: Sun, 29 Sep 2024 13:12:00 +0200 Subject: [PATCH] cleaned up code & created more rollup specific files --- cmd/geth/config.go | 7 ++++++- cmd/utils/flags.go | 7 ++----- cmd/utils/flags_rollup.go | 15 ++------------- core/vm/interpreter.go | 7 ------- eth/api_backend.go | 5 ----- eth/api_backend_rollup.go | 7 +++++++ eth/backend.go | 14 ++++---------- eth/backend_rollup.go | 19 +++++++++++++++++++ eth/ethconfig/config.go | 3 --- internal/ethapi/simulate.go | 4 ++-- 10 files changed, 42 insertions(+), 46 deletions(-) create mode 100644 eth/api_backend_rollup.go create mode 100644 eth/backend_rollup.go diff --git a/cmd/geth/config.go b/cmd/geth/config.go index fd57ff40def4..24eddbabf167 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -192,7 +192,12 @@ func makeFullNode(ctx *cli.Context) *node.Node { cfg.Eth.OverrideVerkle = &v } - backend, eth := utils.RegisterEthService(stack, &cfg.Eth) + // [rollup-geth] + // TODO: think about if there is better solution for this (eg. rollup config file) + if !ctx.IsSet(utils.L1NodeRPCEndpointFlag.Name) { + log.Crit("L1 node RPC endpoint URL not set", "flag", utils.L1NodeRPCEndpointFlag.Name) + } + backend, eth := utils.RegisterEthService(stack, &cfg.Eth, ctx.String(utils.L1NodeRPCEndpointFlag.Name)) // Create gauge with geth system and build information if eth != nil { // The 'eth' backend may be nil in light mode diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9278b445b3aa..c85e7e0a4196 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1651,9 +1651,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { setRequiredBlocks(ctx, cfg) setLes(ctx, cfg) - //[rollup-geth] - setRollupEthConfig(ctx, cfg) - // Cap the cache allowance and tune the garbage collector mem, err := gopsutil.VirtualMemory() if err == nil { @@ -1928,8 +1925,8 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) { // RegisterEthService adds an Ethereum client to the stack. // The second return value is the full node instance. -func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (*eth.EthAPIBackend, *eth.Ethereum) { - backend, err := eth.New(stack, cfg) +func RegisterEthService(stack *node.Node, cfg *ethconfig.Config, l1RPCClientEndpoint string) (*eth.EthAPIBackend, *eth.Ethereum) { + backend, err := eth.New(stack, cfg, l1RPCClientEndpoint) if err != nil { Fatalf("Failed to register the Ethereum service: %v", err) } diff --git a/cmd/utils/flags_rollup.go b/cmd/utils/flags_rollup.go index 4b6d0e0db319..241505d1a1fb 100644 --- a/cmd/utils/flags_rollup.go +++ b/cmd/utils/flags_rollup.go @@ -1,14 +1,12 @@ package utils import ( - "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/internal/flags" - "github.com/ethereum/go-ethereum/log" "github.com/urfave/cli/v2" ) var ( - l1NodeRPCEndpointFlag = &cli.StringFlag{ + L1NodeRPCEndpointFlag = &cli.StringFlag{ Name: "rollup.l1.rpc_endpoint", Usage: "L1 node RPC endpoint eg. http://0.0.0.0:8545", Category: flags.RollupCategory, @@ -18,15 +16,6 @@ var ( var ( RollupFlags = []cli.Flag{ - l1NodeRPCEndpointFlag, + L1NodeRPCEndpointFlag, } ) - -// [rollup-geth] -func setRollupEthConfig(ctx *cli.Context, cfg *ethconfig.Config) { - if ctx.IsSet(l1NodeRPCEndpointFlag.Name) { - cfg.L1NodeRPCEndpoint = ctx.String(l1NodeRPCEndpointFlag.Name) - } else { - log.Crit("L1 node RPC endpoint URL not set", "flag", l1NodeRPCEndpointFlag.Name) - } -} diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 0872dfde4048..6e0b84067032 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -17,9 +17,7 @@ package vm import ( - "context" "fmt" - "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" @@ -40,11 +38,6 @@ type Config struct { L1RpcClient L1RpcClient //[rollup-geth] } -// [rollup-geth] -type L1RpcClient interface { - StoragesAt(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) ([]byte, error) -} - // ScopeContext contains the things that are per-call, such as stack and memory, // but not transients like pc and gas type ScopeContext struct { diff --git a/eth/api_backend.go b/eth/api_backend.go index 4960be76211f..8a9898b956f3 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -431,8 +431,3 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*types.Transaction, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) { return b.eth.stateAtTransaction(ctx, block, txIndex, reexec) } - -// [rollup-geth] -func (b *EthAPIBackend) GetL1RpcClient() vm.L1RpcClient { - return b.eth.BlockChain().GetVMConfig().L1RpcClient -} diff --git a/eth/api_backend_rollup.go b/eth/api_backend_rollup.go new file mode 100644 index 000000000000..42548f2ab164 --- /dev/null +++ b/eth/api_backend_rollup.go @@ -0,0 +1,7 @@ +package eth + +import "github.com/ethereum/go-ethereum/core/vm" + +func (b *EthAPIBackend) GetL1RpcClient() vm.L1RpcClient { + return b.eth.BlockChain().GetVMConfig().L1RpcClient +} diff --git a/eth/backend.go b/eth/backend.go index f8762ffc3f7b..04b32b873dda 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -43,7 +43,6 @@ import ( "github.com/ethereum/go-ethereum/eth/protocols/eth" "github.com/ethereum/go-ethereum/eth/protocols/snap" "github.com/ethereum/go-ethereum/eth/tracers" - "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" @@ -101,7 +100,7 @@ type Ethereum struct { // New creates a new Ethereum object (including the initialisation of the common Ethereum object), // whose lifecycle will be managed by the provided node. -func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { +func New(stack *node.Node, config *ethconfig.Config, l1RPCEndpoint string) (*Ethereum, error) { // Ensure configuration values are compatible and sane if !config.SyncMode.IsValid() { return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode) @@ -217,19 +216,14 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { overrides.OverrideVerkle = config.OverrideVerkle } - //[rollup-geth] - l1Client, err := ethclient.Dial(config.L1NodeRPCEndpoint) - if err != nil { - log.Crit("Unable to connect to L1 RPC endpoint at", "URL", config.L1NodeRPCEndpoint, "error", err) - } else { - vmConfig.L1RpcClient = l1Client - log.Info("Initialized L1 RPC client", "endpoint", config.L1NodeRPCEndpoint) - } + // [rollup-geth] + activateL1RPCEndpoint(l1RPCEndpoint, &vmConfig) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, &config.TransactionHistory) if err != nil { return nil, err } + eth.bloomIndexer.Start(eth.blockchain) if config.BlobPool.Datadir != "" { diff --git a/eth/backend_rollup.go b/eth/backend_rollup.go new file mode 100644 index 000000000000..e9b2ba338be7 --- /dev/null +++ b/eth/backend_rollup.go @@ -0,0 +1,19 @@ +package eth + +import ( + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/ethereum/go-ethereum/log" +) + +// TODO: when we have clearer picture of how do we want rollup "features" (EIPs/RIPs) to be activated +// make this "rule" activated (ie. if not "rule activated" then L1 client can simply be nil) +func activateL1RPCEndpoint(l1RPCEndpoint string, vmConfig *vm.Config) { + l1Client, err := ethclient.Dial(l1RPCEndpoint) + if err != nil { + log.Crit("Unable to connect to L1 RPC endpoint at", "URL", l1RPCEndpoint, "error", err) + } else { + vmConfig.L1RpcClient = l1Client + log.Info("Initialized L1 RPC client", "endpoint", l1RPCEndpoint) + } +} diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 5719ef16a3ab..c781a639408a 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -156,9 +156,6 @@ type Config struct { // OverrideVerkle (TODO: remove after the fork) OverrideVerkle *uint64 `toml:",omitempty"` - - //[rollup-geth] - L1NodeRPCEndpoint string } // CreateConsensusEngine creates a consensus engine for the given chain config. diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index 82a7d8a4cf57..441e90ae9941 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -283,14 +283,14 @@ func (sim *simulator) sanitizeCall(call *TransactionArgs, state *state.StateDB, func (sim *simulator) activePrecompiles(base *types.Header) vm.PrecompiledContracts { var ( - isMerge = (base.Difficulty.Sign() == 0) + isMerge = base.Difficulty.Sign() == 0 rules = sim.chainConfig.Rules(base.Number, isMerge, base.Time) ) precompiles := vm.ActivePrecompiledContracts(rules) //[rollup-geth] This is optional for rollups precompiles.ActivateRollupPrecompiledContracts(vm.RollupPrecompileActivationConfig{ - vm.L1SLoad{L1RpcClient: sim.b.GetL1RpcClient(), GetLatestL1BlockNumber: func() *big.Int { return base.Number }}, + L1SLoad: vm.L1SLoad{L1RpcClient: sim.b.GetL1RpcClient(), GetLatestL1BlockNumber: func() *big.Int { return base.Number }}, }) return maps.Clone(precompiles)