Skip to content

Commit a4e06a5

Browse files
author
colinlyguo
committed
add mandatory flag to control minimum codec version
1 parent 4479dbf commit a4e06a5

File tree

9 files changed

+47
-32
lines changed

9 files changed

+47
-32
lines changed

common/utils/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
// RollupRelayerFlags contains flags only used in rollup-relayer
2222
RollupRelayerFlags = []cli.Flag{
2323
&ImportGenesisFlag,
24+
&MinCodecVersionFlag,
2425
}
2526
// ConfigFileFlag load json type config file.
2627
ConfigFileFlag = cli.StringFlag{
@@ -90,4 +91,10 @@ var (
9091
Usage: "Genesis file of the network",
9192
Value: "./conf/genesis.json",
9293
}
94+
// MinCodecVersionFlag defines the minimum codec version required for the chunk/batch/bundle proposers
95+
MinCodecVersionFlag = cli.UintFlag{
96+
Name: "min-codec-version",
97+
Usage: "Minimum required codec version for the chunk/batch/bundle proposers",
98+
Required: true,
99+
}
93100
)

rollup/cmd/rollup_relayer/app/app.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/prometheus/client_golang/prometheus"
11+
"github.com/scroll-tech/da-codec/encoding"
1112
"github.com/scroll-tech/go-ethereum/ethclient"
1213
"github.com/scroll-tech/go-ethereum/log"
1314
"github.com/urfave/cli/v2"
@@ -84,9 +85,10 @@ func action(ctx *cli.Context) error {
8485
log.Crit("failed to create l2 relayer", "config file", cfgFile, "error", err)
8586
}
8687

87-
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, genesis.Config, db, registry)
88-
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, genesis.Config, db, registry)
89-
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, genesis.Config, db, registry)
88+
minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name))
89+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, registry)
90+
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, registry)
91+
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
9092

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

rollup/internal/controller/watcher/batch_proposer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type BatchProposer struct {
3434
gasCostIncreaseMultiplier float64
3535
maxUncompressedBatchBytesSize uint64
3636

37-
chainCfg *params.ChainConfig
37+
minCodecVersion encoding.CodecVersion
38+
chainCfg *params.ChainConfig
3839

3940
batchProposerCircleTotal prometheus.Counter
4041
proposeBatchFailureTotal prometheus.Counter
@@ -58,7 +59,7 @@ type BatchProposer struct {
5859
}
5960

6061
// NewBatchProposer creates a new BatchProposer instance.
61-
func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer {
62+
func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer {
6263
log.Info("new batch proposer",
6364
"maxL1CommitGasPerBatch", cfg.MaxL1CommitGasPerBatch,
6465
"maxL1CommitCalldataSizePerBatch", cfg.MaxL1CommitCalldataSizePerBatch,
@@ -78,6 +79,7 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chai
7879
batchTimeoutSec: cfg.BatchTimeoutSec,
7980
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
8081
maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize,
82+
minCodecVersion: minCodecVersion,
8183
chainCfg: chainCfg,
8284

8385
batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
@@ -248,8 +250,8 @@ func (p *BatchProposer) proposeBatch() error {
248250
return fmt.Errorf("failed to retrieve codec for block number %v and time %v", firstUnbatchedChunk.StartBlockNumber, firstUnbatchedChunk.StartBlockTime)
249251
}
250252

251-
if codec.Version() < encoding.CodecV4 {
252-
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codec.Version(), encoding.CodecV4)
253+
if codec.Version() < p.minCodecVersion {
254+
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codec.Version(), p.minCodecVersion)
253255
}
254256

255257
maxChunksThisBatch := codec.MaxNumChunksPerBatch()

rollup/internal/controller/watcher/batch_proposer_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func testBatchProposerLimitsCodecV4(t *testing.T) {
117117
ChunkTimeoutSec: 300,
118118
GasCostIncreaseMultiplier: 1.2,
119119
MaxUncompressedBatchBytesSize: math.MaxUint64,
120-
}, &params.ChainConfig{
120+
}, encoding.CodecV4, &params.ChainConfig{
121121
LondonBlock: big.NewInt(0),
122122
BernoulliBlock: big.NewInt(0),
123123
CurieBlock: big.NewInt(0),
@@ -140,7 +140,7 @@ func testBatchProposerLimitsCodecV4(t *testing.T) {
140140
BatchTimeoutSec: tt.batchTimeoutSec,
141141
GasCostIncreaseMultiplier: 1.2,
142142
MaxUncompressedBatchBytesSize: math.MaxUint64,
143-
}, &params.ChainConfig{
143+
}, encoding.CodecV4, &params.ChainConfig{
144144
LondonBlock: big.NewInt(0),
145145
BernoulliBlock: big.NewInt(0),
146146
CurieBlock: big.NewInt(0),
@@ -211,7 +211,7 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) {
211211
ChunkTimeoutSec: 300,
212212
GasCostIncreaseMultiplier: 1.2,
213213
MaxUncompressedBatchBytesSize: math.MaxUint64,
214-
}, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
214+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
215215
cp.TryProposeChunk() // chunk1 contains block1
216216
cp.TryProposeChunk() // chunk2 contains block2
217217

@@ -228,7 +228,7 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) {
228228
BatchTimeoutSec: 0,
229229
GasCostIncreaseMultiplier: 1.2,
230230
MaxUncompressedBatchBytesSize: math.MaxUint64,
231-
}, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
231+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
232232
bp.TryProposeBatch()
233233

234234
batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0)
@@ -296,7 +296,7 @@ func testBatchProposerBlobSizeLimitCodecV4(t *testing.T) {
296296
ChunkTimeoutSec: 0,
297297
GasCostIncreaseMultiplier: 1,
298298
MaxUncompressedBatchBytesSize: math.MaxUint64,
299-
}, chainConfig, db, nil)
299+
}, encoding.CodecV4, chainConfig, db, nil)
300300

301301
blockHeight := int64(0)
302302
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
@@ -317,7 +317,7 @@ func testBatchProposerBlobSizeLimitCodecV4(t *testing.T) {
317317
BatchTimeoutSec: math.MaxUint32,
318318
GasCostIncreaseMultiplier: 1,
319319
MaxUncompressedBatchBytesSize: math.MaxUint64,
320-
}, chainConfig, db, nil)
320+
}, encoding.CodecV4, chainConfig, db, nil)
321321

322322
for i := 0; i < 2; i++ {
323323
bp.TryProposeBatch()
@@ -390,7 +390,7 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV4(t *testing.T) {
390390
ChunkTimeoutSec: 0,
391391
GasCostIncreaseMultiplier: 1,
392392
MaxUncompressedBatchBytesSize: math.MaxUint64,
393-
}, chainConfig, db, nil)
393+
}, encoding.CodecV4, chainConfig, db, nil)
394394

395395
block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json")
396396
for blockHeight := int64(1); blockHeight <= 60; blockHeight++ {
@@ -406,7 +406,7 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV4(t *testing.T) {
406406
BatchTimeoutSec: math.MaxUint32,
407407
GasCostIncreaseMultiplier: 1,
408408
MaxUncompressedBatchBytesSize: math.MaxUint64,
409-
}, chainConfig, db, nil)
409+
}, encoding.CodecV4, chainConfig, db, nil)
410410
bp.TryProposeBatch()
411411

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

rollup/internal/controller/watcher/bundle_proposer.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type BundleProposer struct {
2929
maxBatchNumPerBundle uint64
3030
bundleTimeoutSec uint64
3131

32-
chainCfg *params.ChainConfig
32+
minCodecVersion encoding.CodecVersion
33+
chainCfg *params.ChainConfig
3334

3435
bundleProposerCircleTotal prometheus.Counter
3536
proposeBundleFailureTotal prometheus.Counter
@@ -41,7 +42,7 @@ type BundleProposer struct {
4142
}
4243

4344
// NewBundleProposer creates a new BundleProposer instance.
44-
func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BundleProposer {
45+
func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BundleProposer {
4546
log.Info("new bundle proposer", "bundleBatchesNum", cfg.MaxBatchNumPerBundle, "bundleTimeoutSec", cfg.BundleTimeoutSec)
4647

4748
p := &BundleProposer{
@@ -52,6 +53,7 @@ func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, ch
5253
bundleOrm: orm.NewBundle(db),
5354
maxBatchNumPerBundle: cfg.MaxBatchNumPerBundle,
5455
bundleTimeoutSec: cfg.BundleTimeoutSec,
56+
minCodecVersion: minCodecVersion,
5557
chainCfg: chainCfg,
5658

5759
bundleProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
@@ -131,7 +133,7 @@ func (p *BundleProposer) proposeBundle() error {
131133

132134
// select at most maxBlocksThisChunk blocks
133135
maxBatchesThisBundle := p.maxBatchNumPerBundle
134-
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV4, int(maxBatchesThisBundle))
136+
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, p.minCodecVersion, int(maxBatchesThisBundle))
135137
if err != nil {
136138
return err
137139
}
@@ -155,8 +157,8 @@ func (p *BundleProposer) proposeBundle() error {
155157
hardforkName := encoding.GetHardforkName(p.chainCfg, firstChunk.StartBlockNumber, firstChunk.StartBlockTime)
156158
codecVersion := encoding.CodecVersion(batches[0].CodecVersion)
157159

158-
if codecVersion < encoding.CodecV4 {
159-
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, encoding.CodecV4)
160+
if codecVersion < p.minCodecVersion {
161+
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, p.minCodecVersion)
160162
}
161163

162164
for i := 1; i < len(batches); i++ {

rollup/internal/controller/watcher/bundle_proposer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ func testBundleProposerLimitsCodecV4(t *testing.T) {
9999
ChunkTimeoutSec: math.MaxUint32,
100100
GasCostIncreaseMultiplier: 1,
101101
MaxUncompressedBatchBytesSize: math.MaxUint64,
102-
}, chainConfig, db, nil)
102+
}, encoding.CodecV4, chainConfig, db, nil)
103103

104104
bap := NewBatchProposer(context.Background(), &config.BatchProposerConfig{
105105
MaxL1CommitGasPerBatch: math.MaxUint64,
106106
MaxL1CommitCalldataSizePerBatch: math.MaxUint64,
107107
BatchTimeoutSec: 0,
108108
GasCostIncreaseMultiplier: 1,
109109
MaxUncompressedBatchBytesSize: math.MaxUint64,
110-
}, chainConfig, db, nil)
110+
}, encoding.CodecV4, chainConfig, db, nil)
111111

112112
cp.TryProposeChunk() // chunk1 contains block1
113113
bap.TryProposeBatch() // batch1 contains chunk1
@@ -117,7 +117,7 @@ func testBundleProposerLimitsCodecV4(t *testing.T) {
117117
bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{
118118
MaxBatchNumPerBundle: tt.maxBatchNumPerBundle,
119119
BundleTimeoutSec: tt.bundleTimeoutSec,
120-
}, chainConfig, db, nil)
120+
}, encoding.CodecV4, chainConfig, db, nil)
121121

122122
bup.TryProposeBundle()
123123

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type ChunkProposer struct {
3434
gasCostIncreaseMultiplier float64
3535
maxUncompressedBatchBytesSize uint64
3636

37-
chainCfg *params.ChainConfig
37+
minCodecVersion encoding.CodecVersion
38+
chainCfg *params.ChainConfig
3839

3940
chunkProposerCircleTotal prometheus.Counter
4041
proposeChunkFailureTotal prometheus.Counter
@@ -60,7 +61,7 @@ type ChunkProposer struct {
6061
}
6162

6263
// NewChunkProposer creates a new ChunkProposer instance.
63-
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
64+
func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer {
6465
log.Info("new chunk proposer",
6566
"maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk,
6667
"maxTxNumPerChunk", cfg.MaxTxNumPerChunk,
@@ -85,6 +86,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chai
8586
chunkTimeoutSec: cfg.ChunkTimeoutSec,
8687
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
8788
maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize,
89+
minCodecVersion: minCodecVersion,
8890
chainCfg: chainCfg,
8991

9092
chunkProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
@@ -277,8 +279,8 @@ func (p *ChunkProposer) proposeChunk() error {
277279

278280
codecVersion := encoding.GetCodecVersion(p.chainCfg, blocks[0].Header.Number.Uint64(), blocks[0].Header.Time)
279281

280-
if codecVersion < encoding.CodecV4 {
281-
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, encoding.CodecV4)
282+
if codecVersion < p.minCodecVersion {
283+
return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, p.minCodecVersion)
282284
}
283285

284286
// Including Curie block in a sole chunk.

rollup/internal/controller/watcher/chunk_proposer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func testChunkProposerLimitsCodecV4(t *testing.T) {
164164
ChunkTimeoutSec: tt.chunkTimeoutSec,
165165
GasCostIncreaseMultiplier: 1.2,
166166
MaxUncompressedBatchBytesSize: math.MaxUint64,
167-
}, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
167+
}, encoding.CodecV4, &params.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil)
168168
cp.TryProposeChunk()
169169

170170
chunkOrm := orm.NewChunk(db)
@@ -214,7 +214,7 @@ func testChunkProposerBlobSizeLimitCodecV4(t *testing.T) {
214214
ChunkTimeoutSec: math.MaxUint32,
215215
GasCostIncreaseMultiplier: 1,
216216
MaxUncompressedBatchBytesSize: math.MaxUint64,
217-
}, chainConfig, db, nil)
217+
}, encoding.CodecV4, chainConfig, db, nil)
218218

219219
for i := 0; i < 2; i++ {
220220
cp.TryProposeChunk()

rollup/tests/rollup_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ func testCommitBatchAndFinalizeBundleCodecV4(t *testing.T) {
9797
MaxRowConsumptionPerChunk: 1048319,
9898
ChunkTimeoutSec: 300,
9999
MaxUncompressedBatchBytesSize: math.MaxUint64,
100-
}, chainConfig, db, nil)
100+
}, encoding.CodecV4, chainConfig, db, nil)
101101

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

109109
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
110110
MaxBatchNumPerBundle: 1000000,
111111
BundleTimeoutSec: 300,
112-
}, chainConfig, db, nil)
112+
}, encoding.CodecV4, chainConfig, db, nil)
113113

114114
l2BlockOrm := orm.NewL2Block(db)
115115
err = l2BlockOrm.InsertL2Blocks(context.Background(), blocks[:5])

0 commit comments

Comments
 (0)