Skip to content

Commit

Permalink
fix #3581 synchronizer panic synchronizing from trusted node (#3582)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr authored Apr 23, 2024
1 parent 2b972bc commit 7a0b72d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func (s *ProcessorTrustedBatchSync) AddPostChecker(checker PostClosedBatchChecke

// ProcessTrustedBatch processes a trusted batch and return the new state
func (s *ProcessorTrustedBatchSync) ProcessTrustedBatch(ctx context.Context, trustedBatch *types.Batch, status TrustedState, dbTx pgx.Tx, debugPrefix string) (*TrustedState, error) {
if trustedBatch == nil {
log.Errorf("%s trustedBatch is nil, it never should be nil", debugPrefix)
return nil, fmt.Errorf("%s trustedBatch is nil, it never should be nil", debugPrefix)
}
log.Debugf("%s Processing trusted batch: %v", debugPrefix, trustedBatch.Number)
stateCurrentBatch, statePreviousBatch := s.GetCurrentAndPreviousBatchFromCache(&status)
if s.l1SyncChecker != nil {
Expand Down
15 changes: 15 additions & 0 deletions synchronizer/l2_sync/l2_shared/trusted_batches_retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func isSyncrhonizedTrustedState(lastTrustedStateBatchNumber uint64, latestSynced
return lastTrustedStateBatchNumber < latestSyncedBatch
}

func sanityCheckBatchReturnedByTrusted(batch *types.Batch, expectedBatchNumber uint64) error {
if batch == nil {
return fmt.Errorf("batch %d is nil", expectedBatchNumber)
}
if uint64(batch.Number) != expectedBatchNumber {
return fmt.Errorf("batch %d is not the expected batch %d", batch.Number, expectedBatchNumber)
}
return nil
}

func (s *TrustedBatchesRetrieve) syncTrustedBatchesToFrom(ctx context.Context, latestSyncedBatch uint64, lastTrustedStateBatchNumber uint64) error {
batchNumberToSync := max(latestSyncedBatch, s.firstBatchNumberToSync)
for batchNumberToSync <= lastTrustedStateBatchNumber {
Expand All @@ -120,6 +130,11 @@ func (s *TrustedBatchesRetrieve) syncTrustedBatchesToFrom(ctx context.Context, l
log.Warnf("%s failed to get batch %d from trusted state. Error: %v", debugPrefix, batchNumberToSync, err)
return err
}
err = sanityCheckBatchReturnedByTrusted(batchToSync, batchNumberToSync)
if err != nil {
log.Warnf("%s sanity check over Batch returned by Trusted-RPC failed: %v", debugPrefix, err)
return err
}

dbTx, err := s.state.BeginStateTransaction(ctx)
if err != nil {
Expand Down

0 comments on commit 7a0b72d

Please sign in to comment.