Skip to content

Commit

Permalink
internal/ethapi and tracers use pre-existing function call
Browse files Browse the repository at this point in the history
  • Loading branch information
mralj committed Oct 7, 2024
1 parent b72098e commit 76a2339
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
27 changes: 21 additions & 6 deletions core/vm/contracts_rollup_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@

package vm

import "math/big"
import (
"math/big"
)

// generateRollupPrecompiledContractsOverrides generates rollup precompile config inlucing L2 specific overrides
// generateRollupPrecompiledContractsOverrides generates rollup precompile config including L2 specific overrides
func generateRollupPrecompiledContractsOverrides(evm *EVM) *RollupPrecompileActivationConfig {
return &RollupPrecompileActivationConfig{
L1SLoad{
L1RpcClient: evm.Config.L1RpcClient,
GetLatestL1BlockNumber: getLatestL1BlockNumber(evm),
GetLatestL1BlockNumber: LetRPCDecideLatestL1Number(),
},
}
}

// [OVERRIDE] getLatestL1BlockNumber
// [OVERRIDE] LetRPCDecideLatestL1Number
// Each rollup should override this function so that it returns
// correct latest L1 block number
func getLatestL1BlockNumber(evm *EVM) func() *big.Int {
func LetRPCDecideLatestL1Number() func() *big.Int {
return func() *big.Int {
return evm.Context.BlockNumber
return nil
}
}

// [OVERRIDE] getLatestL1BlockNumber
// Each rollup should override this function so that it returns
// correct latest L1 block number
//
// EXAMPLE 2
// func GetLatestL1BlockNumber(state *state.StateDB) func() *big.Int {
// return func() *big.Int {
// addressOfL1BlockContract := common.Address{}
// slotInContractRepresentingL1BlockNumber := common.Hash{}
// return state.GetState(addressOfL1BlockContract, slotInContractRepresentingL1BlockNumber).Big()
// }
// }
5 changes: 2 additions & 3 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,11 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
config.BlockOverrides.Apply(&vmctx)
rules := api.backend.ChainConfig().Rules(vmctx.BlockNumber, vmctx.Random != nil, vmctx.Time)

//[rollup-geth] This is optional for rollups, instead we can simply do
// rollupsConfig := nil
//[rollup-geth]
rollupsConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: api.backend.GetL1RpcClient(),
GetLatestL1BlockNumber: func() *big.Int { return vmctx.BlockNumber },
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number(),
},
}
precompiles := vm.ActivePrecompiledContracts(rules, &rollupsConfig)
Expand Down
8 changes: 5 additions & 3 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,14 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
}
rules := b.ChainConfig().Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)

//[rollup-geth] This is optional for rollups, instead we can simply do
// rollupsConfig := nil
//[rollup-geth]
// The way code is organized (check call to applyMessage) this config supersedes
// the evm config
rollupConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: b.GetL1RpcClient(),
GetLatestL1BlockNumber: func() *big.Int { return blockCtx.BlockNumber }},
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number(),
},
}
precompiles := maps.Clone(vm.ActivePrecompiledContracts(rules, &rollupConfig))

Expand Down
6 changes: 3 additions & 3 deletions internal/ethapi/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ func (sim *simulator) activePrecompiles(base *types.Header) vm.PrecompiledContra
isMerge = base.Difficulty.Sign() == 0
rules = sim.chainConfig.Rules(base.Number, isMerge, base.Time)
)
//[rollup-geth] This is optional for rollups, instead we can simply do
// rollupsConfig := nil

//[rollup-geth]
rollupsConfig := vm.RollupPrecompileActivationConfig{
L1SLoad: vm.L1SLoad{
L1RpcClient: sim.b.GetL1RpcClient(),
GetLatestL1BlockNumber: func() *big.Int { return base.Number },
GetLatestL1BlockNumber: vm.LetRPCDecideLatestL1Number(),
},
}
precompiles := vm.ActivePrecompiledContracts(rules, &rollupsConfig)
Expand Down

0 comments on commit 76a2339

Please sign in to comment.