Skip to content

Commit

Permalink
fix error handling in sequencer (#1730)
Browse files Browse the repository at this point in the history
* fix error handling in sequencer

* fix error log

* fix error log

* fix error log

* fix test

* fix test
  • Loading branch information
ToniRamirezM committed Mar 3, 2023
1 parent ad4f825 commit 10381d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
16 changes: 13 additions & 3 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (f *finalizer) processTransaction(ctx context.Context, tx *TxTracker) error
}
result, err := f.executor.ProcessBatch(ctx, f.processRequest, false)
if err != nil {
log.Errorf("failed to process transaction, err: %s", err)
log.Errorf("failed to process transaction, isClaim: %v, err: %s", tx.IsClaim, err)
return err
}

Expand Down Expand Up @@ -461,8 +461,8 @@ func (f *finalizer) handleTransactionError(ctx context.Context, result *state.Pr
log.Errorf("failed to update status to failed in the pool for tx: %s, err: %s", tx.Hash.String(), err)
}
}()
} else if executor.IsIntrinsicError(errorCode) {
log.Errorf("intrinsic error, moving tx with Hash: %s to NOT READY, to not ready, err: %s", tx.Hash, txResponse.RomError)
} else if (executor.IsInvalidNonceError(errorCode) || executor.IsInvalidBalanceError(errorCode)) && !tx.IsClaim {
log.Errorf("intrinsic error, moving tx with Hash: %s to NOT READY, err: %s", tx.Hash, txResponse.RomError)
var (
nonce *uint64
balance *big.Int
Expand All @@ -480,6 +480,16 @@ func (f *finalizer) handleTransactionError(ctx context.Context, result *state.Pr
}
}
metrics.WorkerProcessingTime(time.Since(start))
} else {
// Delete the transaction from the efficiency list
f.worker.DeleteTx(tx.Hash, tx.From)
log.Debug("tx deleted from efficiency list", "txHash", tx.Hash.String(), "from", tx.From.Hex(), "isClaim", tx.IsClaim)

// Update the status of the transaction to failed
err := f.dbManager.UpdateTxStatus(ctx, tx.Hash, pool.TxStatusFailed, false)
if err != nil {
log.Errorf("failed to update status to failed in the pool for tx: %s, err: %s", tx.Hash.String(), err)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions sequencer/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ func TestFinalizer_handleTransactionError(t *testing.T) {
},
{
name: "IntrinsicError",
error: pb.RomError(executor.ROM_ERROR_INTRINSIC_INVALID_SIGNATURE),
error: pb.RomError(executor.ROM_ERROR_INTRINSIC_INVALID_NONCE),
expectedMoveCall: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// arrange
if tc.expectedDeleteCall {
workerMock.On("DeleteTx", oldHash, sender).Return().Once()
workerMock.On("DeleteTx", oldHash, sender).Return()
dbManagerMock.On("UpdateTxStatus", ctx, oldHash, pool.TxStatusFailed, false).Return(nil).Once()
dbManagerMock.On("UpdateTxStatus", ctx, oldHash, pool.TxStatusInvalid, false).Return(nil).Once()
dbManagerMock.On("DeleteTransactionFromPool", ctx, tx.Hash).Return(nil).Once()
Expand Down
10 changes: 10 additions & 0 deletions state/runtime/executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ func IsIntrinsicError(error pb.RomError) bool {
return int32(error) >= ROM_ERROR_INTRINSIC_INVALID_SIGNATURE && int32(error) <= ROM_ERROR_INTRINSIC_TX_GAS_OVERFLOW
}

// IsInvalidNonceError indicates if the error is due to a invalid nonce
func IsInvalidNonceError(error pb.RomError) bool {
return int32(error) == ROM_ERROR_INTRINSIC_INVALID_NONCE
}

// IsInvalidBalanceError indicates if the error is due to a invalid balance
func IsInvalidBalanceError(error pb.RomError) bool {
return int32(error) == ROM_ERROR_INTRINSIC_INVALID_BALANCE
}

// ExecutorErr returns an instance of error related to the ExecutorError
func ExecutorErr(errorCode pb.ExecutorError) error {
e := int32(errorCode)
Expand Down

0 comments on commit 10381d5

Please sign in to comment.