Skip to content

Commit

Permalink
dynamic batches of a bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehao committed Jul 21, 2024
1 parent f7a9587 commit f6499be
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rollup/internal/controller/watcher/bundle_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type BundleProposer struct {
bundleBatchesNum prometheus.Gauge
bundleFirstBlockTimeoutReached prometheus.Counter
bundleBatchesProposeNotEnoughTotal prometheus.Counter

lastBundleId uint64
}

// NewBundleProposer creates a new BundleProposer instance.
Expand Down Expand Up @@ -103,8 +105,10 @@ func (p *BundleProposer) updateDBBundleInfo(batches []*orm.Batch, codecVersion e
}

p.proposeBundleUpdateInfoTotal.Inc()
var bundle *orm.Bundle
err := p.db.Transaction(func(dbTX *gorm.DB) error {
bundle, err := p.bundleOrm.InsertBundle(p.ctx, batches, codecVersion, dbTX)
var err error
bundle, err = p.bundleOrm.InsertBundle(p.ctx, batches, codecVersion, dbTX)
if err != nil {
log.Warn("BundleProposer.InsertBundle failed", "err", err)
return err
Expand All @@ -120,6 +124,7 @@ func (p *BundleProposer) updateDBBundleInfo(batches []*orm.Batch, codecVersion e
log.Error("update chunk info in orm failed", "err", err)
return err
}
p.lastBundleId = bundle.Index
return nil
}

Expand All @@ -130,7 +135,8 @@ func (p *BundleProposer) proposeBundle() error {
}

// select at most maxBlocksThisChunk blocks
maxBatchesThisBundle := p.maxBatchNumPerBundle
//maxBatchesThisBundle := p.maxBatchNumPerBundle
maxBatchesThisBundle := p.lastBundleId%p.maxBatchNumPerBundle + 1
batches, err := p.batchOrm.GetBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, encoding.CodecV3, int(maxBatchesThisBundle))
if err != nil {
return err
Expand Down

0 comments on commit f6499be

Please sign in to comment.