Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

l2geth: replica gas estimation fix #519

Merged
merged 5 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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