diff --git a/.changeset/tough-bugs-invent.md b/.changeset/tough-bugs-invent.md new file mode 100644 index 00000000000..87c8d37db40 --- /dev/null +++ b/.changeset/tough-bugs-invent.md @@ -0,0 +1,5 @@ +--- +"@eth-optimism/l2geth": patch +--- + +Allow gas estimation for replicas diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 4a8864e5bc5..3da9dc044ba 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -296,6 +296,9 @@ func (s *SyncService) Stop() error { func (s *SyncService) VerifierLoop() { log.Info("Starting Verifier Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { + if err := s.updateL1GasPrice(); err != nil { + log.Error("Cannot update L1 gas price", "msg", err) + } if err := s.verify(); err != nil { log.Error("Could not verify", "error", err) } @@ -344,6 +347,9 @@ func (s *SyncService) verify() error { func (s *SyncService) SequencerLoop() { log.Info("Starting Sequencer Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { + if err := s.updateL1GasPrice(); err != nil { + log.Error("Cannot update L1 gas price", "msg", err) + } s.txLock.Lock() err := s.sequence() if err != nil { @@ -360,14 +366,6 @@ func (s *SyncService) SequencerLoop() { } func (s *SyncService) sequence() error { - // Update to the latest L1 gas price - l1GasPrice, err := s.client.GetL1GasPrice() - if err != nil { - return err - } - s.L1gpo.SetL1GasPrice(l1GasPrice) - log.Info("Adjusted L1 Gas Price", "gasprice", l1GasPrice) - // Only the sequencer needs to poll for enqueue transactions // and then can choose when to apply them. We choose to apply // transactions such that it makes for efficient batch submitting. @@ -445,6 +443,19 @@ func (s *SyncService) sequence() error { return nil } +// updateL1GasPrice queries for the current L1 gas price and then stores it +// in the L1 Gas Price Oracle. This must be called over time to properly +// estimate the transaction fees that the sequencer should charge. +func (s *SyncService) updateL1GasPrice() error { + l1GasPrice, err := s.client.GetL1GasPrice() + if err != nil { + return err + } + s.L1gpo.SetL1GasPrice(l1GasPrice) + log.Info("Adjusted L1 Gas Price", "gasprice", l1GasPrice) + return nil +} + /// Update the execution context's timestamp and blocknumber /// over time. This is only necessary for the sequencer. func (s *SyncService) updateContext() error { diff --git a/l2geth/rollup/sync_service_test.go b/l2geth/rollup/sync_service_test.go index 2f3a981682b..9eefbf00469 100644 --- a/l2geth/rollup/sync_service_test.go +++ b/l2geth/rollup/sync_service_test.go @@ -169,8 +169,8 @@ func TestSyncServiceL1GasPrice(t *testing.T) { t.Fatal("expected 0 gas price, got", gasBefore) } - // run 1 iteration of the eloop - service.sequence() + // Update the gas price + service.updateL1GasPrice() gasAfter, err := service.L1gpo.SuggestDataPrice(context.Background()) if err != nil {