Skip to content

Commit 6a8ef2c

Browse files
author
colinlyguo
committed
add back chunk compatibility check
1 parent 1ca2997 commit 6a8ef2c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

rollup/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/holiman/uint256 v1.3.2
1212
github.com/mitchellh/mapstructure v1.5.0
1313
github.com/prometheus/client_golang v1.16.0
14-
github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82
14+
github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd
1515
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601
1616
github.com/smartystreets/goconvey v1.8.0
1717
github.com/spf13/viper v1.19.0

rollup/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
249249
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
250250
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
251251
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
252-
github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82 h1:8mqkSusH9qz7Hzz7MtQ9uMXX0ej2c1NyeG14W1LTCQk=
253-
github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
252+
github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd h1:WWpmrmvj6gizg4PJf1AMvMxfKMRiFh5PlLfqUgDJKr8=
253+
github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
254254
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8=
255255
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ=
256256
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)