diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index 674c0ea5d2..cce9458b16 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -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 } @@ -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 @@ -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) + } } } diff --git a/sequencer/finalizer_test.go b/sequencer/finalizer_test.go index 27f13ec5af..fe78d2e4bf 100644 --- a/sequencer/finalizer_test.go +++ b/sequencer/finalizer_test.go @@ -238,7 +238,7 @@ 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, }, } @@ -246,7 +246,7 @@ func TestFinalizer_handleTransactionError(t *testing.T) { 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() diff --git a/state/runtime/executor/errors.go b/state/runtime/executor/errors.go index 9c3ef5a0c0..91b4dcb3b9 100644 --- a/state/runtime/executor/errors.go +++ b/state/runtime/executor/errors.go @@ -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)