Skip to content

Commit

Permalink
l2geth: replica gas estimation fix (#519)
Browse files Browse the repository at this point in the history
* l2geth: replica must also keep track of gas

* l2geth: refactor sequencer loop

* l2geth: updateL1GasPrice comment

* l2geth: explicitly test gas updating

* l2geth: add changeset
  • Loading branch information
tynes authored Apr 21, 2021
1 parent d6734f6 commit ef40ed7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-bugs-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/l2geth": patch
---

Allow gas estimation for replicas
27 changes: 19 additions & 8 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions l2geth/rollup/sync_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ef40ed7

Please sign in to comment.