Skip to content

Commit f4663fd

Browse files
colinlyguoThegaram0xmountaintopHAOYUatHZ
authored
feat(rollup-relayer): add number of blocks per chunk limit (scroll-tech#880)
Co-authored-by: colinlyguo <[email protected]> Co-authored-by: Péter Garamvölgyi <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]>
1 parent c71fa5a commit f4663fd

File tree

8 files changed

+44
-24
lines changed

8 files changed

+44
-24
lines changed

common/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.2.19"
8+
var tag = "v4.2.20"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

rollup/conf/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"gas_cost_increase_multiplier": 1.2
6666
},
6767
"chunk_proposer_config": {
68-
"max_tx_num_per_chunk": 1123,
68+
"max_block_num_per_chunk": 100,
69+
"max_tx_num_per_chunk": 100,
6970
"max_l1_commit_gas_per_chunk": 11234567,
7071
"max_l1_commit_calldata_size_per_chunk": 112345,
7172
"chunk_timeout_sec": 300,

rollup/internal/config/l2.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type L2Config struct {
2828

2929
// ChunkProposerConfig loads chunk_proposer configuration items.
3030
type ChunkProposerConfig struct {
31+
MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"`
3132
MaxTxNumPerChunk uint64 `json:"max_tx_num_per_chunk"`
3233
MaxL1CommitGasPerChunk uint64 `json:"max_l1_commit_gas_per_chunk"`
3334
MaxL1CommitCalldataSizePerChunk uint64 `json:"max_l1_commit_calldata_size_per_chunk"`

rollup/internal/controller/watcher/batch_proposer.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func (p *BatchProposer) proposeBatchChunks() ([]*orm.Chunk, *types.BatchMeta, er
154154
return nil, nil, err
155155
}
156156

157-
dbChunks, err := p.chunkOrm.GetChunksGEIndex(p.ctx, unbatchedChunkIndex, int(p.maxChunkNumPerBatch)+1)
157+
// select at most p.maxChunkNumPerBatch chunks
158+
dbChunks, err := p.chunkOrm.GetChunksGEIndex(p.ctx, unbatchedChunkIndex, int(p.maxChunkNumPerBatch))
158159
if err != nil {
159160
return nil, nil, err
160161
}
@@ -207,8 +208,7 @@ func (p *BatchProposer) proposeBatchChunks() ([]*orm.Chunk, *types.BatchMeta, er
207208
totalL1CommitGas += types.CalldataNonZeroByteGas * (32 * (totalL1MessagePopped + 255) / 256)
208209
totalL1CommitGas += types.GetKeccak256Gas(89 + 32*(totalL1MessagePopped+255)/256)
209210
totalOverEstimateL1CommitGas := uint64(p.gasCostIncreaseMultiplier * float64(totalL1CommitGas))
210-
if totalChunks > p.maxChunkNumPerBatch ||
211-
totalL1CommitCalldataSize > p.maxL1CommitCalldataSizePerBatch ||
211+
if totalL1CommitCalldataSize > p.maxL1CommitCalldataSizePerBatch ||
212212
totalOverEstimateL1CommitGas > p.maxL1CommitGasPerBatch {
213213
// Check if the first chunk breaks hard limits.
214214
// If so, it indicates there are bugs in chunk-proposer, manual fix is needed.
@@ -234,8 +234,6 @@ func (p *BatchProposer) proposeBatchChunks() ([]*orm.Chunk, *types.BatchMeta, er
234234
}
235235

236236
log.Debug("breaking limit condition in batching",
237-
"currentTotalChunks", totalChunks,
238-
"maxChunkNumPerBatch", p.maxChunkNumPerBatch,
239237
"currentL1CommitCalldataSize", totalL1CommitCalldataSize,
240238
"maxL1CommitCalldataSizePerBatch", p.maxL1CommitCalldataSizePerBatch,
241239
"currentOverEstimateL1CommitGas", totalOverEstimateL1CommitGas,
@@ -249,12 +247,20 @@ func (p *BatchProposer) proposeBatchChunks() ([]*orm.Chunk, *types.BatchMeta, er
249247
}
250248

251249
currentTimeSec := uint64(time.Now().Unix())
252-
if dbChunks[0].StartBlockTime+p.batchTimeoutSec < currentTimeSec {
253-
log.Warn("first block timeout",
254-
"start block number", dbChunks[0].StartBlockNumber,
255-
"first block timestamp", dbChunks[0].StartBlockTime,
256-
"chunk outdated time threshold", currentTimeSec,
257-
)
250+
if dbChunks[0].StartBlockTime+p.batchTimeoutSec < currentTimeSec ||
251+
totalChunks == p.maxChunkNumPerBatch {
252+
if dbChunks[0].StartBlockTime+p.batchTimeoutSec < currentTimeSec {
253+
log.Warn("first block timeout",
254+
"start block number", dbChunks[0].StartBlockNumber,
255+
"start block timestamp", dbChunks[0].StartBlockTime,
256+
"current time", currentTimeSec,
257+
)
258+
} else {
259+
log.Info("reached maximum number of chunks in batch",
260+
"chunk count", totalChunks,
261+
)
262+
}
263+
258264
batchMeta.TotalL1CommitGas = totalL1CommitGas
259265
batchMeta.TotalL1CommitCalldataSize = totalL1CommitCalldataSize
260266
p.batchFirstBlockTimeoutReached.Inc()

rollup/internal/controller/watcher/batch_proposer_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func testBatchProposer(t *testing.T) {
2323
assert.NoError(t, err)
2424

2525
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
26+
MaxBlockNumPerChunk: 100,
2627
MaxTxNumPerChunk: 10000,
2728
MaxL1CommitGasPerChunk: 50000000000,
2829
MaxL1CommitCalldataSizePerChunk: 1000000,

rollup/internal/controller/watcher/chunk_proposer.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import (
1818
"scroll-tech/rollup/internal/orm"
1919
)
2020

21-
// maxNumBlockPerChunk is the maximum number of blocks we allow per chunk.
22-
// Normally we will pack much fewer blocks because of other limits.
23-
const maxNumBlockPerChunk int = 100
24-
2521
// chunkRowConsumption is map(sub-circuit name => sub-circuit row count)
2622
type chunkRowConsumption map[string]uint64
2723

@@ -55,6 +51,7 @@ type ChunkProposer struct {
5551
chunkOrm *orm.Chunk
5652
l2BlockOrm *orm.L2Block
5753

54+
maxBlockNumPerChunk uint64
5855
maxTxNumPerChunk uint64
5956
maxL1CommitGasPerChunk uint64
6057
maxL1CommitCalldataSizePerChunk uint64
@@ -90,6 +87,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, db *
9087
db: db,
9188
chunkOrm: orm.NewChunk(db),
9289
l2BlockOrm: orm.NewL2Block(db),
90+
maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk,
9391
maxTxNumPerChunk: cfg.MaxTxNumPerChunk,
9492
maxL1CommitGasPerChunk: cfg.MaxL1CommitGasPerChunk,
9593
maxL1CommitCalldataSizePerChunk: cfg.MaxL1CommitCalldataSizePerChunk,
@@ -191,7 +189,8 @@ func (p *ChunkProposer) proposeChunk() (*types.Chunk, error) {
191189
return nil, err
192190
}
193191

194-
blocks, err := p.l2BlockOrm.GetL2WrappedBlocksGEHeight(p.ctx, unchunkedBlockHeight, maxNumBlockPerChunk)
192+
// select at most p.maxBlockNumPerChunk blocks
193+
blocks, err := p.l2BlockOrm.GetL2WrappedBlocksGEHeight(p.ctx, unchunkedBlockHeight, int(p.maxBlockNumPerChunk))
195194
if err != nil {
196195
return nil, err
197196
}
@@ -293,12 +292,21 @@ func (p *ChunkProposer) proposeChunk() (*types.Chunk, error) {
293292
}
294293

295294
currentTimeSec := uint64(time.Now().Unix())
296-
if blocks[0].Header.Time+p.chunkTimeoutSec < currentTimeSec {
297-
log.Warn("first block timeout",
298-
"block number", blocks[0].Header.Number,
299-
"block timestamp", blocks[0].Header.Time,
300-
"block outdated time threshold", currentTimeSec,
301-
)
295+
if chunk.Blocks[0].Header.Time+p.chunkTimeoutSec < currentTimeSec ||
296+
uint64(len(chunk.Blocks)) == p.maxBlockNumPerChunk {
297+
if chunk.Blocks[0].Header.Time+p.chunkTimeoutSec < currentTimeSec {
298+
log.Warn("first block timeout",
299+
"block number", chunk.Blocks[0].Header.Number,
300+
"block timestamp", chunk.Blocks[0].Header.Time,
301+
"current time", currentTimeSec,
302+
)
303+
} else {
304+
log.Info("reached maximum number of blocks in chunk",
305+
"start block number", chunk.Blocks[0].Header.Number,
306+
"block count", len(chunk.Blocks),
307+
)
308+
}
309+
302310
p.chunkFirstBlockTimeoutReached.Inc()
303311
p.chunkTxNum.Set(float64(totalTxNum))
304312
p.chunkEstimateL1CommitGas.Set(float64(totalL1CommitGas))

rollup/internal/controller/watcher/chunk_proposer_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func testChunkProposer(t *testing.T) {
2323
assert.NoError(t, err)
2424

2525
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
26+
MaxBlockNumPerChunk: 100,
2627
MaxTxNumPerChunk: 10000,
2728
MaxL1CommitGasPerChunk: 50000000000,
2829
MaxL1CommitCalldataSizePerChunk: 1000000,
@@ -53,6 +54,7 @@ func testChunkProposerRowConsumption(t *testing.T) {
5354
assert.NoError(t, err)
5455

5556
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
57+
MaxBlockNumPerChunk: 100,
5658
MaxTxNumPerChunk: 10000,
5759
MaxL1CommitGasPerChunk: 50000000000,
5860
MaxL1CommitCalldataSizePerChunk: 1000000,

rollup/tests/rollup_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func testCommitBatchAndFinalizeBatch(t *testing.T) {
5757
assert.NoError(t, err)
5858

5959
cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
60+
MaxBlockNumPerChunk: 100,
6061
MaxTxNumPerChunk: 10000,
6162
MaxL1CommitGasPerChunk: 50000000000,
6263
MaxL1CommitCalldataSizePerChunk: 1000000,

0 commit comments

Comments
 (0)