@@ -44,6 +44,9 @@ type ChunkProposer struct {
4444 chunkBlocksProposeNotEnoughTotal prometheus.Counter
4545 chunkEstimateBlobSizeTime prometheus.Gauge
4646
47+ // total number of times that chunk proposer stops early due to compressed data compatibility breach
48+ compressedDataCompatibilityBreachTotal prometheus.Counter
49+
4750 chunkProposeBlockHeight prometheus.Gauge
4851 chunkProposeThroughput prometheus.Counter
4952}
@@ -82,6 +85,10 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC
8285 Name : "rollup_propose_chunk_update_info_failure_total" ,
8386 Help : "Total number of propose chunk update info failure total." ,
8487 }),
88+ compressedDataCompatibilityBreachTotal : promauto .With (reg ).NewCounter (prometheus.CounterOpts {
89+ Name : "rollup_propose_chunk_due_to_compressed_data_compatibility_breach_total" ,
90+ Help : "Total number of propose chunk due to compressed data compatibility breach." ,
91+ }),
8592 chunkTxNum : promauto .With (reg ).NewGauge (prometheus.GaugeOpts {
8693 Name : "rollup_propose_chunk_tx_num" ,
8794 Help : "The chunk tx num" ,
@@ -147,6 +154,45 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en
147154 return nil
148155 }
149156
157+ compatibilityBreachOccurred := false
158+
159+ for {
160+ compatible , err := encoding .CheckChunkCompressedDataCompatibility (chunk , codecVersion )
161+ if err != nil {
162+ log .Error ("Failed to check chunk compressed data compatibility" , "start block number" , chunk .Blocks [0 ].Header .Number , "codecVersion" , codecVersion , "err" , err )
163+ return err
164+ }
165+
166+ if compatible {
167+ break
168+ }
169+
170+ compatibilityBreachOccurred = true
171+
172+ if len (chunk .Blocks ) == 1 {
173+ log .Warn ("Disable compression: cannot truncate chunk with only 1 block for compatibility" , "block number" , chunk .Blocks [0 ].Header .Number )
174+ break
175+ }
176+
177+ chunk .Blocks = chunk .Blocks [:len (chunk .Blocks )- 1 ]
178+
179+ log .Info ("Chunk not compatible with compressed data, removing last block" , "start block number" , chunk .Blocks [0 ].Header .Number , "truncated block length" , len (chunk .Blocks ))
180+ }
181+
182+ if compatibilityBreachOccurred {
183+ p .compressedDataCompatibilityBreachTotal .Inc ()
184+
185+ // recalculate chunk metrics after truncation
186+ var calcErr error
187+ metrics , calcErr = utils .CalculateChunkMetrics (chunk , codecVersion )
188+ if calcErr != nil {
189+ return fmt .Errorf ("failed to calculate chunk metrics, start block number: %v, error: %w" , chunk .Blocks [0 ].Header .Number , calcErr )
190+ }
191+
192+ p .recordTimerChunkMetrics (metrics )
193+ p .recordAllChunkMetrics (metrics )
194+ }
195+
150196 p .chunkProposeBlockHeight .Set (float64 (chunk .Blocks [len (chunk .Blocks )- 1 ].Header .Number .Uint64 ()))
151197 p .chunkProposeThroughput .Add (float64 (chunk .TotalGasUsed ()))
152198
0 commit comments