Skip to content

Commit 676f41f

Browse files
author
colinlyguo
committed
feat(bundle-proposer): static batch per bundle
1 parent 54d8236 commit 676f41f

File tree

5 files changed

+31
-48
lines changed

5 files changed

+31
-48
lines changed

rollup/conf/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@
103103
"max_uncompressed_batch_bytes_size": 634880
104104
},
105105
"bundle_proposer_config": {
106-
"max_batch_num_per_bundle": 20,
107-
"bundle_timeout_sec": 36000
106+
"batch_num_per_bundle": 20
108107
}
109108
},
110109
"db_config": {

rollup/internal/config/l2.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ type BatchProposerConfig struct {
5151

5252
// BundleProposerConfig loads bundle_proposer configuration items.
5353
type BundleProposerConfig struct {
54-
MaxBatchNumPerBundle uint64 `json:"max_batch_num_per_bundle"`
55-
BundleTimeoutSec uint64 `json:"bundle_timeout_sec"`
54+
BatchNumPerBundle uint64 `json:"batch_num_per_bundle"`
5655
}

rollup/internal/controller/watcher/bundle_proposer.go

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package watcher
33
import (
44
"context"
55
"errors"
6-
"time"
76

87
"github.com/prometheus/client_golang/prometheus"
98
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -25,8 +24,7 @@ type BundleProposer struct {
2524
batchOrm *orm.Batch
2625
bundleOrm *orm.Bundle
2726

28-
maxBatchNumPerBundle uint64
29-
bundleTimeoutSec uint64
27+
batchNumPerBundle uint64
3028

3129
chainCfg *params.ChainConfig
3230

@@ -41,17 +39,16 @@ type BundleProposer struct {
4139

4240
// NewBundleProposer creates a new BundleProposer instance.
4341
func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BundleProposer {
44-
log.Info("new bundle proposer", "bundleBatchesNum", cfg.MaxBatchNumPerBundle, "bundleTimeoutSec", cfg.BundleTimeoutSec)
42+
log.Info("new bundle proposer", "bundleBatchesNum", cfg.BatchNumPerBundle)
4543

4644
p := &BundleProposer{
47-
ctx: ctx,
48-
db: db,
49-
chunkOrm: orm.NewChunk(db),
50-
batchOrm: orm.NewBatch(db),
51-
bundleOrm: orm.NewBundle(db),
52-
maxBatchNumPerBundle: cfg.MaxBatchNumPerBundle,
53-
bundleTimeoutSec: cfg.BundleTimeoutSec,
54-
chainCfg: chainCfg,
45+
ctx: ctx,
46+
db: db,
47+
chunkOrm: orm.NewChunk(db),
48+
batchOrm: orm.NewBatch(db),
49+
bundleOrm: orm.NewBundle(db),
50+
batchNumPerBundle: cfg.BatchNumPerBundle,
51+
chainCfg: chainCfg,
5552

5653
bundleProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
5754
Name: "rollup_propose_bundle_circle_total",
@@ -129,8 +126,8 @@ func (p *BundleProposer) proposeBundle() error {
129126
}
130127

131128
// select at most maxBlocksThisChunk blocks
132-
maxBatchesThisBundle := p.maxBatchNumPerBundle
133-
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV3, int(maxBatchesThisBundle))
129+
batchesThisBundle := p.batchNumPerBundle
130+
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV3, int(batchesThisBundle))
134131
if err != nil {
135132
return err
136133
}
@@ -161,21 +158,13 @@ func (p *BundleProposer) proposeBundle() error {
161158
currentHardfork := encoding.GetHardforkName(p.chainCfg, chunk.StartBlockNumber, chunk.StartBlockTime)
162159
if currentHardfork != hardforkName {
163160
batches = batches[:i]
164-
maxBatchesThisBundle = uint64(i) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
161+
batchesThisBundle = uint64(i) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
165162
break
166163
}
167164
}
168165

169-
if uint64(len(batches)) == maxBatchesThisBundle {
170-
log.Info("reached maximum number of batches per bundle", "batch count", len(batches), "start batch index", batches[0].Index, "end batch index", batches[len(batches)-1].Index)
171-
p.bundleFirstBlockTimeoutReached.Inc()
172-
p.bundleBatchesNum.Set(float64(len(batches)))
173-
return p.updateDBBundleInfo(batches, codecVersion)
174-
}
175-
176-
currentTimeSec := uint64(time.Now().Unix())
177-
if firstChunk.StartBlockTime+p.bundleTimeoutSec < currentTimeSec {
178-
log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "current time", currentTimeSec)
166+
if uint64(len(batches)) == batchesThisBundle {
167+
log.Info("reached number of batches per bundle", "batch count", len(batches), "start batch index", batches[0].Index, "end batch index", batches[len(batches)-1].Index)
179168
p.bundleFirstBlockTimeoutReached.Inc()
180169
p.bundleBatchesNum.Set(float64(len(batches)))
181170
return p.updateDBBundleInfo(batches, codecVersion)

rollup/internal/controller/watcher/bundle_proposer_test.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@ import (
2323
func testBundleProposerLimits(t *testing.T) {
2424
tests := []struct {
2525
name string
26-
maxBatchNumPerBundle uint64
26+
batchNumPerBundle uint64
2727
bundleTimeoutSec uint64
2828
expectedBundlesLen int
2929
expectedBatchesInFirstBundle uint64 // only be checked when expectedBundlesLen > 0
3030
}{
3131
{
32-
name: "NoLimitReached",
33-
maxBatchNumPerBundle: math.MaxUint64,
34-
bundleTimeoutSec: math.MaxUint32,
35-
expectedBundlesLen: 0,
32+
name: "NoLimitReached",
33+
batchNumPerBundle: math.MaxUint64,
34+
bundleTimeoutSec: math.MaxUint32,
35+
expectedBundlesLen: 0,
3636
},
3737
{
3838
name: "Timeout",
39-
maxBatchNumPerBundle: math.MaxUint64,
39+
batchNumPerBundle: math.MaxUint64,
4040
bundleTimeoutSec: 0,
4141
expectedBundlesLen: 1,
4242
expectedBatchesInFirstBundle: 2,
4343
},
4444
{
45-
name: "maxBatchNumPerBundleIs0",
46-
maxBatchNumPerBundle: 0,
47-
bundleTimeoutSec: math.MaxUint32,
48-
expectedBundlesLen: 0,
45+
name: "maxBatchNumPerBundleIs0",
46+
batchNumPerBundle: 0,
47+
bundleTimeoutSec: math.MaxUint32,
48+
expectedBundlesLen: 0,
4949
},
5050
{
5151
name: "maxBatchNumPerBundleIs1",
52-
maxBatchNumPerBundle: 1,
52+
batchNumPerBundle: 1,
5353
bundleTimeoutSec: math.MaxUint32,
5454
expectedBundlesLen: 1,
5555
expectedBatchesInFirstBundle: 1,
@@ -115,8 +115,7 @@ func testBundleProposerLimits(t *testing.T) {
115115
bap.TryProposeBatch() // batch2 contains chunk2
116116

117117
bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{
118-
MaxBatchNumPerBundle: tt.maxBatchNumPerBundle,
119-
BundleTimeoutSec: tt.bundleTimeoutSec,
118+
BatchNumPerBundle: tt.batchNumPerBundle,
120119
}, chainConfig, db, nil)
121120

122121
bup.TryProposeBundle()
@@ -205,8 +204,7 @@ func testBundleProposerRespectHardforks(t *testing.T) {
205204
}
206205

207206
bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{
208-
MaxBatchNumPerBundle: math.MaxUint64,
209-
BundleTimeoutSec: 0,
207+
BatchNumPerBundle: math.MaxUint64,
210208
}, chainConfig, db, nil)
211209

212210
for i := 0; i < 5; i++ {

rollup/tests/rollup_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ func testCommitBatchAndFinalizeBatchOrBundleWithAllCodecVersions(t *testing.T) {
113113
}, chainConfig, db, nil)
114114

115115
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
116-
MaxBatchNumPerBundle: 1000000,
117-
BundleTimeoutSec: 300,
116+
BatchNumPerBundle: 1000000,
118117
}, chainConfig, db, nil)
119118

120119
l2BlockOrm := orm.NewL2Block(db)
@@ -280,8 +279,7 @@ func testCommitBatchAndFinalizeBatchOrBundleCrossingAllTransitions(t *testing.T)
280279
}, chainConfig, db, nil)
281280

282281
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
283-
MaxBatchNumPerBundle: 1000000,
284-
BundleTimeoutSec: 300,
282+
BatchNumPerBundle: 1000000,
285283
}, chainConfig, db, nil)
286284

287285
cp.TryProposeChunk()

0 commit comments

Comments
 (0)