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

Commit 4d58b10

Browse files
committed
fix GetBatchTimestamp
1 parent f55bf3f commit 4d58b10

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

state/batch.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,26 @@ func (s *State) GetBatchTimestamp(ctx context.Context, batchNumber uint64, force
584584
return nil, err
585585
}
586586
if forkid >= FORKID_ETROG {
587-
return virtualTimestamp, nil
587+
// If the batch is not virtualized then we will return the timestamp of the last L2 block in the batch
588+
// If the batch doesn't have L2 blocks we will return the timestamp from state.batch (time of batch creation)
589+
if virtualTimestamp == nil {
590+
l2Block, err := s.GetLastL2BlockByBatchNumber(ctx, batchNumber, dbTx)
591+
if err != nil {
592+
if errors.Is(err, pgx.ErrNoRows) {
593+
return batchTimestamp, nil
594+
}
595+
596+
return nil, err
597+
}
598+
599+
if l2Block != nil {
600+
return &l2Block.ReceivedAt, nil
601+
}
602+
603+
return batchTimestamp, nil
604+
} else {
605+
return virtualTimestamp, nil
606+
}
588607
}
589608
return batchTimestamp, nil
590609
}

0 commit comments

Comments
 (0)