diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 2675a616759c..cbf71c151d8f 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -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") @@ -257,6 +262,7 @@ func init() { consoleFlags, debug.Flags, metricsFlags, + rollupFlags, //[rollup-geth] ) flags.AutoEnvVars(app.Flags, "GETH") diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6db88ff66183..dccf4981340c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 ( @@ -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 { @@ -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 { @@ -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) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 793f398367a7..adbf8632d6e6 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -17,7 +17,9 @@ package vm import ( + "context" "fmt" + "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" @@ -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, diff --git a/eth/backend.go b/eth/backend.go index f10d99c3a70b..f8762ffc3f7b 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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" @@ -164,7 +165,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { shutdownTracker: shutdowncheck.NewShutdownTracker(chainDb), } bcVersion := rawdb.ReadDatabaseVersion(chainDb) - var dbVer = "" + dbVer := "" if bcVersion != nil { dbVer = fmt.Sprintf("%d", *bcVersion) } @@ -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 diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index c781a639408a..5719ef16a3ab 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -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. diff --git a/internal/flags/categories.go b/internal/flags/categories.go index d426add55b10..7f28f24f9097 100644 --- a/internal/flags/categories.go +++ b/internal/flags/categories.go @@ -37,6 +37,7 @@ const ( MiscCategory = "MISC" TestingCategory = "TESTING" DeprecatedCategory = "ALIASED (deprecated)" + RollupCategory = "ROLLUP" //[rollup-geth] ) func init() {