Commit 989a3027 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

l2geth: optimize loops (#1027)

* l2geth: optimize loops

* l2geth: stop ticker when done

* l2geth: don't wait for first tick

* chore: add changeset
parent 859437f9
---
'@eth-optimism/l2geth': patch
---
Optimize main polling loops
......@@ -138,17 +138,18 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
}
// Wait until the remote service is done syncing
for {
t := time.NewTicker(10 * time.Second)
for ; true; <-t.C {
status, err := service.client.SyncStatus(service.backend)
if err != nil {
log.Error("Cannot get sync status")
continue
}
if !status.Syncing {
t.Stop()
break
}
log.Info("Still syncing", "index", status.CurrentTransactionIndex, "tip", status.HighestKnownTransactionIndex)
time.Sleep(10 * time.Second)
}
// Initialize the latest L1 data here to make sure that
......@@ -320,7 +321,8 @@ func (s *SyncService) Stop() error {
// VerifierLoop is the main loop for Verifier mode
func (s *SyncService) VerifierLoop() {
log.Info("Starting Verifier Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold)
for {
t := time.NewTicker(s.pollInterval)
for ; true; <-t.C {
if err := s.updateL1GasPrice(); err != nil {
log.Error("Cannot update L1 gas price", "msg", err)
}
......@@ -330,7 +332,6 @@ func (s *SyncService) VerifierLoop() {
if err := s.updateL2GasPrice(nil); err != nil {
log.Error("Cannot update L2 gas price", "msg", err)
}
time.Sleep(s.pollInterval)
}
}
......@@ -354,7 +355,8 @@ func (s *SyncService) verify() error {
// transactions and then updates the EthContext.
func (s *SyncService) SequencerLoop() {
log.Info("Starting Sequencer Loop", "poll-interval", s.pollInterval, "timestamp-refresh-threshold", s.timestampRefreshThreshold)
for {
t := time.NewTicker(s.pollInterval)
for ; true; <-t.C {
if err := s.updateL1GasPrice(); err != nil {
log.Error("Cannot update L1 gas price", "msg", err)
}
......@@ -370,7 +372,6 @@ func (s *SyncService) SequencerLoop() {
if err := s.updateContext(); err != nil {
log.Error("Could not update execution context", "error", err)
}
time.Sleep(s.pollInterval)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment