Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 7a0b72d

Browse files
authored
fix #3581 synchronizer panic synchronizing from trusted node (#3582)
1 parent 2b972bc commit 7a0b72d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

synchronizer/l2_sync/l2_shared/processor_trusted_batch_sync.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func (s *ProcessorTrustedBatchSync) AddPostChecker(checker PostClosedBatchChecke
171171

172172
// ProcessTrustedBatch processes a trusted batch and return the new state
173173
func (s *ProcessorTrustedBatchSync) ProcessTrustedBatch(ctx context.Context, trustedBatch *types.Batch, status TrustedState, dbTx pgx.Tx, debugPrefix string) (*TrustedState, error) {
174+
if trustedBatch == nil {
175+
log.Errorf("%s trustedBatch is nil, it never should be nil", debugPrefix)
176+
return nil, fmt.Errorf("%s trustedBatch is nil, it never should be nil", debugPrefix)
177+
}
174178
log.Debugf("%s Processing trusted batch: %v", debugPrefix, trustedBatch.Number)
175179
stateCurrentBatch, statePreviousBatch := s.GetCurrentAndPreviousBatchFromCache(&status)
176180
if s.l1SyncChecker != nil {

synchronizer/l2_sync/l2_shared/trusted_batches_retrieve.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ func isSyncrhonizedTrustedState(lastTrustedStateBatchNumber uint64, latestSynced
109109
return lastTrustedStateBatchNumber < latestSyncedBatch
110110
}
111111

112+
func sanityCheckBatchReturnedByTrusted(batch *types.Batch, expectedBatchNumber uint64) error {
113+
if batch == nil {
114+
return fmt.Errorf("batch %d is nil", expectedBatchNumber)
115+
}
116+
if uint64(batch.Number) != expectedBatchNumber {
117+
return fmt.Errorf("batch %d is not the expected batch %d", batch.Number, expectedBatchNumber)
118+
}
119+
return nil
120+
}
121+
112122
func (s *TrustedBatchesRetrieve) syncTrustedBatchesToFrom(ctx context.Context, latestSyncedBatch uint64, lastTrustedStateBatchNumber uint64) error {
113123
batchNumberToSync := max(latestSyncedBatch, s.firstBatchNumberToSync)
114124
for batchNumberToSync <= lastTrustedStateBatchNumber {
@@ -120,6 +130,11 @@ func (s *TrustedBatchesRetrieve) syncTrustedBatchesToFrom(ctx context.Context, l
120130
log.Warnf("%s failed to get batch %d from trusted state. Error: %v", debugPrefix, batchNumberToSync, err)
121131
return err
122132
}
133+
err = sanityCheckBatchReturnedByTrusted(batchToSync, batchNumberToSync)
134+
if err != nil {
135+
log.Warnf("%s sanity check over Batch returned by Trusted-RPC failed: %v", debugPrefix, err)
136+
return err
137+
}
123138

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

0 commit comments

Comments
 (0)