Skip to content

Commit de7f6e5

Browse files
authored
refactor(rollup relayer): remove max_block_num_per_chunk configuration parameter (#1729)
Co-authored-by: jonastheis <jonastheis@users.noreply.github.com>
1 parent 3b32319 commit de7f6e5

File tree

11 files changed

+23
-84
lines changed

11 files changed

+23
-84
lines changed

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.5.45"
8+
var tag = "v4.5.46"
99

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

permissionless-batches/conf/relayer/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
},
1616
"chunk_proposer_config": {
1717
"propose_interval_milliseconds": 100,
18-
"max_block_num_per_chunk": 100,
1918
"max_l2_gas_per_chunk": 20000000,
2019
"chunk_timeout_sec": 300,
2120
"max_uncompressed_batch_bytes_size": 4194304

rollup/conf/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
},
9393
"chunk_proposer_config": {
9494
"propose_interval_milliseconds": 100,
95-
"max_block_num_per_chunk": 100,
9695
"max_l2_gas_per_chunk": 20000000,
9796
"chunk_timeout_sec": 300,
9897
"max_uncompressed_batch_bytes_size": 4194304

rollup/internal/config/l2.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type L2Config struct {
3131
// ChunkProposerConfig loads chunk_proposer configuration items.
3232
type ChunkProposerConfig struct {
3333
ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"`
34-
MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"`
3534
MaxL2GasPerChunk uint64 `json:"max_l2_gas_per_chunk"`
3635
ChunkTimeoutSec uint64 `json:"chunk_timeout_sec"`
3736
MaxUncompressedBatchBytesSize uint64 `json:"max_uncompressed_batch_bytes_size"`

rollup/internal/controller/watcher/batch_proposer_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func testBatchProposerLimitsCodecV7(t *testing.T) {
3636
name: "Timeout",
3737
batchTimeoutSec: 0,
3838
expectedBatchesLen: 1,
39-
expectedChunksInFirstBatch: 2,
39+
expectedChunksInFirstBatch: 1,
4040
},
4141
}
4242

@@ -72,8 +72,7 @@ func testBatchProposerLimitsCodecV7(t *testing.T) {
7272
assert.NoError(t, err)
7373

7474
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
75-
MaxBlockNumPerChunk: 1,
76-
MaxL2GasPerChunk: 20000000,
75+
MaxL2GasPerChunk: math.MaxUint64,
7776
ChunkTimeoutSec: 300,
7877
MaxUncompressedBatchBytesSize: math.MaxUint64,
7978
}, encoding.CodecV7, &params.ChainConfig{
@@ -154,7 +153,6 @@ func testBatchProposerBlobSizeLimitCodecV7(t *testing.T) {
154153
chainConfig := &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}
155154

156155
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
157-
MaxBlockNumPerChunk: math.MaxUint64,
158156
MaxL2GasPerChunk: math.MaxUint64,
159157
ChunkTimeoutSec: 0,
160158
MaxUncompressedBatchBytesSize: math.MaxUint64,
@@ -227,7 +225,6 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV7(t *testing.T) {
227225
chainConfig := &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}
228226

229227
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
230-
MaxBlockNumPerChunk: math.MaxUint64,
231228
MaxL2GasPerChunk: math.MaxUint64,
232229
ChunkTimeoutSec: 0,
233230
MaxUncompressedBatchBytesSize: math.MaxUint64,
@@ -309,15 +306,14 @@ func testBatchProposerUncompressedBatchBytesLimitCodecV8(t *testing.T) {
309306

310307
// Create chunk proposer with no uncompressed batch bytes limit for chunks
311308
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
312-
MaxBlockNumPerChunk: 1, // One block per chunk
313-
MaxL2GasPerChunk: math.MaxUint64,
309+
MaxL2GasPerChunk: 1200000, // One block per chunk via gas limit
314310
ChunkTimeoutSec: math.MaxUint32,
315311
MaxUncompressedBatchBytesSize: math.MaxUint64,
316312
}, encoding.CodecV8, chainConfig, db, nil)
317313

318314
// Insert 2 blocks with large calldata and create 2 chunks
319315
l2BlockOrm := orm.NewL2Block(db)
320-
for i := uint64(1); i <= 2; i++ {
316+
for i := uint64(1); i <= 3; i++ {
321317
blockCopy := *block
322318
blockCopy.Header = &gethTypes.Header{}
323319
*blockCopy.Header = *block.Header
@@ -326,7 +322,9 @@ func testBatchProposerUncompressedBatchBytesLimitCodecV8(t *testing.T) {
326322
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{&blockCopy})
327323
assert.NoError(t, err)
328324

329-
cp.TryProposeChunk() // Each call creates one chunk with one block
325+
cp.TryProposeChunk() // Each chunk will contain 1 block (~3KiB)
326+
// We create 2 chunks here, as we have 3 blocks and reach the gas limit for the 1st chunk with the 2nd block
327+
// and the 2nd chunk with the 3rd block.
330328
}
331329

332330
// Create batch proposer with 4KiB uncompressed batch bytes limit

rollup/internal/controller/watcher/bundle_proposer_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,19 @@ func testBundleProposerLimitsCodecV7(t *testing.T) {
8686
_, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{})
8787
assert.NoError(t, err)
8888

89+
block3 := *block1
90+
block3.Header = &gethTypes.Header{}
91+
*block3.Header = *block1.Header
92+
block3.Header.Number = new(big.Int).SetUint64(block2.Header.Number.Uint64() + 1)
93+
8994
l2BlockOrm := orm.NewL2Block(db)
90-
err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2})
95+
err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2, &block3})
9196
assert.NoError(t, err)
9297

9398
chainConfig := &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}
9499

95100
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
96-
MaxBlockNumPerChunk: 1,
97-
MaxL2GasPerChunk: math.MaxUint64,
101+
MaxL2GasPerChunk: 1152994, // One block per chunk via gas limit
98102
ChunkTimeoutSec: math.MaxUint32,
99103
MaxUncompressedBatchBytesSize: math.MaxUint64,
100104
}, encoding.CodecV7, chainConfig, db, nil)

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type ChunkProposer struct {
5454
// NewChunkProposer creates a new ChunkProposer instance.
5555
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
5656
log.Info("new chunk proposer",
57-
"maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk,
5857
"maxL2GasPerChunk", cfg.MaxL2GasPerChunk,
5958
"chunkTimeoutSec", cfg.ChunkTimeoutSec,
6059
"maxBlobSize", maxBlobSize)
@@ -232,10 +231,9 @@ func (p *ChunkProposer) ProposeChunk() error {
232231
return err
233232
}
234233

235-
maxBlocksThisChunk := p.cfg.MaxBlockNumPerChunk
236-
237-
// select at most maxBlocksThisChunk blocks
238-
blocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, unchunkedBlockHeight, int(maxBlocksThisChunk))
234+
// select blocks without a hard limit on count in practice (use a large value)
235+
// The actual limits will be enforced by gas, timeout, and blob size constraints
236+
blocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, unchunkedBlockHeight, 1000)
239237
if err != nil {
240238
return err
241239
}
@@ -251,7 +249,7 @@ func (p *ChunkProposer) ProposeChunk() error {
251249
currentHardfork := encoding.GetHardforkName(p.chainCfg, blocks[i].Header.Number.Uint64(), blocks[i].Header.Time)
252250
if currentHardfork != hardforkName {
253251
blocks = blocks[:i]
254-
maxBlocksThisChunk = uint64(i) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
252+
// Truncate blocks at hardfork boundary
255253
break
256254
}
257255
}
@@ -324,8 +322,8 @@ func (p *ChunkProposer) ProposeChunk() error {
324322
}
325323

326324
currentTimeSec := uint64(time.Now().Unix())
327-
if metrics.FirstBlockTimestamp+p.cfg.ChunkTimeoutSec < currentTimeSec || metrics.NumBlocks == maxBlocksThisChunk {
328-
log.Info("reached maximum number of blocks in chunk or first block timeout",
325+
if metrics.FirstBlockTimestamp+p.cfg.ChunkTimeoutSec < currentTimeSec {
326+
log.Info("first block timeout reached",
329327
"block count", len(chunk.Blocks),
330328
"start block number", chunk.Blocks[0].Header.Number,
331329
"start block timestamp", metrics.FirstBlockTimestamp,

rollup/internal/controller/watcher/chunk_proposer_test.go

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,33 @@ import (
2222
func testChunkProposerLimitsCodecV7(t *testing.T) {
2323
tests := []struct {
2424
name string
25-
maxBlockNum uint64
2625
maxL2Gas uint64
2726
chunkTimeoutSec uint64
2827
expectedChunksLen int
2928
expectedBlocksInFirstChunk int // only be checked when expectedChunksLen > 0
3029
}{
3130
{
3231
name: "NoLimitReached",
33-
maxBlockNum: 100,
3432
maxL2Gas: 20_000_000,
3533
chunkTimeoutSec: 1000000000000,
3634
expectedChunksLen: 0,
3735
},
3836
{
3937
name: "Timeout",
40-
maxBlockNum: 100,
4138
maxL2Gas: 20_000_000,
4239
chunkTimeoutSec: 0,
4340
expectedChunksLen: 1,
4441
expectedBlocksInFirstChunk: 2,
4542
},
4643
{
4744
name: "MaxL2GasPerChunkIs0",
48-
maxBlockNum: 10,
4945
maxL2Gas: 0,
5046
chunkTimeoutSec: 1000000000000,
5147
expectedChunksLen: 0,
5248
},
5349
{
54-
name: "MaxBlockNumPerChunkIs1",
55-
maxBlockNum: 1,
56-
maxL2Gas: 20_000_000,
50+
name: "SingleBlockByGasLimit",
51+
maxL2Gas: 1_100_000,
5752
chunkTimeoutSec: 1000000000000,
5853
expectedChunksLen: 1,
5954
expectedBlocksInFirstChunk: 1,
@@ -62,7 +57,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) {
6257
// In this test the second block is not included in the chunk because together
6358
// with the first block it exceeds the maxL2GasPerChunk limit.
6459
name: "MaxL2GasPerChunkIsSecondBlock",
65-
maxBlockNum: 10,
6660
maxL2Gas: 1_153_000,
6761
chunkTimeoutSec: 1000000000000,
6862
expectedChunksLen: 1,
@@ -85,7 +79,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) {
8579
assert.NoError(t, err)
8680

8781
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
88-
MaxBlockNumPerChunk: tt.maxBlockNum,
8982
MaxL2GasPerChunk: tt.maxL2Gas,
9083
ChunkTimeoutSec: tt.chunkTimeoutSec,
9184
MaxUncompressedBatchBytesSize: math.MaxUint64,
@@ -110,53 +103,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) {
110103
}
111104
}
112105

113-
func testChunkProposerBlobSizeLimitCodecV7(t *testing.T) {
114-
db := setupDB(t)
115-
defer database.CloseDB(db)
116-
block := readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
117-
for i := uint64(0); i < 510; i++ {
118-
l2BlockOrm := orm.NewL2Block(db)
119-
block.Header.Number = new(big.Int).SetUint64(i + 1)
120-
block.Header.Time = i + 1
121-
err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block})
122-
assert.NoError(t, err)
123-
}
124-
125-
// Add genesis chunk.
126-
chunkOrm := orm.NewChunk(db)
127-
_, err := chunkOrm.InsertChunk(context.Background(), &encoding.Chunk{Blocks: []*encoding.Block{{Header: &gethTypes.Header{Number: big.NewInt(0)}}}}, encoding.CodecV0, utils.ChunkMetrics{})
128-
assert.NoError(t, err)
129-
130-
chainConfig := &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}
131-
132-
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
133-
MaxBlockNumPerChunk: 255,
134-
MaxL2GasPerChunk: math.MaxUint64,
135-
ChunkTimeoutSec: math.MaxUint32,
136-
MaxUncompressedBatchBytesSize: math.MaxUint64,
137-
}, encoding.CodecV7, chainConfig, db, nil)
138-
139-
for i := 0; i < 2; i++ {
140-
cp.TryProposeChunk()
141-
}
142-
143-
chunkOrm = orm.NewChunk(db)
144-
chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 1, 0)
145-
assert.NoError(t, err)
146-
147-
var expectedNumChunks int = 2
148-
var numBlocksMultiplier uint64 = 255
149-
assert.Len(t, chunks, expectedNumChunks)
150-
151-
for i, chunk := range chunks {
152-
expected := numBlocksMultiplier * (uint64(i) + 1)
153-
if expected > 2000 {
154-
expected = 2000
155-
}
156-
assert.Equal(t, expected, chunk.EndBlockNumber)
157-
}
158-
}
159-
160106
func testChunkProposerUncompressedBatchBytesLimitCodecV8(t *testing.T) {
161107
db := setupDB(t)
162108
defer database.CloseDB(db)
@@ -204,7 +150,6 @@ func testChunkProposerUncompressedBatchBytesLimitCodecV8(t *testing.T) {
204150
// Set max_uncompressed_batch_bytes_size to 4KiB (4 * 1024)
205151
// One block (~3KiB) should fit, but two blocks (~6KiB) should exceed the limit
206152
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
207-
MaxBlockNumPerChunk: math.MaxUint64, // No block number limit
208153
MaxL2GasPerChunk: math.MaxUint64, // No gas limit
209154
ChunkTimeoutSec: math.MaxUint32, // No timeout limit
210155
MaxUncompressedBatchBytesSize: 4 * 1024, // 4KiB limit

rollup/internal/controller/watcher/watcher_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func TestFunction(t *testing.T) {
102102

103103
// Run chunk proposer test cases.
104104
t.Run("TestChunkProposerLimitsCodecV7", testChunkProposerLimitsCodecV7)
105-
t.Run("TestChunkProposerBlobSizeLimitCodecV7", testChunkProposerBlobSizeLimitCodecV7)
106105
t.Run("TestChunkProposerUncompressedBatchBytesLimitCodecV8", testChunkProposerUncompressedBatchBytesLimitCodecV8)
107106

108107
// Run batch proposer test cases.

rollup/proposer-tool-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"l2_config": {
33
"endpoint": "https://rpc.scroll.io",
44
"chunk_proposer_config": {
5-
"max_block_num_per_chunk": 100,
65
"max_l2_gas_per_chunk": 20000000,
76
"chunk_timeout_sec": 72000000000,
87
"max_uncompressed_batch_bytes_size": 4194304

0 commit comments

Comments
 (0)