Skip to content

Commit

Permalink
rollup precompile config is glob. variable
Browse files Browse the repository at this point in the history
I decided to implement it this way after trying to integrate code with Arbitrum and having a better understanding of the calls that are made to the NewEvm
This approach makes it easier to both override the default config, and to have the option to "not to think about it"
  • Loading branch information
mralj committed Oct 11, 2024
1 parent 42855ae commit d4cd646
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 93 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
applyMetricConfig(ctx, &cfg)

//[rollup-geth]
activateL1RPCEndpoint(ctx, stack)
utils.ActivateL1RPCEndpoint(ctx, stack)

return stack, cfg
}
Expand Down
20 changes: 0 additions & 20 deletions cmd/geth/config_rollup.go

This file was deleted.

35 changes: 23 additions & 12 deletions cmd/utils/flags_rollup.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package utils

import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/urfave/cli/v2"
)

var (
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 L1NodeRPCEndpointFlag = &cli.StringFlag{
Name: "rollup.l1.rpc_endpoint",
Usage: "L1 node RPC endpoint eg. http://0.0.0.0:8545",
Category: flags.RollupCategory,
}

var RollupFlags = []cli.Flag{
L1NodeRPCEndpointFlag,
}

var (
RollupFlags = []cli.Flag{
L1NodeRPCEndpointFlag,
// 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(ctx *cli.Context, stack *node.Node) {
if !ctx.IsSet(L1NodeRPCEndpointFlag.Name) {
log.Error("L1 node RPC endpoint URL not set", "flag", L1NodeRPCEndpointFlag.Name)
return
}
)

l1RPCEndpoint := ctx.String(L1NodeRPCEndpointFlag.Name)
stack.RegisterEthClient(l1RPCEndpoint)
vm.SetVmL1RpcClient(stack.EthClient())
}
17 changes: 9 additions & 8 deletions core/vm/contracts_rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ func activeRollupPrecompiledContracts(rules params.Rules) PrecompiledContracts {
}

// ActivateRollupPrecompiledContracts activates rollup-specific precompiles
func (pc PrecompiledContracts) ActivateRollupPrecompiledContracts(rules params.Rules, config *RollupPrecompileActivationConfig) {
if config == nil {
return
}

func (pc PrecompiledContracts) ActivateRollupPrecompiledContracts(rules params.Rules, config RollupPrecompileActivationConfig) {
activeRollupPrecompiles := activeRollupPrecompiledContracts(rules)
for k, v := range activeRollupPrecompiles {
pc[k] = v
Expand Down Expand Up @@ -131,13 +127,18 @@ func (c *L1SLoad) isL1SLoadActive() bool {
}

func (pc PrecompiledContracts) activateL1SLoad(l1RpcClient L1RpcClient, getLatestL1BlockNumber func() *big.Int) {
if paramsAreNil := l1RpcClient == nil || getLatestL1BlockNumber == nil; paramsAreNil {
return
}
if precompileNotRuleActivated := pc[rollupL1SloadAddress] == nil; precompileNotRuleActivated {
return
}

if rpcClientNotOverridenUseDefaultOne := l1RpcClient == nil; rpcClientNotOverridenUseDefaultOne {
l1RpcClient = defaultRollupPrecompilesConfig.L1RpcClient
}

if latestBlockGetterNotOverridenUseDefaultOne := getLatestL1BlockNumber == nil; latestBlockGetterNotOverridenUseDefaultOne {
getLatestL1BlockNumber = defaultRollupPrecompilesConfig.GetLatestL1BlockNumber
}

pc[rollupL1SloadAddress] = &L1SLoad{
L1RpcClient: l1RpcClient,
GetLatestL1BlockNumber: getLatestL1BlockNumber,
Expand Down
14 changes: 12 additions & 2 deletions core/vm/contracts_rollup_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ import (
"math/big"
)

var defaultRollupPrecompilesConfig RollupPrecompileActivationConfig = RollupPrecompileActivationConfig{
L1SLoad: L1SLoad{
GetLatestL1BlockNumber: LetRPCDecideLatestL1Number,
},
}

func SetVmL1RpcClient(c L1RpcClient) {
defaultRollupPrecompilesConfig.L1RpcClient = c
}

// generateRollupPrecompiledContractsOverrides generates rollup precompile config including L2 specific overrides
func generateRollupPrecompiledContractsOverrides(evm *EVM) *RollupPrecompileActivationConfig {
return &RollupPrecompileActivationConfig{
func generateRollupPrecompiledContractsOverrides(evm *EVM) RollupPrecompileActivationConfig {
return RollupPrecompileActivationConfig{
L1SLoad{
L1RpcClient: evm.Config.L1RpcClient,
GetLatestL1BlockNumber: LetRPCDecideLatestL1Number,
Expand Down
7 changes: 0 additions & 7 deletions eth/api_backend_rollup.go

This file was deleted.

2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}

// [rollup-geth]
vmConfig.L1RpcClient = stack.EthClient()
vm.SetVmL1RpcClient(stack.EthClient())

eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, &config.TransactionHistory)
if err != nil {
Expand Down
11 changes: 1 addition & 10 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ type Backend interface {
ChainDb() ethdb.Database
StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (*state.StateDB, StateReleaseFunc, error)
StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*types.Transaction, vm.BlockContext, *state.StateDB, StateReleaseFunc, error)

// [rollup-geth]
GetL1RpcClient() vm.L1RpcClient
}

// API is the collection of tracing APIs exposed over the private debugging endpoint.
Expand Down Expand Up @@ -965,13 +962,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
precompiles := vm.ActivePrecompiledContracts(rules)

//[rollup-geth]
rollupsConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: api.backend.GetL1RpcClient(),
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number,
},
}
precompiles.ActivateRollupPrecompiledContracts(rules, &rollupsConfig)
precompiles.ActivateRollupPrecompiledContracts(rules, vm.RollupPrecompileActivationConfig{})

if err := config.StateOverrides.Apply(statedb, precompiles); err != nil {
return nil, err
Expand Down
7 changes: 0 additions & 7 deletions eth/tracers/api_rollup_test.go

This file was deleted.

10 changes: 3 additions & 7 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,14 +1166,10 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
}
rules := b.ChainConfig().Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)
precompiles := maps.Clone(vm.ActivePrecompiledContracts(rules))

//[rollup-geth]
rollupConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: b.GetL1RpcClient(),
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number,
},
}
precompiles.ActivateRollupPrecompiledContracts(rules, &rollupConfig)
rollupConfigOverrides := vm.RollupPrecompileActivationConfig{}
precompiles.ActivateRollupPrecompiledContracts(rules, rollupConfigOverrides)

if err := overrides.Apply(state, precompiles); err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ type Backend interface {
SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

//[rollup-geth]
GetL1RpcClient() vm.L1RpcClient
}

func GetAPIs(apiBackend Backend) []rpc.API {
Expand Down
10 changes: 2 additions & 8 deletions internal/ethapi/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,9 @@ func (sim *simulator) activePrecompiles(base *types.Header) vm.PrecompiledContra
rules = sim.chainConfig.Rules(base.Number, isMerge, base.Time)
)

//[rollup-geth]
rollupsConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: sim.b.GetL1RpcClient(),
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number,
},
}
precompiles := vm.ActivePrecompiledContracts(rules)
precompiles.ActivateRollupPrecompiledContracts(rules, &rollupsConfig)
//[rollup-geth]
precompiles.ActivateRollupPrecompiledContracts(rules, vm.RollupPrecompileActivationConfig{})

return maps.Clone(precompiles)
}
Expand Down
7 changes: 0 additions & 7 deletions internal/ethapi/transaction_args_rollup_test.go

This file was deleted.

0 comments on commit d4cd646

Please sign in to comment.