Skip to content

Commit

Permalink
dial L1 RPC client passed via required flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mralj committed Oct 4, 2024
1 parent c5916f1 commit 0ae7e7b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ var (
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
}

//[rollup-geth]
rollupFlags = []cli.Flag{
utils.L1NodeRPCEndpointFlag,
}
)

var app = flags.NewApp("the go-ethereum command line interface")
Expand Down Expand Up @@ -257,6 +262,7 @@ func init() {
consoleFlags,
debug.Flags,
metricsFlags,
rollupFlags, //[rollup-geth]
)
flags.AutoEnvVars(app.Flags, "GETH")

Expand Down
22 changes: 21 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,14 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Value: metrics.DefaultConfig.InfluxDBOrganization,
Category: flags.MetricsCategory,
}

//[rollup-geth]
L1NodeRPCEndpointFlag = &cli.StringFlag{
Name: "rollup.l1.rpc_endpoint",
Usage: "L1 node RPC endpoint eg. http://0.0.0.0:8545",
Category: flags.RollupCategory,
Required: true,
}
)

var (
Expand Down Expand Up @@ -1251,6 +1259,15 @@ func setLes(ctx *cli.Context, cfg *ethconfig.Config) {
}
}

// [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)
}
}

// MakeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles(max int) int {
Expand Down Expand Up @@ -1651,6 +1668,9 @@ 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 @@ -1861,7 +1881,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
cfg.Genesis = nil // fallback to db content

//validate genesis has PoS enabled in block 0
// validate genesis has PoS enabled in block 0
genesis, err := core.ReadGenesis(chaindb)
if err != nil {
Fatalf("Could not read genesis from database: %v", err)
Expand Down
10 changes: 9 additions & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package vm

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

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand All @@ -34,7 +36,13 @@ type Config struct {
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled

StatelessSelfValidation bool // Generate execution witnesses and self-check against them (testing purpose)
StatelessSelfValidation bool // Generate execution witnesses and self-check against them (testing purpose)
L1RpcClient L1Client //[rollup-geth]
}

// [rollup-geth]
type L1Client interface {
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
}

// ScopeContext contains the things that are per-call, such as stack and memory,
Expand Down
13 changes: 12 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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 @@ -164,7 +165,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
shutdownTracker: shutdowncheck.NewShutdownTracker(chainDb),
}
bcVersion := rawdb.ReadDatabaseVersion(chainDb)
var dbVer = "<nil>"
dbVer := "<nil>"
if bcVersion != nil {
dbVer = fmt.Sprintf("%d", *bcVersion)
}
Expand Down Expand Up @@ -215,6 +216,16 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.OverrideVerkle != nil {
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)
}

eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, &config.TransactionHistory)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ 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
1 change: 1 addition & 0 deletions internal/flags/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
MiscCategory = "MISC"
TestingCategory = "TESTING"
DeprecatedCategory = "ALIASED (deprecated)"
RollupCategory = "ROLLUP" //[rollup-geth]
)

func init() {
Expand Down

0 comments on commit 0ae7e7b

Please sign in to comment.