Skip to content

Commit

Permalink
cleaned up code & created more rollup specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
mralj committed Oct 7, 2024
1 parent 2a7b7d7 commit 0f74390
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 46 deletions.
7 changes: 6 additions & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 2 additions & 13 deletions cmd/utils/flags_rollup.go
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
}
7 changes: 0 additions & 7 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package vm

import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand All @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions eth/api_backend_rollup.go
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 4 additions & 10 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 != "" {
Expand Down
19 changes: 19 additions & 0 deletions eth/backend_rollup.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
3 changes: 0 additions & 3 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0f74390

Please sign in to comment.