Skip to content

Commit

Permalink
fix RPC closebatch executor error (#3272)
Browse files Browse the repository at this point in the history
* fix RPC closebatch executor error

* fix close batch

* fix close batch

* fix close batch

* fix close batch

* fix close batch

---------

Co-authored-by: agnusmor <[email protected]>
  • Loading branch information
ToniRamirezM and agnusmor authored Feb 14, 2024
1 parent 0171536 commit eb3ae9b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sequencer
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"

Expand All @@ -11,6 +12,7 @@ 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/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -404,7 +406,7 @@ func (f *finalizer) batchSanityCheck(ctx context.Context, batchNum uint64, initi
return nil, ErrProcessBatch
}

if batchResponse.ExecutorError != nil {
if batchResponse.ExecutorError != nil && !errors.Is(batchResponse.ExecutorError, runtime.ErrExecutorErrorCloseBatch) {
log.Errorf("executor error when reprocessing batch %d, error: %v", batch.BatchNumber, batchResponse.ExecutorError)
reprocessError(batch)
return nil, ErrExecutorError
Expand Down
3 changes: 3 additions & 0 deletions sequencer/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,9 @@ func TestNewFinalizer(t *testing.T) {
func TestFinalizer_closeWIPBatch(t *testing.T) {
// arrange
f = setupFinalizer(true)
// set wip batch has at least one L2 block as it can not be closed empty
f.wipBatch.countOfL2Blocks++

usedResources := getUsedBatchResources(f.batchConstraints, f.wipBatch.imRemainingResources)

receipt := state.ProcessingReceipt{
Expand Down
10 changes: 6 additions & 4 deletions sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sequencer

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -11,6 +12,7 @@ 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/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -279,13 +281,13 @@ func (f *finalizer) executeL2Block(ctx context.Context, initialStateRoot common.
return nil, 0, err
}

if batchResponse.ExecutorError != nil {
executeL2BLockError(err)
if batchResponse.ExecutorError != nil && !errors.Is(batchResponse.ExecutorError, runtime.ErrExecutorErrorCloseBatch) {
executeL2BLockError(batchResponse.ExecutorError)
return nil, 0, ErrExecutorError
}

if batchResponse.IsRomOOCError {
executeL2BLockError(err)
executeL2BLockError(batchResponse.RomError_V2)
return nil, 0, ErrProcessBatchOOC
}

Expand Down Expand Up @@ -557,7 +559,7 @@ func (f *finalizer) executeNewWIPL2Block(ctx context.Context) (*state.ProcessBat
return nil, err
}

if batchResponse.ExecutorError != nil {
if batchResponse.ExecutorError != nil && !errors.Is(batchResponse.ExecutorError, runtime.ErrExecutorErrorCloseBatch) {
return nil, ErrExecutorError
}

Expand Down
2 changes: 1 addition & 1 deletion state/batchV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (s *State) sendBatchRequestToExecutorV2(ctx context.Context, batchRequest *
log.Errorf("error executor ProcessBatchV2 response: %v", batchResponse)
} else {
batchResponseToString := processBatchResponseToString(newBatchNum, batchResponse, elapsed)
if batchResponse.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR {
if batchResponse.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR && batchResponse.Error != executor.ExecutorError_EXECUTOR_ERROR_CLOSE_BATCH {
err = executor.ExecutorErr(batchResponse.Error)
log.Warnf("executor batch %d response, executor error: %v", newBatchNum, err)
log.Warn(batchResponseToString)
Expand Down
2 changes: 1 addition & 1 deletion state/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
endTime = time.Now()
if err != nil {
return nil, err
} else if processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR {
} else if processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR && processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_CLOSE_BATCH {
err = executor.ExecutorErr(processBatchResponseV2.Error)
s.eventLog.LogExecutorErrorV2(ctx, processBatchResponseV2.Error, processBatchRequestV2)
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (s *State) internalProcessUnsignedTransactionV2(ctx context.Context, tx *ty
}
}

if err == nil && processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR {
if err == nil && processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR && processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_CLOSE_BATCH {
err = executor.ExecutorErr(processBatchResponseV2.Error)
s.eventLog.LogExecutorErrorV2(ctx, processBatchResponseV2.Error, processBatchRequestV2)
return nil, err
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func (s *State) internalTestGasEstimationTransactionV2(ctx context.Context, batc
log.Errorf("error estimating gas: %v", err)
return false, false, gasUsed, nil, err
}
if processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR {
if processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_NO_ERROR && processBatchResponseV2.Error != executor.ExecutorError_EXECUTOR_ERROR_CLOSE_BATCH {
err = executor.ExecutorErr(processBatchResponseV2.Error)
s.eventLog.LogExecutorErrorV2(ctx, processBatchResponseV2.Error, processBatchRequestV2)
return false, false, gasUsed, nil, err
Expand Down

0 comments on commit eb3ae9b

Please sign in to comment.