Skip to content

Commit

Permalink
l2geth: fix error handling for get tx batch
Browse files Browse the repository at this point in the history
  • Loading branch information
tynes committed Apr 22, 2021
1 parent 5df96f7 commit 895cb81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions l2geth/rollup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
28 changes: 15 additions & 13 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -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")
Expand Down

0 comments on commit 895cb81

Please sign in to comment.