Skip to content

Commit

Permalink
synchronizer: remove fatals (0xPolygonHermez#3093)
Browse files Browse the repository at this point in the history
* removed fatals
  • Loading branch information
joanestebanr authored Jan 18, 2024
1 parent 7c7a7d8 commit 1690310
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const (
NothingProcessMode BatchProcessMode = "nothing"
)

var (
// ErrFatalBatchDesynchronized is the error when the batch is desynchronized
ErrFatalBatchDesynchronized = fmt.Errorf("batch desynchronized")
)

// ProcessData contains the data required to process a batch
type ProcessData struct {
BatchNumber uint64
Expand Down Expand Up @@ -322,10 +327,10 @@ func isTrustedBatchClosed(batch *types.Batch) bool {

func checkStateRootAndLER(batchNumber uint64, expectedStateRoot common.Hash, expectedLER common.Hash, calculatedStateRoot common.Hash, calculatedLER common.Hash) error {
if calculatedStateRoot != expectedStateRoot {
return fmt.Errorf("batch %v: stareRoot calculated [%s] is different from the one in the batch [%s]", batchNumber, calculatedStateRoot, expectedStateRoot)
return fmt.Errorf("batch %v: stareRoot calculated [%s] is different from the one in the batch [%s] err:%w", batchNumber, calculatedStateRoot, expectedStateRoot, ErrFatalBatchDesynchronized)
}
if calculatedLER != expectedLER {
return fmt.Errorf("batch %v: LocalExitRoot calculated [%s] is different from the one in the batch [%s]", batchNumber, calculatedLER, expectedLER)
return fmt.Errorf("batch %v: LocalExitRoot calculated [%s] is different from the one in the batch [%s] err:%w", batchNumber, calculatedLER, expectedLER, ErrFatalBatchDesynchronized)
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ var (
ErrNotImplemented = errors.New("not implemented")
// ErrFailExecuteBatch is returned when the batch is not executed correctly
ErrFailExecuteBatch = errors.New("fail execute batch")
// ErrNotExpectedBathResult is returned when the batch result is not the expected (must match Trusted)
ErrNotExpectedBathResult = errors.New("not expected batch result (differ from Trusted Batch)")
// ErrCriticalClosedBatchDontContainExpectedData is returnted when try to close a batch that is already close but data doesnt match
ErrCriticalClosedBatchDontContainExpectedData = errors.New("when closing the batch, the batch is already close, but the data on state doesnt match the expected")
// ErrCantReprocessBatchMissingPreviousStateBatch can't reprocess a divergent batch because is missing previous state batch
Expand Down Expand Up @@ -133,8 +131,7 @@ func (b *SyncTrustedBatchExecutorForEtrog) FullProcess(ctx context.Context, data

err = batchResultSanityCheck(data, processBatchResp, debugStr)
if err != nil {
// TODO: Remove this fatal
log.Fatalf("%s error batchResultSanityCheck. Error: %s", data.DebugPrefix, err.Error())
log.Errorf("%s error batchResultSanityCheck. Error: %s", data.DebugPrefix, err.Error())
return nil, err
}

Expand Down Expand Up @@ -204,8 +201,7 @@ func (b *SyncTrustedBatchExecutorForEtrog) IncrementalProcess(ctx context.Contex

err = batchResultSanityCheck(data, processBatchResp, debugStr)
if err != nil {
// TODO: Remove this fatal
log.Fatalf("%s error batchResultSanityCheck. Error: %s", data.DebugPrefix, err.Error())
log.Errorf("%s error batchResultSanityCheck. Error: %s", data.DebugPrefix, err.Error())
return nil, err
}

Expand Down Expand Up @@ -276,15 +272,15 @@ func batchResultSanityCheck(data *l2_shared.ProcessData, processBatchResp *state
return nil
}
if processBatchResp.NewStateRoot == state.ZeroHash {
return fmt.Errorf("%s processBatchResp.NewStateRoot is ZeroHash. Err: %w", debugStr, ErrNotExpectedBathResult)
return fmt.Errorf("%s processBatchResp.NewStateRoot is ZeroHash. Err: %w", debugStr, l2_shared.ErrFatalBatchDesynchronized)
}
if processBatchResp.NewStateRoot != data.TrustedBatch.StateRoot {
return fmt.Errorf("%s processBatchResp.NewStateRoot(%s) != data.TrustedBatch.StateRoot(%s). Err: %w", debugStr,
processBatchResp.NewStateRoot.String(), data.TrustedBatch.StateRoot.String(), ErrNotExpectedBathResult)
processBatchResp.NewStateRoot.String(), data.TrustedBatch.StateRoot.String(), l2_shared.ErrFatalBatchDesynchronized)
}
if processBatchResp.NewLocalExitRoot != data.TrustedBatch.LocalExitRoot {
return fmt.Errorf("%s processBatchResp.NewLocalExitRoot(%s) != data.StateBatch.LocalExitRoot(%s). Err: %w", debugStr,
processBatchResp.NewLocalExitRoot.String(), data.TrustedBatch.LocalExitRoot.String(), ErrNotExpectedBathResult)
processBatchResp.NewLocalExitRoot.String(), data.TrustedBatch.LocalExitRoot.String(), l2_shared.ErrFatalBatchDesynchronized)
}
// We can't check AccInputHash because we dont have timeLimit neither L1InfoRoot used to create the batch
// is going to be update from L1
Expand Down
10 changes: 3 additions & 7 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ func NewSynchronizer(
switch cfg.L1SynchronizationMode {
case ParallelMode:
log.Info("L1SynchronizationMode is parallel")
var err error
res.l1SyncOrchestration, err = newL1SyncParallel(ctx, cfg, etherManForL1, res, runInDevelopmentMode)
if err != nil {
log.Fatalf("Can't initialize L1SyncParallel. Error: %s", err)
}
res.l1SyncOrchestration = newL1SyncParallel(ctx, cfg, etherManForL1, res, runInDevelopmentMode)
case SequentialMode:
log.Info("L1SynchronizationMode is sequential")
default:
Expand All @@ -132,7 +128,7 @@ func NewSynchronizer(

var waitDuration = time.Duration(0)

func newL1SyncParallel(ctx context.Context, cfg Config, etherManForL1 []EthermanInterface, sync *ClientSynchronizer, runExternalControl bool) (*l1_parallel_sync.L1SyncOrchestration, error) {
func newL1SyncParallel(ctx context.Context, cfg Config, etherManForL1 []EthermanInterface, sync *ClientSynchronizer, runExternalControl bool) *l1_parallel_sync.L1SyncOrchestration {
chIncommingRollupInfo := make(chan l1_parallel_sync.L1SyncMessage, cfg.L1ParallelSynchronization.MaxPendingNoProcessedBlocks)
cfgConsumer := l1_parallel_sync.ConfigConsumer{
ApplyAfterNumRollupReceived: cfg.L1ParallelSynchronization.PerformanceWarning.ApplyAfterNumRollupReceived,
Expand Down Expand Up @@ -161,7 +157,7 @@ func newL1SyncParallel(ctx context.Context, cfg Config, etherManForL1 []Etherman
externalControl := newExternalControl(l1DataRetriever, l1SyncOrchestration)
externalControl.start()
}
return l1SyncOrchestration, nil
return l1SyncOrchestration
}

// CleanTrustedState Clean cache of TrustedBatches and StateRoot
Expand Down

0 comments on commit 1690310

Please sign in to comment.