Skip to content

Commit 93d118b

Browse files
committed
refactor: fix epoch bumping
1 parent 32c089e commit 93d118b

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

sequencers/based/sequencer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *BasedSequencer) SubmitBatchTxs(ctx context.Context, req coresequencer.S
6767
// GetNextBatch retrieves the next batch of transactions from the DA layer
6868
// It fetches forced inclusion transactions and returns them as the next batch
6969
func (s *BasedSequencer) GetNextBatch(ctx context.Context, req coresequencer.GetNextBatchRequest) (*coresequencer.GetNextBatchResponse, error) {
70-
currentDAHeight := s.daHeight.Load()
70+
currentDAHeight := s.GetDAHeight()
7171

7272
s.logger.Debug().Uint64("da_height", currentDAHeight).Msg("fetching forced inclusion transactions from DA")
7373

@@ -88,11 +88,11 @@ func (s *BasedSequencer) GetNextBatch(ctx context.Context, req coresequencer.Get
8888
}
8989
}
9090

91-
// Update DA height based on the retrieved event
92-
if forcedTxsEvent.EndDaHeight > currentDAHeight {
93-
s.SetDAHeight(forcedTxsEvent.EndDaHeight)
94-
} else if forcedTxsEvent.StartDaHeight > currentDAHeight {
95-
s.SetDAHeight(forcedTxsEvent.StartDaHeight)
91+
// Update DA height.
92+
// If we are in between epochs, we still need to bump the da height.
93+
// At the end of an epoch, we need to bump to go to the next epoch.
94+
if forcedTxsEvent.EndDaHeight >= currentDAHeight {
95+
s.SetDAHeight(forcedTxsEvent.EndDaHeight + 1)
9696
}
9797

9898
// Add forced inclusion transactions to the queue with validation

sequencers/common/size_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
// This checks against the DA layer limit, not the per-batch limit.
1313
// Returns true if the blob is within the absolute size limit, false otherwise.
1414
func ValidateBlobSize(blob []byte) bool {
15-
return uint64(len(blob)) <= AbsoluteMaxBlobSize
15+
return uint64(GetBlobSize(blob)) <= AbsoluteMaxBlobSize
1616
}
1717

1818
// WouldExceedCumulativeSize checks if adding a blob would exceed the cumulative size limit for a batch.

sequencers/single/sequencer.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ func (c *Sequencer) GetNextBatch(ctx context.Context, req coresequencer.GetNextB
130130
return nil, ErrInvalidId
131131
}
132132

133-
currentDAHeight := c.daHeight.Load()
133+
currentDAHeight := c.GetDAHeight()
134134

135-
forcedEvent, err := c.fiRetriever.RetrieveForcedIncludedTxs(ctx, currentDAHeight)
135+
forcedTxsEvent, err := c.fiRetriever.RetrieveForcedIncludedTxs(ctx, currentDAHeight)
136136
if err != nil {
137137
if errors.Is(err, coreda.ErrHeightFromFuture) {
138138
c.logger.Debug().
@@ -143,25 +143,27 @@ func (c *Sequencer) GetNextBatch(ctx context.Context, req coresequencer.GetNextB
143143
}
144144

145145
// Still create an empty forced inclusion event
146-
forcedEvent = &block.ForcedInclusionEvent{
146+
forcedTxsEvent = &block.ForcedInclusionEvent{
147147
Txs: [][]byte{},
148148
StartDaHeight: currentDAHeight,
149149
EndDaHeight: currentDAHeight,
150150
}
151151
}
152152

153153
// Always try to process forced inclusion transactions (including pending from previous epochs)
154-
forcedTxs := c.processForcedInclusionTxs(forcedEvent, req.MaxBytes)
155-
if forcedEvent.EndDaHeight > currentDAHeight {
156-
c.SetDAHeight(forcedEvent.EndDaHeight)
157-
} else if forcedEvent.StartDaHeight > currentDAHeight {
158-
c.SetDAHeight(forcedEvent.StartDaHeight)
154+
forcedTxs := c.processForcedInclusionTxs(forcedTxsEvent, req.MaxBytes)
155+
156+
// Update DA height.
157+
// If we are in between epochs, we still need to bump the da height.
158+
// At the end of an epoch, we need to bump to go to the next epoch.
159+
if forcedTxsEvent.EndDaHeight >= currentDAHeight {
160+
c.SetDAHeight(forcedTxsEvent.EndDaHeight + 1)
159161
}
160162

161163
c.logger.Debug().
162164
Int("tx_count", len(forcedTxs)).
163-
Uint64("da_height_start", forcedEvent.StartDaHeight).
164-
Uint64("da_height_end", forcedEvent.EndDaHeight).
165+
Uint64("da_height_start", forcedTxsEvent.StartDaHeight).
166+
Uint64("da_height_end", forcedTxsEvent.EndDaHeight).
165167
Msg("retrieved forced inclusion transactions from DA")
166168

167169
// Calculate size used by forced inclusion transactions

0 commit comments

Comments
 (0)