Compare commits

...

6 Commits

Author SHA1 Message Date
colinlyguo
3f684ed8b0 chore: auto version bump [bot] 2024-11-19 06:31:22 +00:00
colin
f69d82024b Merge branch 'develop' into feat-rollup-relayer-static-batch-per-bundle 2024-11-19 13:31:07 +07:00
colinlyguo
15ff972b3b fix unit tests 2024-11-19 13:09:36 +08:00
colinlyguo
8882d4db34 fix unit tests 2024-11-19 02:47:44 +08:00
colinlyguo
0b33b812f8 chore: auto version bump [bot] 2024-11-18 16:36:37 +00:00
colinlyguo
676f41f252 feat(bundle-proposer): static batch per bundle 2024-11-19 00:35:25 +08:00
6 changed files with 33 additions and 62 deletions

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "v4.4.76"
var tag = "v4.4.77"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -104,8 +104,7 @@
"max_uncompressed_batch_bytes_size": 634880
},
"bundle_proposer_config": {
"max_batch_num_per_bundle": 20,
"bundle_timeout_sec": 36000
"batch_num_per_bundle": 20
}
},
"db_config": {

View File

@@ -51,6 +51,5 @@ type BatchProposerConfig struct {
// BundleProposerConfig loads bundle_proposer configuration items.
type BundleProposerConfig struct {
MaxBatchNumPerBundle uint64 `json:"max_batch_num_per_bundle"`
BundleTimeoutSec uint64 `json:"bundle_timeout_sec"`
BatchNumPerBundle uint64 `json:"batch_num_per_bundle"`
}

View File

@@ -3,7 +3,6 @@ package watcher
import (
"context"
"errors"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -25,8 +24,7 @@ type BundleProposer struct {
batchOrm *orm.Batch
bundleOrm *orm.Bundle
maxBatchNumPerBundle uint64
bundleTimeoutSec uint64
batchNumPerBundle uint64
chainCfg *params.ChainConfig
@@ -35,23 +33,21 @@ type BundleProposer struct {
proposeBundleUpdateInfoTotal prometheus.Counter
proposeBundleUpdateInfoFailureTotal prometheus.Counter
bundleBatchesNum prometheus.Gauge
bundleFirstBlockTimeoutReached prometheus.Counter
bundleBatchesProposeNotEnoughTotal prometheus.Counter
}
// NewBundleProposer creates a new BundleProposer instance.
func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BundleProposer {
log.Info("new bundle proposer", "bundleBatchesNum", cfg.MaxBatchNumPerBundle, "bundleTimeoutSec", cfg.BundleTimeoutSec)
log.Info("new bundle proposer", "bundleBatchesNum", cfg.BatchNumPerBundle)
p := &BundleProposer{
ctx: ctx,
db: db,
chunkOrm: orm.NewChunk(db),
batchOrm: orm.NewBatch(db),
bundleOrm: orm.NewBundle(db),
maxBatchNumPerBundle: cfg.MaxBatchNumPerBundle,
bundleTimeoutSec: cfg.BundleTimeoutSec,
chainCfg: chainCfg,
ctx: ctx,
db: db,
chunkOrm: orm.NewChunk(db),
batchOrm: orm.NewBatch(db),
bundleOrm: orm.NewBundle(db),
batchNumPerBundle: cfg.BatchNumPerBundle,
chainCfg: chainCfg,
bundleProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_propose_bundle_circle_total",
@@ -73,10 +69,6 @@ func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, ch
Name: "rollup_propose_bundle_batches_number",
Help: "The number of batches in the current bundle.",
}),
bundleFirstBlockTimeoutReached: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_propose_bundle_first_block_timeout_reached_total",
Help: "Total times the first block in a bundle reached the timeout.",
}),
bundleBatchesProposeNotEnoughTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_propose_bundle_batches_propose_not_enough_total",
Help: "Total number of times there were not enough batches to propose a bundle.",
@@ -128,9 +120,9 @@ func (p *BundleProposer) proposeBundle() error {
return err
}
// select at most maxBlocksThisChunk blocks
maxBatchesThisBundle := p.maxBatchNumPerBundle
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV3, int(maxBatchesThisBundle))
// select at most batchesThisBundle batches
batchesThisBundle := p.batchNumPerBundle
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV3, int(batchesThisBundle))
if err != nil {
return err
}
@@ -161,22 +153,13 @@ func (p *BundleProposer) proposeBundle() error {
currentHardfork := encoding.GetHardforkName(p.chainCfg, chunk.StartBlockNumber, chunk.StartBlockTime)
if currentHardfork != hardforkName {
batches = batches[:i]
maxBatchesThisBundle = uint64(i) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
batchesThisBundle = uint64(i) // update batchesThisBundle as these are the last batches before the hardfork
break
}
}
if uint64(len(batches)) == maxBatchesThisBundle {
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)
p.bundleFirstBlockTimeoutReached.Inc()
p.bundleBatchesNum.Set(float64(len(batches)))
return p.updateDBBundleInfo(batches, codecVersion)
}
currentTimeSec := uint64(time.Now().Unix())
if firstChunk.StartBlockTime+p.bundleTimeoutSec < currentTimeSec {
log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "current time", currentTimeSec)
p.bundleFirstBlockTimeoutReached.Inc()
if uint64(len(batches)) == batchesThisBundle {
log.Info("bundle complete: reached target batch count", "batch count", len(batches), "start batch index", batches[0].Index, "end batch index", batches[len(batches)-1].Index)
p.bundleBatchesNum.Set(float64(len(batches)))
return p.updateDBBundleInfo(batches, codecVersion)
}

View File

@@ -23,33 +23,26 @@ import (
func testBundleProposerLimits(t *testing.T) {
tests := []struct {
name string
maxBatchNumPerBundle uint64
batchNumPerBundle uint64
bundleTimeoutSec uint64
expectedBundlesLen int
expectedBatchesInFirstBundle uint64 // only be checked when expectedBundlesLen > 0
}{
{
name: "NoLimitReached",
maxBatchNumPerBundle: math.MaxUint64,
bundleTimeoutSec: math.MaxUint32,
expectedBundlesLen: 0,
name: "NoLimitReached",
batchNumPerBundle: math.MaxUint64,
bundleTimeoutSec: math.MaxUint32,
expectedBundlesLen: 0,
},
{
name: "Timeout",
maxBatchNumPerBundle: math.MaxUint64,
bundleTimeoutSec: 0,
expectedBundlesLen: 1,
expectedBatchesInFirstBundle: 2,
},
{
name: "maxBatchNumPerBundleIs0",
maxBatchNumPerBundle: 0,
bundleTimeoutSec: math.MaxUint32,
expectedBundlesLen: 0,
name: "maxBatchNumPerBundleIs0",
batchNumPerBundle: 0,
bundleTimeoutSec: math.MaxUint32,
expectedBundlesLen: 0,
},
{
name: "maxBatchNumPerBundleIs1",
maxBatchNumPerBundle: 1,
batchNumPerBundle: 1,
bundleTimeoutSec: math.MaxUint32,
expectedBundlesLen: 1,
expectedBatchesInFirstBundle: 1,
@@ -115,8 +108,7 @@ func testBundleProposerLimits(t *testing.T) {
bap.TryProposeBatch() // batch2 contains chunk2
bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{
MaxBatchNumPerBundle: tt.maxBatchNumPerBundle,
BundleTimeoutSec: tt.bundleTimeoutSec,
BatchNumPerBundle: tt.batchNumPerBundle,
}, chainConfig, db, nil)
bup.TryProposeBundle()
@@ -144,6 +136,7 @@ func testBundleProposerRespectHardforks(t *testing.T) {
BernoulliBlock: big.NewInt(1),
CurieBlock: big.NewInt(2),
DarwinTime: func() *uint64 { t := uint64(4); return &t }(),
DarwinV2Time: func() *uint64 { t := uint64(4); return &t }(),
}
// Add genesis batch.
@@ -205,8 +198,7 @@ func testBundleProposerRespectHardforks(t *testing.T) {
}
bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{
MaxBatchNumPerBundle: math.MaxUint64,
BundleTimeoutSec: 0,
BatchNumPerBundle: 1,
}, chainConfig, db, nil)
for i := 0; i < 5; i++ {

View File

@@ -113,8 +113,7 @@ func testCommitBatchAndFinalizeBatchOrBundleWithAllCodecVersions(t *testing.T) {
}, chainConfig, db, nil)
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
MaxBatchNumPerBundle: 1000000,
BundleTimeoutSec: 300,
BatchNumPerBundle: 2,
}, chainConfig, db, nil)
l2BlockOrm := orm.NewL2Block(db)
@@ -280,8 +279,7 @@ func testCommitBatchAndFinalizeBatchOrBundleCrossingAllTransitions(t *testing.T)
}, chainConfig, db, nil)
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
MaxBatchNumPerBundle: 1000000,
BundleTimeoutSec: 300,
BatchNumPerBundle: 1,
}, chainConfig, db, nil)
cp.TryProposeChunk()