Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3581 synchronizer panic synchronizing from trusted node #3582

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading