Skip to content

Commit 8167b75

Browse files
author
colinlyguo
committed
tweaks
1 parent 4e5839f commit 8167b75

File tree

10 files changed

+33
-29
lines changed

10 files changed

+33
-29
lines changed

rollup/cmd/proposer_tool/app/app.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ func action(ctx *cli.Context) error {
8888
return fmt.Errorf("failed to retrieve L2 genesis header: %v", err)
8989
}
9090

91-
genesisTime := genesisHeader.Time
92-
currentTime := uint64(time.Now().Unix())
93-
timeDrift := currentTime - genesisTime
94-
95-
cfg.L2Config.ChunkProposerConfig.ChunkTimeoutSec += timeDrift
96-
cfg.L2Config.BatchProposerConfig.BatchTimeoutSec += timeDrift
97-
cfg.L2Config.BundleProposerConfig.BundleTimeoutSec += timeDrift
98-
9991
chunk := &encoding.Chunk{
10092
Blocks: []*encoding.Block{{
10193
Header: genesisHeader,
@@ -149,7 +141,7 @@ func action(ctx *cli.Context) error {
149141
}
150142

151143
minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name))
152-
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry, true /* used by tool */)
144+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry)
153145
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry)
154146
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
155147

rollup/cmd/rollup_relayer/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ 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, false /* not used by tool */)
105+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, db, registry)
106106
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, db, registry)
107107
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
108108

rollup/internal/controller/watcher/batch_proposer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/scroll-tech/go-ethereum/params"
1414
"gorm.io/gorm"
1515

16+
"scroll-tech/common/types"
1617
"scroll-tech/rollup/internal/config"
1718
"scroll-tech/rollup/internal/orm"
1819
"scroll-tech/rollup/internal/utils"
@@ -34,6 +35,7 @@ type BatchProposer struct {
3435
maxUncompressedBatchBytesSize uint64
3536
maxChunksPerBatch int
3637

38+
replayMode bool
3739
minCodecVersion encoding.CodecVersion
3840
chainCfg *params.ChainConfig
3941

@@ -80,6 +82,7 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minC
8082
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
8183
maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize,
8284
maxChunksPerBatch: cfg.MaxChunksPerBatch,
85+
replayMode: db != l2BlockDB,
8386
minCodecVersion: minCodecVersion,
8487
chainCfg: chainCfg,
8588

@@ -226,6 +229,15 @@ func (p *BatchProposer) updateDBBatchInfo(batch *encoding.Batch, codecVersion en
226229
log.Warn("BatchProposer.UpdateBatchHashInRange update the chunk's batch hash failure", "hash", dbBatch.Hash, "error", dbErr)
227230
return dbErr
228231
}
232+
if p.replayMode {
233+
// if replayMode is true, it means that the batch is proposed by the proposer tool, set the batch status to types.RollupCommitted
234+
// and commit tx hash to a unique value so that new bundles can be proposed
235+
if dbErr = p.batchOrm.UpdateCommitTxHashAndRollupStatus(p.ctx, dbBatch.Hash, dbBatch.Hash, types.RollupCommitted, dbTX); dbErr != nil {
236+
log.Warn("BatchProposer.UpdateCommitTxHashAndRollupStatus update the batch's commit tx hash failure", "hash", dbBatch.Hash, "error", dbErr)
237+
return dbErr
238+
}
239+
}
240+
229241
return nil
230242
})
231243
if err != nil {

rollup/internal/controller/watcher/batch_proposer_test.go

Lines changed: 4 additions & 4 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, false /* not used by tool */)
127+
}, db, db, nil)
128128
cp.TryProposeChunk() // chunk1 contains block1
129129
cp.TryProposeChunk() // chunk2 contains block2
130130

@@ -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, false /* not used by tool */)
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)
218218
cp.TryProposeChunk() // chunk1 contains block1
219219
cp.TryProposeChunk() // chunk2 contains block2
220220

@@ -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, false /* not used by tool */)
304+
}, encoding.CodecV4, chainConfig, db, db, nil)
305305

306306
blockHeight := int64(0)
307307
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
@@ -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, false /* not used by tool */)
400+
}, encoding.CodecV4, chainConfig, db, db, nil)
401401

402402
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
403403
for blockHeight := int64(1); blockHeight <= 60; blockHeight++ {

rollup/internal/controller/watcher/bundle_proposer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (p *BundleProposer) proposeBundle() error {
199199

200200
currentTimeSec := uint64(time.Now().Unix())
201201
if firstChunk.StartBlockTime+p.bundleTimeoutSec < currentTimeSec {
202-
log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "current time", currentTimeSec)
202+
log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "bundle timeout", p.bundleTimeoutSec, "current time", currentTimeSec)
203203

204204
batches, err = p.allBatchesCommittedInSameTXIncluded(batches)
205205
if err != nil {

rollup/internal/controller/watcher/bundle_proposer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func testBundleProposerLimitsCodecV4(t *testing.T) {
103103
ChunkTimeoutSec: math.MaxUint32,
104104
GasCostIncreaseMultiplier: 1,
105105
MaxUncompressedBatchBytesSize: math.MaxUint64,
106-
}, encoding.CodecV4, chainConfig, db, db, nil, false /* not used by tool */)
106+
}, encoding.CodecV4, chainConfig, db, db, nil)
107107

108108
bap := NewBatchProposer(context.Background(), &config.BatchProposerConfig{
109109
MaxL1CommitGasPerBatch: math.MaxUint64,

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ChunkProposer struct {
3636
gasCostIncreaseMultiplier float64
3737
maxUncompressedBatchBytesSize uint64
3838

39-
toolFlag bool
39+
replayMode bool
4040
minCodecVersion encoding.CodecVersion
4141
chainCfg *params.ChainConfig
4242

@@ -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, toolFlag bool) *ChunkProposer {
68+
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, l2BlockDB, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
6969
log.Info("new chunk proposer",
7070
"maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk,
7171
"maxTxNumPerChunk", cfg.MaxTxNumPerChunk,
@@ -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-
toolFlag: toolFlag,
95+
replayMode: l2BlockDB != db,
9696
minCodecVersion: minCodecVersion,
9797
chainCfg: chainCfg,
9898

@@ -243,7 +243,7 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en
243243
log.Warn("ChunkProposer.InsertChunk failed", "codec version", codecVersion, "err", err)
244244
return err
245245
}
246-
if !p.toolFlag {
246+
if !p.replayMode {
247247
if err := p.l2BlockOrm.UpdateChunkHashInRange(p.ctx, dbChunk.StartBlockNumber, dbChunk.EndBlockNumber, dbChunk.Hash, dbTX); err != nil {
248248
log.Error("failed to update chunk_hash for l2_blocks", "chunk hash", dbChunk.Hash, "start block", dbChunk.StartBlockNumber, "end block", dbChunk.EndBlockNumber, "err", err)
249249
return err
@@ -445,7 +445,7 @@ func (p *ChunkProposer) tryProposeEuclidTransitionChunk(blocks []*encoding.Block
445445
}
446446

447447
prevBlocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, blocks[0].Header.Number.Uint64()-1, 1)
448-
if !p.toolFlag && (err != nil || len(prevBlocks) == 0 || prevBlocks[0].Header.Hash() != blocks[0].Header.ParentHash) {
448+
if !p.replayMode && (err != nil || len(prevBlocks) == 0 || prevBlocks[0].Header.Hash() != blocks[0].Header.ParentHash) {
449449
return false, fmt.Errorf("failed to get parent block: %w", err)
450450
}
451451

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, false /* not used by tool */)
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)
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, false /* not used by tool */)
256+
}, encoding.CodecV4, chainConfig, db, db, nil)
257257

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

rollup/proposer-tool-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
"max_l2_gas_per_chunk": 20000000,
88
"max_l1_commit_gas_per_chunk": 5000000,
99
"max_l1_commit_calldata_size_per_chunk": 123740,
10-
"chunk_timeout_sec": 720000,
11-
"max_row_consumption_per_chunk": 1000000,
10+
"chunk_timeout_sec": 72000000000,
11+
"max_row_consumption_per_chunk": 10000000000,
1212
"gas_cost_increase_multiplier": 1.2,
1313
"max_uncompressed_batch_bytes_size": 634693
1414
},
1515
"batch_proposer_config": {
1616
"max_l1_commit_gas_per_batch": 5000000,
1717
"max_l1_commit_calldata_size_per_batch": 123740,
18-
"batch_timeout_sec": 720000,
18+
"batch_timeout_sec": 72000000000,
1919
"gas_cost_increase_multiplier": 1.2,
2020
"max_uncompressed_batch_bytes_size": 634693,
2121
"max_chunks_per_batch": 45
2222
},
2323
"bundle_proposer_config": {
2424
"max_batch_num_per_bundle": 45,
25-
"bundle_timeout_sec": 3600
25+
"bundle_timeout_sec": 36000000000
2626
}
2727
},
2828
"db_config": {

rollup/tests/rollup_test.go

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

100100
bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{
101101
MaxL1CommitGasPerBatch: 50000000000,
@@ -291,7 +291,7 @@ func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) {
291291
MaxRowConsumptionPerChunk: 1048319,
292292
ChunkTimeoutSec: 300,
293293
MaxUncompressedBatchBytesSize: math.MaxUint64,
294-
}, encoding.CodecV7, chainConfig, db, db, nil, false /* not used by tool */)
294+
}, encoding.CodecV7, chainConfig, db, db, nil)
295295

296296
bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{
297297
MaxL1CommitGasPerBatch: 50000000000,

0 commit comments

Comments
 (0)