Skip to content

Commit

Permalink
executor error refactor (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM authored Jul 19, 2023
1 parent e314df2 commit c9b4057
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 42 deletions.
30 changes: 8 additions & 22 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ type Pool struct {
}

type preExecutionResponse struct {
usedZkCounters state.ZKCounters
isOOC bool
isOOG bool
isReverted bool
txResponse *state.ProcessTransactionResponse
usedZkCounters state.ZKCounters
isExecutorLevelError bool
isOOC bool
isOOG bool
isReverted bool
txResponse *state.ProcessTransactionResponse
}

// GasPrices contains the gas prices for L2 and L1
Expand Down Expand Up @@ -170,23 +171,7 @@ func (p *Pool) StoreTx(ctx context.Context, tx types.Transaction, ip string, isW
preExecutionResponse, err := p.preExecuteTx(ctx, tx)
if errors.Is(err, runtime.ErrIntrinsicInvalidBatchGasLimit) {
return ErrGasLimit
} else if errors.Is(err, runtime.ErrFea2Scalar) ||
errors.Is(err, runtime.ErrBalanceMismatch) ||
errors.Is(err, runtime.ErrTos32) {
event := &event.Event{
ReceivedAt: time.Now(),
IPAddress: ip,
Source: event.Source_Node,
Component: event.Component_Pool,
Level: event.Level_Critical,
EventID: event.EventID_ExecutorError,
Description: fmt.Sprintf("Error: %s. TxHash: %s", err.Error(), tx.Hash().String()),
}

err := p.eventLog.LogEvent(ctx, event)
if err != nil {
log.Errorf("error adding event: %v", err)
}
} else if preExecutionResponse.isExecutorLevelError {
// Do not add tx to the pool
return err
} else if err != nil {
Expand Down Expand Up @@ -246,6 +231,7 @@ func (p *Pool) preExecuteTx(ctx context.Context, tx types.Transaction) (preExecu
if processBatchResponse.Responses != nil && len(processBatchResponse.Responses) > 0 {
errorToCheck := processBatchResponse.Responses[0].RomError
response.isReverted = errors.Is(errorToCheck, runtime.ErrExecutionReverted)
response.isExecutorLevelError = processBatchResponse.IsExecutorLevelError
response.isOOC = executor.IsROMOutOfCountersError(executor.RomErrorCode(errorToCheck))
response.isOOG = errors.Is(errorToCheck, runtime.ErrOutOfGas)
response.usedZkCounters = processBatchResponse.UsedZkCounters
Expand Down
21 changes: 1 addition & 20 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/sequencer/metrics"
"github.com/0xPolygonHermez/zkevm-node/state"
stateMetrics "github.com/0xPolygonHermez/zkevm-node/state/metrics"
"github.com/0xPolygonHermez/zkevm-node/state/runtime"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgx/v4"
Expand Down Expand Up @@ -588,26 +587,8 @@ func (f *finalizer) processTransaction(ctx context.Context, tx *TxTracker) (errW
} else if tx != nil && err == nil && !processBatchResponse.IsRomLevelError && len(processBatchResponse.Responses) == 0 {
err = fmt.Errorf("executor returned no errors and no responses for tx: %s", tx.HashStr)
f.halt(ctx, err)
} else if tx != nil && processBatchResponse.ExecutorError == runtime.ErrBalanceMismatch ||
processBatchResponse.ExecutorError == runtime.ErrFea2Scalar ||
processBatchResponse.ExecutorError == runtime.ErrTos32 {
} else if tx != nil && processBatchResponse.IsExecutorLevelError {
log.Errorf("error received from executor. Error: %v", err)
// Record event
event := event.Event{
ReceivedAt: time.Now(),
Source: event.Source_Node,
Component: event.Component_Executor,
Level: event.Level_Critical,
EventID: event.EventID_ExecutorError,
Description: processBatchResponse.ExecutorError.Error(),
Data: f.processRequest.Transactions,
Json: fmt.Sprintf("processBatchResponse: %#v. f.processRequest: %#v", processBatchResponse, f.processRequest),
}
err := f.eventLog.LogEvent(ctx, &event)
if err != nil {
log.Error("error storing event on db. Error: %s. Event: %#v", err.Error(), event)
}

// Delete tx from the worker
f.worker.DeleteTx(tx.Hash, tx.From)

Expand Down

0 comments on commit c9b4057

Please sign in to comment.