From 895cb81f0fd10a6f9aa8bb02146225db2119020c Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 21 Apr 2021 18:01:47 -0700 Subject: [PATCH] l2geth: fix error handling for get tx batch --- l2geth/rollup/client.go | 4 ++-- l2geth/rollup/sync_service.go | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/l2geth/rollup/client.go b/l2geth/rollup/client.go index d44fbf2c8ede..26241f4e821c 100644 --- a/l2geth/rollup/client.go +++ b/l2geth/rollup/client.go @@ -548,8 +548,8 @@ func (c *Client) GetTransactionBatch(index uint64) (*Batch, []*types.Transaction // parseTransactionBatchResponse will turn a TransactionBatchResponse into a // Batch and its corresponding types.Transactions func parseTransactionBatchResponse(txBatch *TransactionBatchResponse, signer *types.OVMSigner) (*Batch, []*types.Transaction, error) { - if txBatch == nil { - return nil, nil, nil + if txBatch == nil || txBatch.Batch == nil { + return nil, nil, errElementNotFound } batch := txBatch.Batch txs := make([]*types.Transaction, len(txBatch.Transactions)) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 628f1045a733..cce4a6fd03dd 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -669,13 +669,13 @@ func (s *SyncService) syncTransactionsToTip(backend Backend) error { for { latest, err := s.client.GetLatestTransaction(backend) - if err != nil { - return fmt.Errorf("Cannot get latest transaction: %w", err) - } - if latest == nil { + if errors.Is(err, errElementNotFound) { log.Info("No transactions to sync") return nil } + if err != nil { + return fmt.Errorf("Cannot get latest transaction: %w", err) + } latestIndex := latest.GetMeta().Index if latestIndex == nil { return errors.New("Latest index is nil") @@ -722,13 +722,13 @@ func (s *SyncService) syncTransactionBatchesToTip() error { for { latest, _, err := s.client.GetLatestTransactionBatch() - if err != nil { - return fmt.Errorf("Cannot get latest transaction batch: %w", err) - } - if latest == nil { + if errors.Is(err, errElementNotFound) { log.Info("No transaction batches to sync") return nil } + if err != nil { + return fmt.Errorf("Cannot get latest transaction batch: %w", err) + } latestIndex := latest.Index nextIndex := s.GetNextVerifiedIndex() @@ -739,7 +739,9 @@ func (s *SyncService) syncTransactionBatchesToTip() error { return fmt.Errorf("Cannot get transaction batch: %w", err) } for _, tx := range txs { - s.applyBatchedTransaction(tx) + if err := s.applyBatchedTransaction(tx); err != nil { + return fmt.Errorf("cannot apply batched transaction: %w", err) + } } } post, _, err := s.client.GetLatestTransactionBatch() @@ -760,13 +762,13 @@ func (s *SyncService) syncQueueToTip() error { for { latest, err := s.client.GetLatestEnqueue() - if err != nil { - return fmt.Errorf("Cannot get latest enqueue transaction: %w", err) - } - if latest == nil { + if errors.Is(err, errElementNotFound) { log.Info("No enqueue transactions to sync") return nil } + if err != nil { + return fmt.Errorf("Cannot get latest enqueue transaction: %w", err) + } latestIndex := latest.GetMeta().QueueIndex if latestIndex == nil { return errors.New("Latest queue transaction has no queue index")