Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error handling in sequencer #1730

Merged
merged 6 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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