From c87bf03b7fdcb679b5c27a335ede45e56c667506 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 20 Apr 2021 11:28:16 -0700 Subject: [PATCH 1/5] l2geth: replica must also keep track of gas --- l2geth/rollup/sync_service.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 4a8864e5bc50..9a883c4a6a5e 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,8 +347,13 @@ func (s *SyncService) verify() error { func (s *SyncService) SequencerLoop() { log.Info("Starting Sequencer Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { + err := s.updateL1GasPrice() + if err != nil { + log.Error("Cannot update L1 gas price", "msg", err) + continue + } s.txLock.Lock() - err := s.sequence() + err = s.sequence() if err != nil { log.Error("Could not sequence", "error", err) } @@ -360,14 +368,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 +445,17 @@ func (s *SyncService) sequence() error { return nil } +func (s *SyncService) updateL1GasPrice() 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) + return nil +} + /// Update the execution context's timestamp and blocknumber /// over time. This is only necessary for the sequencer. func (s *SyncService) updateContext() error { From 8300316cac41b283ee3ca5d2ae8feefb223e9af7 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 20 Apr 2021 12:47:26 -0700 Subject: [PATCH 2/5] l2geth: refactor sequencer loop --- l2geth/rollup/sync_service.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 9a883c4a6a5e..5aaa495fffae 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -347,13 +347,11 @@ func (s *SyncService) verify() error { func (s *SyncService) SequencerLoop() { log.Info("Starting Sequencer Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold) for { - err := s.updateL1GasPrice() - if err != nil { + if err := s.updateL1GasPrice(); err != nil { log.Error("Cannot update L1 gas price", "msg", err) - continue } s.txLock.Lock() - err = s.sequence() + err := s.sequence() if err != nil { log.Error("Could not sequence", "error", err) } From 40a595d8466a6d9fc94f317e4aa6d75fd91166f8 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 20 Apr 2021 12:47:49 -0700 Subject: [PATCH 3/5] l2geth: updateL1GasPrice comment --- l2geth/rollup/sync_service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 5aaa495fffae..3da9dc044bac 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -443,8 +443,10 @@ 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 { - // Update to the latest L1 gas price l1GasPrice, err := s.client.GetL1GasPrice() if err != nil { return err From 859c54ee058b330d3489b0888a1530ff49859a6a Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 20 Apr 2021 12:48:22 -0700 Subject: [PATCH 4/5] l2geth: explicitly test gas updating --- l2geth/rollup/sync_service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/l2geth/rollup/sync_service_test.go b/l2geth/rollup/sync_service_test.go index 2f3a981682bd..9eefbf00469f 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 { From fc3c0a68ed6c3567279c9bb3f841d697ecdd203a Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 20 Apr 2021 12:49:26 -0700 Subject: [PATCH 5/5] l2geth: add changeset --- .changeset/tough-bugs-invent.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-bugs-invent.md diff --git a/.changeset/tough-bugs-invent.md b/.changeset/tough-bugs-invent.md new file mode 100644 index 000000000000..87c8d37db407 --- /dev/null +++ b/.changeset/tough-bugs-invent.md @@ -0,0 +1,5 @@ +--- +"@eth-optimism/l2geth": patch +--- + +Allow gas estimation for replicas