Skip to content

Commit

Permalink
fix: predeploy gasprice oracle (#1039)
Browse files Browse the repository at this point in the history
* l2geth: delete extra config options

* l2geth: stop using extra config options

* l2geth: more stop using extra config options

* chore: add changeset

* l2geth: add new config for gpo owner

* chore: add changeset

* l2geth: fix tests

* tests: fix build
  • Loading branch information
tynes committed Jun 25, 2021
1 parent 0b73bd3 commit 9e3b656
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-ants-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Add new config `ROLLUP_GAS_PRICE_ORACLE_OWNER_ADDRESS` to set the owner of the gas price oracle at runtime
5 changes: 5 additions & 0 deletions .changeset/odd-shrimps-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Removes config options that are no longer required. `ROLLUP_DATAPRICE`, `ROLLUP_EXECUTION_PRICE`, `ROLLUP_GAS_PRICE_ORACLE_ADDRESS` and `ROLLUP_ENABLE_L2_GAS_POLLING`. The oracle was moved to a predeploy 0x42.. address and polling is always enabled as it no longer needs to be backwards compatible
5 changes: 1 addition & 4 deletions l2geth/cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,9 @@ var (
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupDataPriceFlag,
utils.RollupExecutionPriceFlag,
utils.RollupBackendFlag,
utils.RollupEnableL2GasPollingFlag,
utils.RollupGasPriceOracleAddressFlag,
utils.RollupEnforceFeesFlag,
utils.GasPriceOracleOwnerAddress,
}

rpcFlags = []cli.Flag{
Expand Down
5 changes: 1 addition & 4 deletions l2geth/cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupMaxCalldataSizeFlag,
utils.RollupDataPriceFlag,
utils.RollupExecutionPriceFlag,
utils.RollupBackendFlag,
utils.RollupEnableL2GasPollingFlag,
utils.RollupGasPriceOracleAddressFlag,
utils.RollupEnforceFeesFlag,
utils.GasPriceOracleOwnerAddress,
},
},
{
Expand Down
47 changes: 10 additions & 37 deletions l2geth/cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,6 @@ var (
Value: "l1",
EnvVar: "ROLLUP_BACKEND",
}
// Flag to enable verifier mode
RollupEnableVerifierFlag = cli.BoolFlag{
Name: "rollup.verifier",
Usage: "Enable the verifier",
Expand Down Expand Up @@ -894,34 +893,16 @@ var (
Value: eth.DefaultConfig.Rollup.MaxCallDataSize,
EnvVar: "ROLLUP_MAX_CALLDATA_SIZE",
}
RollupDataPriceFlag = BigFlag{
Name: "rollup.dataprice",
Usage: "The L1 calldata price to use for the sequencer fees",
Value: eth.DefaultConfig.Rollup.DataPrice,
EnvVar: "ROLLUP_DATAPRICE",
}
RollupExecutionPriceFlag = BigFlag{
Name: "rollup.executionprice",
Usage: "The execution gas price to use for the sequencer fees",
Value: eth.DefaultConfig.Rollup.ExecutionPrice,
EnvVar: "ROLLUP_EXECUTIONPRICE",
}
RollupGasPriceOracleAddressFlag = cli.StringFlag{
Name: "rollup.gaspriceoracleaddress",
Usage: "Address of the rollup gas price oracle",
Value: "0x0000000000000000000000000000000000000000",
EnvVar: "ROLLUP_GAS_PRICE_ORACLE_ADDRESS",
}
RollupEnableL2GasPollingFlag = cli.BoolFlag{
Name: "rollup.enablel2gaspolling",
Usage: "Poll for the L2 gas price from the L2 state",
EnvVar: "ROLLUP_ENABLE_L2_GAS_POLLING",
}
RollupEnforceFeesFlag = cli.BoolFlag{
Name: "rollup.enforcefeesflag",
Usage: "Disable transactions with 0 gas price",
EnvVar: "ROLLUP_ENFORCE_FEES",
}
GasPriceOracleOwnerAddress = cli.StringFlag{
Name: "rollup.gaspriceoracleowneraddress",
Usage: "Owner of the OVM_GasPriceOracle",
EnvVar: "ROLLUP_GAS_PRICE_ORACLE_OWNER_ADDRESS",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1199,11 +1180,9 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(RollupTimstampRefreshFlag.Name) {
cfg.TimestampRefreshThreshold = ctx.GlobalDuration(RollupTimstampRefreshFlag.Name)
}
if ctx.GlobalIsSet(RollupDataPriceFlag.Name) {
cfg.DataPrice = GlobalBig(ctx, RollupDataPriceFlag.Name)
}
if ctx.GlobalIsSet(RollupExecutionPriceFlag.Name) {
cfg.ExecutionPrice = GlobalBig(ctx, RollupExecutionPriceFlag.Name)
if ctx.GlobalIsSet(GasPriceOracleOwnerAddress.Name) {
addr := ctx.GlobalString(GasPriceOracleOwnerAddress.Name)
cfg.GasPriceOracleOwnerAddress = common.HexToAddress(addr)
}
if ctx.GlobalIsSet(RollupBackendFlag.Name) {
val := ctx.GlobalString(RollupBackendFlag.Name)
Expand All @@ -1214,13 +1193,6 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
}
cfg.Backend = backend
}
if ctx.GlobalIsSet(RollupGasPriceOracleAddressFlag.Name) {
addr := ctx.GlobalString(RollupGasPriceOracleAddressFlag.Name)
cfg.GasPriceOracleAddress = common.HexToAddress(addr)
}
if ctx.GlobalIsSet(RollupEnableL2GasPollingFlag.Name) {
cfg.EnableL2GasPolling = true
}
if ctx.GlobalIsSet(RollupEnforceFeesFlag.Name) {
cfg.EnforceFees = true
}
Expand Down Expand Up @@ -1791,8 +1763,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
l1FeeWalletAddress := cfg.Rollup.L1FeeWalletAddress
addrManagerOwnerAddress := cfg.Rollup.AddressManagerOwnerAddress
l1ETHGatewayAddress := cfg.Rollup.L1ETHGatewayAddress
gpoOwnerAddress := cfg.Rollup.GasPriceOracleOwnerAddress
stateDumpPath := cfg.Rollup.StateDumpPath
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, xdomainAddress, l1ETHGatewayAddress, addrManagerOwnerAddress, l1FeeWalletAddress, stateDumpPath, chainID, gasLimit)
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, xdomainAddress, l1ETHGatewayAddress, addrManagerOwnerAddress, gpoOwnerAddress, l1FeeWalletAddress, stateDumpPath, chainID, gasLimit)
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
cfg.Miner.GasPrice = big.NewInt(1)
}
Expand Down
2 changes: 1 addition & 1 deletion l2geth/console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}, common.Address{}, common.Address{}, "", nil, 12000000),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}, common.Address{}, common.Address{}, common.Address{}, "", nil, 12000000),
Miner: miner.Config{
Etherbase: common.HexToAddress(testAddress),
},
Expand Down
17 changes: 13 additions & 4 deletions l2geth/core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Genesis struct {
L1CrossDomainMessengerAddress common.Address `json:"-"`
AddressManagerOwnerAddress common.Address `json:"-"`
L1ETHGatewayAddress common.Address `json:"-"`
GasPriceOracleOwnerAddress common.Address `json:"-"`
ChainID *big.Int `json:"-"`
}

Expand Down Expand Up @@ -267,7 +268,7 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
}

// ApplyOvmStateToState applies the initial OVM state to a state object.
func ApplyOvmStateToState(statedb *state.StateDB, stateDump *dump.OvmDump, l1XDomainMessengerAddress common.Address, l1ETHGatewayAddress common.Address, addrManagerOwnerAddress common.Address, l1FeeWalletAddress common.Address, chainID *big.Int, gasLimit uint64) {
func ApplyOvmStateToState(statedb *state.StateDB, stateDump *dump.OvmDump, l1XDomainMessengerAddress, l1ETHGatewayAddress, addrManagerOwnerAddress, gpoOwnerAddress, l1FeeWalletAddress common.Address, chainID *big.Int, gasLimit uint64) {
if len(stateDump.Accounts) == 0 {
return
}
Expand Down Expand Up @@ -305,7 +306,7 @@ func ApplyOvmStateToState(statedb *state.StateDB, stateDump *dump.OvmDump, l1XDo
log.Info("Setting OVM_L1ETHGateway in OVM_ETH", "address", l1ETHGatewayAddress.Hex())
if strings.Contains(OVM_ETH.Code, "a84ce98") {
// Set the gateway of OVM_ETH at new dump
log.Info("Detected current OVM_ETH dump, setting slot 0x1 ")
log.Info("Detected current OVM_ETH dump, setting slot 0x1")
l1GatewaySlot := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001")
l1GatewayValue := common.BytesToHash(l1ETHGatewayAddress.Bytes())
statedb.SetState(OVM_ETH.Address, l1GatewaySlot, l1GatewayValue)
Expand Down Expand Up @@ -337,6 +338,13 @@ func ApplyOvmStateToState(statedb *state.StateDB, stateDump *dump.OvmDump, l1XDo
l1FeeWalletSlot := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
l1FeeWalletValue := common.BytesToHash(l1FeeWalletAddress.Bytes())
statedb.SetState(OVM_SequencerFeeVault.Address, l1FeeWalletSlot, l1FeeWalletValue)
GasPriceOracle, ok := stateDump.Accounts["OVM_GasPriceOracle"]
if ok {
ownerSlot := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
ownerValue := common.BytesToHash(gpoOwnerAddress.Bytes())
statedb.SetState(GasPriceOracle.Address, ownerSlot, ownerValue)
log.Info("Setting GasPriceOracle Owner", "owner", gpoOwnerAddress.Hex())
}
}
}

Expand All @@ -350,7 +358,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {

if vm.UsingOVM {
// OVM_ENABLED
ApplyOvmStateToState(statedb, g.Config.StateDump, g.L1CrossDomainMessengerAddress, g.L1ETHGatewayAddress, g.AddressManagerOwnerAddress, g.L1FeeWalletAddress, g.ChainID, g.GasLimit)
ApplyOvmStateToState(statedb, g.Config.StateDump, g.L1CrossDomainMessengerAddress, g.L1ETHGatewayAddress, g.AddressManagerOwnerAddress, g.GasPriceOracleOwnerAddress, g.L1FeeWalletAddress, g.ChainID, g.GasLimit)
}

for addr, account := range g.Alloc {
Expand Down Expand Up @@ -477,7 +485,7 @@ func DefaultGoerliGenesisBlock() *Genesis {
}

// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress common.Address, l1ETHGatewayAddress common.Address, addrManagerOwnerAddress common.Address, l1FeeWalletAddress common.Address, stateDumpPath string, chainID *big.Int, gasLimit uint64) *Genesis {
func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress common.Address, l1ETHGatewayAddress common.Address, addrManagerOwnerAddress, gpoOwnerAddress, l1FeeWalletAddress common.Address, stateDumpPath string, chainID *big.Int, gasLimit uint64) *Genesis {
// Override the default period to the user requested one
config := *params.AllCliqueProtocolChanges
config.Clique.Period = period
Expand Down Expand Up @@ -536,6 +544,7 @@ func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress comm
L1FeeWalletAddress: l1FeeWalletAddress,
AddressManagerOwnerAddress: addrManagerOwnerAddress,
L1ETHGatewayAddress: l1ETHGatewayAddress,
GasPriceOracleOwnerAddress: gpoOwnerAddress,
ChainID: config.ChainID,
}
}
Expand Down
4 changes: 2 additions & 2 deletions l2geth/eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM, "data-price", config.Rollup.DataPrice, "execution-price", config.Rollup.ExecutionPrice)
log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
// create the Rollup GPO and allow the API backend and the sync service to access it
rollupGpo := gasprice.NewRollupOracle(config.Rollup.DataPrice, config.Rollup.ExecutionPrice)
rollupGpo := gasprice.NewRollupOracle()
eth.APIBackend.rollupGpo = rollupGpo
eth.syncService.RollupGpo = rollupGpo
return eth, nil
Expand Down
2 changes: 0 additions & 2 deletions l2geth/eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ var DefaultConfig = Config{
// is additional overhead that is unaccounted. Round down to 127000 for
// safety.
MaxCallDataSize: 127000,
DataPrice: big.NewInt(100 * params.GWei),
ExecutionPrice: big.NewInt(0),
},
DiffDbCache: 256,
}
Expand Down
8 changes: 5 additions & 3 deletions l2geth/eth/gasprice/rollup_gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ type RollupOracle struct {
}

// NewRollupOracle returns an initialized RollupOracle
func NewRollupOracle(l1GasPrice *big.Int, l2GasPrice *big.Int) *RollupOracle {
func NewRollupOracle() *RollupOracle {
return &RollupOracle{
l1GasPrice: l1GasPrice,
l2GasPrice: l2GasPrice,
l1GasPrice: new(big.Int),
l2GasPrice: new(big.Int),
l1GasPriceLock: sync.RWMutex{},
l2GasPriceLock: sync.RWMutex{},
}
}

Expand Down
6 changes: 1 addition & 5 deletions l2geth/rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Config struct {
L1FeeWalletAddress common.Address
AddressManagerOwnerAddress common.Address
L1ETHGatewayAddress common.Address
GasPriceOracleAddress common.Address
GasPriceOracleOwnerAddress common.Address
// Turns on checking of state for L2 gas price
EnableL2GasPolling bool
// Deployment Height of the canonical transaction chain
Expand All @@ -35,10 +35,6 @@ type Config struct {
PollInterval time.Duration
// Interval for updating the timestamp
TimestampRefreshThreshold time.Duration
// The gas price to use when estimating L1 calldata publishing costs
DataPrice *big.Int
// The gas price to use for L2 congestion costs
ExecutionPrice *big.Int
// Represents the source of the transactions that is being synced
Backend Backend
// Only accept transactions with fees
Expand Down
12 changes: 2 additions & 10 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var errShortRemoteTip = errors.New("Unexpected remote less than tip")
// L2GasPrice slot refers to the storage slot that the execution price is stored
// in the L2 predeploy contract, the GasPriceOracle
var l2GasPriceSlot = common.BigToHash(big.NewInt(1))
var l2GasPriceOracleAddress = common.HexToAddress("0x420000000000000000000000000000000000000F")

// SyncService implements the main functionality around pulling in transactions
// and executing them. It can be configured to run in both sequencer mode and in
Expand All @@ -57,8 +58,6 @@ type SyncService struct {
timestampRefreshThreshold time.Duration
chainHeadCh chan core.ChainHeadEvent
backend Backend
gpoAddress common.Address
enableL2GasPolling bool
enforceFees bool
}

Expand Down Expand Up @@ -112,8 +111,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
pollInterval: pollInterval,
timestampRefreshThreshold: timestampRefreshThreshold,
backend: cfg.Backend,
gpoAddress: cfg.GasPriceOracleAddress,
enableL2GasPolling: cfg.EnableL2GasPolling,
enforceFees: cfg.EnforceFees,
}

Expand Down Expand Up @@ -435,11 +432,6 @@ func (s *SyncService) updateL1GasPrice() error {
// price oracle at the state that corresponds to the state root. If no state
// root is passed in, then the tip is used.
func (s *SyncService) updateL2GasPrice(hash *common.Hash) error {
// TODO(mark): this is temporary and will be able to be rmoved when the
// OVM_GasPriceOracle is moved into the predeploy contracts
if !s.enableL2GasPolling {
return nil
}
var state *state.StateDB
var err error
if hash != nil {
Expand All @@ -450,7 +442,7 @@ func (s *SyncService) updateL2GasPrice(hash *common.Hash) error {
if err != nil {
return err
}
result := state.GetState(s.gpoAddress, l2GasPriceSlot)
result := state.GetState(l2GasPriceOracleAddress, l2GasPriceSlot)
s.RollupGpo.SetL2GasPrice(result.Big())
return nil
}
Expand Down
8 changes: 3 additions & 5 deletions l2geth/rollup/sync_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,6 @@ func TestSyncServiceL2GasPrice(t *testing.T) {
if err != nil {
t.Fatal(err)
}
service.enableL2GasPolling = true
service.gpoAddress = common.HexToAddress("0xF20b338752976878754518183873602902360704")

price, err := service.RollupGpo.SuggestL2GasPrice(context.Background())
if err != nil {
Expand All @@ -533,7 +531,7 @@ func TestSyncServiceL2GasPrice(t *testing.T) {
t.Fatal("Cannot get state db")
}
l2GasPrice := big.NewInt(100000000000)
state.SetState(service.gpoAddress, l2GasPriceSlot, common.BigToHash(l2GasPrice))
state.SetState(l2GasPriceOracleAddress, l2GasPriceSlot, common.BigToHash(l2GasPrice))
root, _ := state.Commit(false)

service.updateL2GasPrice(&root)
Expand Down Expand Up @@ -695,7 +693,7 @@ func newTestSyncService(isVerifier bool) (*SyncService, chan core.NewTxsEvent, e
return nil, nil, nil, fmt.Errorf("Cannot initialize syncservice: %w", err)
}

service.RollupGpo = gasprice.NewRollupOracle(big.NewInt(0), big.NewInt(0))
service.RollupGpo = gasprice.NewRollupOracle()
txCh := make(chan core.NewTxsEvent, 1)
sub := service.SubscribeNewTxsEvent(txCh)

Expand All @@ -717,7 +715,7 @@ type mockClient struct {
func setupMockClient(service *SyncService, responses map[string]interface{}) {
client := newMockClient(responses)
service.client = client
service.RollupGpo = gasprice.NewRollupOracle(big.NewInt(0), big.NewInt(0))
service.RollupGpo = gasprice.NewRollupOracle()
}

func newMockClient(responses map[string]interface{}) *mockClient {
Expand Down

0 comments on commit 9e3b656

Please sign in to comment.