Skip to content

Commit

Permalink
Fix/3203 panic if batch process fail and must be closed (0xPolygonHer…
Browse files Browse the repository at this point in the history
…mez#3206)

* synchronizer avoid panic if process trusted batch fails
  • Loading branch information
joanestebanr authored Feb 5, 2024
1 parent 112bdd0 commit a4059e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (s *ProcessorTrustedBatchSync) ExecuteProcessBatch(ctx context.Context, pro
log.Debugf("%s is partially synchronized but we don't have intermediate stateRoot so it needs to be fully reprocessed", processMode.DebugPrefix)
processBatchResp, err = s.Steps.ReProcess(ctx, processMode, dbTx)
}
if processMode.BatchMustBeClosed {
if processBatchResp != nil && err == nil && processMode.BatchMustBeClosed {
err = checkProcessBatchResultMatchExpected(processMode, processBatchResp.ProcessBatchResponse)
if err != nil {
log.Error("%s error verifying batch result! Error: ", processMode.DebugPrefix, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package test_l2_shared

import (
"context"
"errors"
"testing"

"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
Expand All @@ -9,6 +11,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/synchronizer/l2_sync/l2_shared"
mock_l2_shared "github.com/0xPolygonHermez/zkevm-node/synchronizer/l2_sync/l2_shared/mocks"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -321,3 +324,16 @@ func TestGetNextStatusUpdateExecutionResult(t *testing.T) {
require.NoError(t, err)
require.Equal(t, common.HexToHash("0x123"), newStatus.LastTrustedBatches[0].StateRoot)
}

func TestExecuteProcessBatchError(t *testing.T) {
testData := newTestDataForProcessorTrustedBatchSync(t)

data := l2_shared.ProcessData{
Mode: l2_shared.NothingProcessMode,
BatchMustBeClosed: true,
}
returnedError := errors.New("error")
testData.mockExecutor.EXPECT().NothingProcess(mock.Anything, mock.Anything, mock.Anything).Return(nil, returnedError)
_, err := testData.sut.ExecuteProcessBatch(context.Background(), &data, nil)
require.ErrorIs(t, returnedError, err)
}

0 comments on commit a4059e6

Please sign in to comment.