@@ -3,7 +3,6 @@ package watcher
33import (
44 "context"
55 "errors"
6- "time"
76
87 "github.com/prometheus/client_golang/prometheus"
98 "github.com/prometheus/client_golang/prometheus/promauto"
@@ -25,8 +24,7 @@ type BundleProposer struct {
2524 batchOrm * orm.Batch
2625 bundleOrm * orm.Bundle
2726
28- maxBatchNumPerBundle uint64
29- bundleTimeoutSec uint64
27+ batchNumPerBundle uint64
3028
3129 chainCfg * params.ChainConfig
3230
@@ -41,17 +39,16 @@ type BundleProposer struct {
4139
4240// NewBundleProposer creates a new BundleProposer instance.
4341func NewBundleProposer (ctx context.Context , cfg * config.BundleProposerConfig , chainCfg * params.ChainConfig , db * gorm.DB , reg prometheus.Registerer ) * BundleProposer {
44- log .Info ("new bundle proposer" , "bundleBatchesNum" , cfg .MaxBatchNumPerBundle , "bundleTimeoutSec" , cfg . BundleTimeoutSec )
42+ log .Info ("new bundle proposer" , "bundleBatchesNum" , cfg .BatchNumPerBundle )
4543
4644 p := & BundleProposer {
47- ctx : ctx ,
48- db : db ,
49- chunkOrm : orm .NewChunk (db ),
50- batchOrm : orm .NewBatch (db ),
51- bundleOrm : orm .NewBundle (db ),
52- maxBatchNumPerBundle : cfg .MaxBatchNumPerBundle ,
53- bundleTimeoutSec : cfg .BundleTimeoutSec ,
54- chainCfg : chainCfg ,
45+ ctx : ctx ,
46+ db : db ,
47+ chunkOrm : orm .NewChunk (db ),
48+ batchOrm : orm .NewBatch (db ),
49+ bundleOrm : orm .NewBundle (db ),
50+ batchNumPerBundle : cfg .BatchNumPerBundle ,
51+ chainCfg : chainCfg ,
5552
5653 bundleProposerCircleTotal : promauto .With (reg ).NewCounter (prometheus.CounterOpts {
5754 Name : "rollup_propose_bundle_circle_total" ,
@@ -129,8 +126,8 @@ func (p *BundleProposer) proposeBundle() error {
129126 }
130127
131128 // select at most maxBlocksThisChunk blocks
132- maxBatchesThisBundle := p .maxBatchNumPerBundle
133- batches , err := p .batchOrm .GetBatchesGEIndexGECodecVersion (p .ctx , firstUnbundledBatchIndex , encoding .CodecV3 , int (maxBatchesThisBundle ))
129+ batchesThisBundle := p .batchNumPerBundle
130+ batches , err := p .batchOrm .GetBatchesGEIndexGECodecVersion (p .ctx , firstUnbundledBatchIndex , encoding .CodecV3 , int (batchesThisBundle ))
134131 if err != nil {
135132 return err
136133 }
@@ -161,21 +158,13 @@ func (p *BundleProposer) proposeBundle() error {
161158 currentHardfork := encoding .GetHardforkName (p .chainCfg , chunk .StartBlockNumber , chunk .StartBlockTime )
162159 if currentHardfork != hardforkName {
163160 batches = batches [:i ]
164- maxBatchesThisBundle = uint64 (i ) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
161+ batchesThisBundle = uint64 (i ) // update maxBlocksThisChunk to trigger chunking, because these blocks are the last blocks before the hardfork
165162 break
166163 }
167164 }
168165
169- if uint64 (len (batches )) == maxBatchesThisBundle {
170- 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 )
171- p .bundleFirstBlockTimeoutReached .Inc ()
172- p .bundleBatchesNum .Set (float64 (len (batches )))
173- return p .updateDBBundleInfo (batches , codecVersion )
174- }
175-
176- currentTimeSec := uint64 (time .Now ().Unix ())
177- if firstChunk .StartBlockTime + p .bundleTimeoutSec < currentTimeSec {
178- log .Info ("first block timeout" , "batch count" , len (batches ), "start block number" , firstChunk .StartBlockNumber , "start block timestamp" , firstChunk .StartBlockTime , "current time" , currentTimeSec )
166+ if uint64 (len (batches )) == batchesThisBundle {
167+ log .Info ("reached number of batches per bundle" , "batch count" , len (batches ), "start batch index" , batches [0 ].Index , "end batch index" , batches [len (batches )- 1 ].Index )
179168 p .bundleFirstBlockTimeoutReached .Inc ()
180169 p .bundleBatchesNum .Set (float64 (len (batches )))
181170 return p .updateDBBundleInfo (batches , codecVersion )
0 commit comments