Skip to content

Commit 818add4

Browse files
author
colinlyguo
committed
address comments
1 parent be3f189 commit 818add4

File tree

8 files changed

+44
-26
lines changed

8 files changed

+44
-26
lines changed

rollup/cmd/proposer_tool/app/app.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ func action(ctx *cli.Context) error {
169169
}
170170

171171
minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name))
172-
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry)
173-
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry)
172+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, registry)
173+
chunkProposer.SetReplayDB(dbForReplay)
174+
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, registry)
175+
batchProposer.SetReplayDB(dbForReplay)
174176
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
175177

176178
go utils.Loop(subCtx, 100*time.Millisecond, chunkProposer.TryProposeChunk)

rollup/cmd/rollup_relayer/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func action(ctx *cli.Context) error {
102102
}
103103

104104
minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name))
105-
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, db, registry)
106-
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, db, registry)
105+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, registry)
106+
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, registry)
107107
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
108108

109109
l2watcher := watcher.NewL2WatcherClient(subCtx, l2client, cfg.L2Config.Confirmations, cfg.L2Config.L2MessageQueueAddress, cfg.L2Config.WithdrawTrieRootSlot, genesis.Config, db, registry)

rollup/internal/controller/watcher/batch_proposer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type BatchProposer struct {
6262
}
6363

6464
// NewBatchProposer creates a new BatchProposer instance.
65-
func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, l2BlockDB, db *gorm.DB, reg prometheus.Registerer) *BatchProposer {
65+
func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer {
6666
log.Info("new batch proposer",
6767
"maxL1CommitGasPerBatch", cfg.MaxL1CommitGasPerBatch,
6868
"maxL1CommitCalldataSizePerBatch", cfg.MaxL1CommitCalldataSizePerBatch,
@@ -76,14 +76,14 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minC
7676
db: db,
7777
batchOrm: orm.NewBatch(db),
7878
chunkOrm: orm.NewChunk(db),
79-
l2BlockOrm: orm.NewL2Block(l2BlockDB),
79+
l2BlockOrm: orm.NewL2Block(db),
8080
maxL1CommitGasPerBatch: cfg.MaxL1CommitGasPerBatch,
8181
maxL1CommitCalldataSizePerBatch: cfg.MaxL1CommitCalldataSizePerBatch,
8282
batchTimeoutSec: cfg.BatchTimeoutSec,
8383
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
8484
maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize,
8585
maxChunksPerBatch: cfg.MaxChunksPerBatch,
86-
replayMode: db != l2BlockDB,
86+
replayMode: false,
8787
minCodecVersion: minCodecVersion,
8888
chainCfg: chainCfg,
8989

@@ -156,6 +156,14 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minC
156156
return p
157157
}
158158

159+
// SetReplayDB sets the replay database for the BatchProposer.
160+
// This is used for the proposer tool only, to change the l2_block data source.
161+
// This function is not thread-safe and should be called after initializing the BatchProposer and before starting to propose chunks.
162+
func (p *BatchProposer) SetReplayDB(replayDB *gorm.DB) {
163+
p.l2BlockOrm = orm.NewL2Block(replayDB)
164+
p.replayMode = true
165+
}
166+
159167
// TryProposeBatch tries to propose a new batches.
160168
func (p *BatchProposer) TryProposeBatch() {
161169
p.batchProposerCircleTotal.Inc()

rollup/internal/controller/watcher/batch_proposer_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func testBatchProposerLimitsCodecV4(t *testing.T) {
124124
CurieBlock: big.NewInt(0),
125125
DarwinTime: new(uint64),
126126
DarwinV2Time: new(uint64),
127-
}, db, db, nil)
127+
}, db, nil)
128128
cp.TryProposeChunk() // chunk1 contains block1
129129
cp.TryProposeChunk() // chunk2 contains block2
130130

@@ -148,7 +148,7 @@ func testBatchProposerLimitsCodecV4(t *testing.T) {
148148
CurieBlock: big.NewInt(0),
149149
DarwinTime: new(uint64),
150150
DarwinV2Time: new(uint64),
151-
}, db, db, nil)
151+
}, db, nil)
152152
bp.TryProposeBatch()
153153

154154
batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0)
@@ -214,7 +214,7 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) {
214214
ChunkTimeoutSec: 300,
215215
GasCostIncreaseMultiplier: 1.2,
216216
MaxUncompressedBatchBytesSize: math.MaxUint64,
217-
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, db, nil)
217+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
218218
cp.TryProposeChunk() // chunk1 contains block1
219219
cp.TryProposeChunk() // chunk2 contains block2
220220

@@ -232,7 +232,7 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) {
232232
GasCostIncreaseMultiplier: 1.2,
233233
MaxUncompressedBatchBytesSize: math.MaxUint64,
234234
MaxChunksPerBatch: math.MaxInt32,
235-
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, db, nil)
235+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
236236
bp.TryProposeBatch()
237237

238238
batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0)
@@ -301,7 +301,7 @@ func testBatchProposerBlobSizeLimitCodecV4(t *testing.T) {
301301
ChunkTimeoutSec: 0,
302302
GasCostIncreaseMultiplier: 1,
303303
MaxUncompressedBatchBytesSize: math.MaxUint64,
304-
}, encoding.CodecV4, chainConfig, db, db, nil)
304+
}, encoding.CodecV4, chainConfig, db, nil)
305305

306306
blockHeight := int64(0)
307307
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
@@ -323,7 +323,7 @@ func testBatchProposerBlobSizeLimitCodecV4(t *testing.T) {
323323
GasCostIncreaseMultiplier: 1,
324324
MaxUncompressedBatchBytesSize: math.MaxUint64,
325325
MaxChunksPerBatch: math.MaxInt32,
326-
}, encoding.CodecV4, chainConfig, db, db, nil)
326+
}, encoding.CodecV4, chainConfig, db, nil)
327327

328328
for i := 0; i < 2; i++ {
329329
bp.TryProposeBatch()
@@ -397,7 +397,7 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV4(t *testing.T) {
397397
ChunkTimeoutSec: 0,
398398
GasCostIncreaseMultiplier: 1,
399399
MaxUncompressedBatchBytesSize: math.MaxUint64,
400-
}, encoding.CodecV4, chainConfig, db, db, nil)
400+
}, encoding.CodecV4, chainConfig, db, nil)
401401

402402
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
403403
for blockHeight := int64(1); blockHeight <= 60; blockHeight++ {
@@ -414,7 +414,7 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV4(t *testing.T) {
414414
GasCostIncreaseMultiplier: 1,
415415
MaxUncompressedBatchBytesSize: math.MaxUint64,
416416
MaxChunksPerBatch: math.MaxInt32,
417-
}, encoding.CodecV4, chainConfig, db, db, nil)
417+
}, encoding.CodecV4, chainConfig, db, nil)
418418
bp.TryProposeBatch()
419419

420420
batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0)

rollup/internal/controller/watcher/bundle_proposer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ func testBundleProposerLimitsCodecV4(t *testing.T) {
103103
ChunkTimeoutSec: math.MaxUint32,
104104
GasCostIncreaseMultiplier: 1,
105105
MaxUncompressedBatchBytesSize: math.MaxUint64,
106-
}, encoding.CodecV4, chainConfig, db, db, nil)
106+
}, encoding.CodecV4, chainConfig, db, nil)
107107

108108
bap := NewBatchProposer(context.Background(), &config.BatchProposerConfig{
109109
MaxL1CommitGasPerBatch: math.MaxUint64,
110110
MaxL1CommitCalldataSizePerBatch: math.MaxUint64,
111111
BatchTimeoutSec: 0,
112112
GasCostIncreaseMultiplier: 1,
113113
MaxUncompressedBatchBytesSize: math.MaxUint64,
114-
}, encoding.CodecV4, chainConfig, db, db, nil)
114+
}, encoding.CodecV4, chainConfig, db, nil)
115115

116116
cp.TryProposeChunk() // chunk1 contains block1
117117
bap.TryProposeBatch() // batch1 contains chunk1

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type ChunkProposer struct {
6565
}
6666

6767
// NewChunkProposer creates a new ChunkProposer instance.
68-
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, l2BlockDB, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
68+
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
6969
log.Info("new chunk proposer",
7070
"maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk,
7171
"maxTxNumPerChunk", cfg.MaxTxNumPerChunk,
@@ -82,7 +82,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC
8282
ctx: ctx,
8383
db: db,
8484
chunkOrm: orm.NewChunk(db),
85-
l2BlockOrm: orm.NewL2Block(l2BlockDB),
85+
l2BlockOrm: orm.NewL2Block(db),
8686
maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk,
8787
maxTxNumPerChunk: cfg.MaxTxNumPerChunk,
8888
maxL2GasPerChunk: cfg.MaxL2GasPerChunk,
@@ -92,7 +92,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC
9292
chunkTimeoutSec: cfg.ChunkTimeoutSec,
9393
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
9494
maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize,
95-
replayMode: l2BlockDB != db,
95+
replayMode: false,
9696
minCodecVersion: minCodecVersion,
9797
chainCfg: chainCfg,
9898

@@ -177,6 +177,14 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC
177177
return p
178178
}
179179

180+
// SetReplayDB sets the replay database for the ChunkProposer.
181+
// This is used for the proposer tool only, to change the l2_block data source.
182+
// This function is not thread-safe and should be called after initializing the ChunkProposer and before starting to propose chunks.
183+
func (p *ChunkProposer) SetReplayDB(replayDB *gorm.DB) {
184+
p.l2BlockOrm = orm.NewL2Block(replayDB)
185+
p.replayMode = true
186+
}
187+
180188
// TryProposeChunk tries to propose a new chunk.
181189
func (p *ChunkProposer) TryProposeChunk() {
182190
p.chunkProposerCircleTotal.Inc()

rollup/internal/controller/watcher/chunk_proposer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func testChunkProposerLimitsCodecV4(t *testing.T) {
202202
ChunkTimeoutSec: tt.chunkTimeoutSec,
203203
GasCostIncreaseMultiplier: 1.2,
204204
MaxUncompressedBatchBytesSize: math.MaxUint64,
205-
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, db, nil)
205+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
206206
cp.TryProposeChunk()
207207

208208
chunkOrm := orm.NewChunk(db)
@@ -253,7 +253,7 @@ func testChunkProposerBlobSizeLimitCodecV4(t *testing.T) {
253253
ChunkTimeoutSec: math.MaxUint32,
254254
GasCostIncreaseMultiplier: 1,
255255
MaxUncompressedBatchBytesSize: math.MaxUint64,
256-
}, encoding.CodecV4, chainConfig, db, db, nil)
256+
}, encoding.CodecV4, chainConfig, db, nil)
257257

258258
for i := 0; i < 2; i++ {
259259
cp.TryProposeChunk()

rollup/tests/rollup_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ func testCommitBatchAndFinalizeBundleCodecV4V5V6(t *testing.T) {
9595
MaxRowConsumptionPerChunk: 1048319,
9696
ChunkTimeoutSec: 300,
9797
MaxUncompressedBatchBytesSize: math.MaxUint64,
98-
}, encoding.CodecV4, chainConfig, db, db, nil)
98+
}, encoding.CodecV4, chainConfig, db, nil)
9999

100100
bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{
101101
MaxL1CommitGasPerBatch: 50000000000,
102102
MaxL1CommitCalldataSizePerBatch: 1000000,
103103
BatchTimeoutSec: 300,
104104
MaxUncompressedBatchBytesSize: math.MaxUint64,
105105
MaxChunksPerBatch: math.MaxInt32,
106-
}, encoding.CodecV4, chainConfig, db, db, nil)
106+
}, encoding.CodecV4, chainConfig, db, nil)
107107

108108
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
109109
MaxBatchNumPerBundle: 1000000,
@@ -291,14 +291,14 @@ func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) {
291291
MaxRowConsumptionPerChunk: 1048319,
292292
ChunkTimeoutSec: 300,
293293
MaxUncompressedBatchBytesSize: math.MaxUint64,
294-
}, encoding.CodecV7, chainConfig, db, db, nil)
294+
}, encoding.CodecV7, chainConfig, db, nil)
295295

296296
bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{
297297
MaxL1CommitGasPerBatch: 50000000000,
298298
MaxL1CommitCalldataSizePerBatch: 1000000,
299299
BatchTimeoutSec: 300,
300300
MaxUncompressedBatchBytesSize: math.MaxUint64,
301-
}, encoding.CodecV7, chainConfig, db, db, nil)
301+
}, encoding.CodecV7, chainConfig, db, nil)
302302

303303
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
304304
MaxBatchNumPerBundle: 2,

0 commit comments

Comments
 (0)