Skip to content

Commit e5ba965

Browse files
committed
implement feedback
1 parent 230263d commit e5ba965

6 files changed

Lines changed: 28 additions & 30 deletions

File tree

‎block/internal/da/forced_inclusion_retriever.go‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (r *ForcedInclusionRetriever) RetrieveForcedIncludedTxs(ctx context.Context
5151
return nil, ErrForceInclusionNotConfigured
5252
}
5353

54-
epochStart, epochEnd := types.CalculateEpochBoundaries(daHeight, r.genesis.DAStartHeight, r.daEpochSize)
54+
epochStart, epochEnd, currentEpochNumber := types.CalculateEpochBoundaries(daHeight, r.genesis.DAStartHeight, r.daEpochSize)
5555

5656
if daHeight != epochStart {
5757
r.logger.Debug().
@@ -66,9 +66,6 @@ func (r *ForcedInclusionRetriever) RetrieveForcedIncludedTxs(ctx context.Context
6666
}, nil
6767
}
6868

69-
// We're at epoch start - fetch transactions from DA
70-
currentEpochNumber := types.CalculateEpochNumber(daHeight, r.genesis.DAStartHeight, r.daEpochSize)
71-
7269
event := &ForcedInclusionEvent{
7370
StartDaHeight: epochStart,
7471
Txs: [][]byte{},
@@ -81,22 +78,22 @@ func (r *ForcedInclusionRetriever) RetrieveForcedIncludedTxs(ctx context.Context
8178
Uint64("epoch_num", currentEpochNumber).
8279
Msg("retrieving forced included transactions from DA")
8380

84-
epochStartResult := r.client.RetrieveForcedInclusion(ctx, epochStart)
85-
if epochStartResult.Code == coreda.StatusHeightFromFuture {
81+
epochEndResult := r.client.RetrieveForcedInclusion(ctx, epochEnd)
82+
if epochEndResult.Code == coreda.StatusHeightFromFuture {
8683
r.logger.Debug().
87-
Uint64("epoch_start", epochStart).
88-
Msg("epoch start height not yet available on DA - backoff required")
89-
return nil, fmt.Errorf("%w: epoch start height %d not yet available", coreda.ErrHeightFromFuture, epochStart)
84+
Uint64("epoch_end", epochEnd).
85+
Msg("epoch end height not yet available on DA - backoff required")
86+
return nil, fmt.Errorf("%w: epoch end height %d not yet available", coreda.ErrHeightFromFuture, epochEnd)
9087
}
9188

92-
epochEndResult := epochStartResult
89+
epochStartResult := epochEndResult
9390
if epochStart != epochEnd {
94-
epochEndResult = r.client.RetrieveForcedInclusion(ctx, epochEnd)
95-
if epochEndResult.Code == coreda.StatusHeightFromFuture {
91+
epochStartResult = r.client.RetrieveForcedInclusion(ctx, epochStart)
92+
if epochStartResult.Code == coreda.StatusHeightFromFuture {
9693
r.logger.Debug().
97-
Uint64("epoch_end", epochEnd).
98-
Msg("epoch end height not yet available on DA - backoff required")
99-
return nil, fmt.Errorf("%w: epoch end height %d not yet available", coreda.ErrHeightFromFuture, epochEnd)
94+
Uint64("epoch_start", epochStart).
95+
Msg("epoch start height not yet available on DA - backoff required")
96+
return nil, fmt.Errorf("%w: epoch start height %d not yet available", coreda.ErrHeightFromFuture, epochStart)
10097
}
10198
}
10299

‎block/internal/syncing/syncer.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ func (s *Syncer) verifyForcedInclusionTxs(currentState types.State, data *types.
705705

706706
// Check if any pending forced inclusion txs from previous epochs are included
707707
var stillPending []pendingForcedInclusionTx
708-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
708+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
709709
pending := value.(pendingForcedInclusionTx)
710710
if _, ok := blockTxMap[pending.TxHash]; ok {
711711
s.logger.Debug().
@@ -752,7 +752,7 @@ func (s *Syncer) verifyForcedInclusionTxs(currentState types.State, data *types.
752752
}
753753

754754
// Update pending map - clear old entries and store only remaining pending
755-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
755+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
756756
s.pendingForcedInclusionTxs.Delete(key)
757757
return true
758758
})
@@ -774,7 +774,7 @@ func (s *Syncer) verifyForcedInclusionTxs(currentState types.State, data *types.
774774
if len(forcedIncludedTxsEvent.Txs) > 0 {
775775
if newPendingCount > 0 {
776776
totalPending := 0
777-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
777+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
778778
totalPending++
779779
return true
780780
})

‎block/internal/syncing/syncer_forced_inclusion_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func TestVerifyForcedInclusionTxs_DeferralWithinEpoch(t *testing.T) {
556556

557557
// Verify that dataBin2 is now tracked as pending
558558
pendingCount := 0
559-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
559+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
560560
pendingCount++
561561
return true
562562
})
@@ -593,7 +593,7 @@ func TestVerifyForcedInclusionTxs_DeferralWithinEpoch(t *testing.T) {
593593

594594
// Verify that pending queue is now empty (dataBin2 was included)
595595
pendingCount = 0
596-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
596+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
597597
pendingCount++
598598
return true
599599
})
@@ -699,7 +699,7 @@ func TestVerifyForcedInclusionTxs_MaliciousAfterEpochEnd(t *testing.T) {
699699

700700
// Verify that the forced tx is tracked as pending
701701
pendingCount := 0
702-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
702+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
703703
pendingCount++
704704
return true
705705
})

‎docs/adr/adr-019-forced-inclusion-mechanism.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (s *Syncer) verifyForcedInclusionTxs(currentState State, data *Data) error
322322

323323
// 3. Check if any pending forced inclusion txs from previous epochs are included
324324
var stillPending []pendingForcedInclusionTx
325-
s.pendingForcedInclusionTxs.Range(func(key, value interface{}) bool {
325+
s.pendingForcedInclusionTxs.Range(func(key, value any) bool {
326326
pending := value.(pendingForcedInclusionTx)
327327
if _, ok := blockTxMap[pending.TxHash]; ok {
328328
// Transaction was included - remove from pending

‎types/epoch.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ func CalculateEpochNumber(daHeight, daStartHeight, daEpochSize uint64) uint64 {
3333
// Returns:
3434
// - start: The first DA height in the epoch (inclusive)
3535
// - end: The last DA height in the epoch (inclusive)
36-
func CalculateEpochBoundaries(daHeight, daStartHeight, daEpochSize uint64) (start, end uint64) {
36+
func CalculateEpochBoundaries(daHeight, daStartHeight, daEpochSize uint64) (start, end, epochNum uint64) {
37+
epochNum = CalculateEpochNumber(daHeight, daStartHeight, daEpochSize)
38+
3739
if daEpochSize == 0 {
38-
return daStartHeight, daStartHeight
40+
return daStartHeight, daStartHeight, epochNum
3941
}
4042

4143
if daHeight < daStartHeight {
42-
return daStartHeight, daStartHeight + daEpochSize - 1
44+
return daStartHeight, daStartHeight + daEpochSize - 1, epochNum
4345
}
4446

45-
epochNum := CalculateEpochNumber(daHeight, daStartHeight, daEpochSize)
4647
start = daStartHeight + (epochNum-1)*daEpochSize
4748
end = daStartHeight + epochNum*daEpochSize - 1
4849

49-
return start, end
50+
return start, end, epochNum
5051
}

‎types/epoch_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func TestCalculateEpochBoundaries(t *testing.T) {
218218

219219
for _, tt := range tests {
220220
t.Run(tt.name, func(t *testing.T) {
221-
start, end := CalculateEpochBoundaries(tt.daHeight, tt.daStartHeight, tt.daEpochSize)
221+
start, end, _ := CalculateEpochBoundaries(tt.daHeight, tt.daStartHeight, tt.daEpochSize)
222222
assert.Equal(t, tt.expectedStart, start, "start height mismatch")
223223
assert.Equal(t, tt.expectedEnd, end, "end height mismatch")
224224
})
@@ -262,7 +262,7 @@ func TestEpochConsistency(t *testing.T) {
262262
epochNum := CalculateEpochNumber(h, tt.daStartHeight, tt.daEpochSize)
263263
assert.Equal(t, epoch, epochNum, "height %d should be in epoch %d", h, epoch)
264264

265-
start, end := CalculateEpochBoundaries(h, tt.daStartHeight, tt.daEpochSize)
265+
start, end, _ := CalculateEpochBoundaries(h, tt.daStartHeight, tt.daEpochSize)
266266
assert.Equal(t, expectedStart, start, "height %d should have start %d", h, expectedStart)
267267
assert.Equal(t, expectedEnd, end, "height %d should have end %d", h, expectedEnd)
268268
}
@@ -293,7 +293,7 @@ func TestEpochBoundaryTransitions(t *testing.T) {
293293
epoch := CalculateEpochNumber(tr.height, daStartHeight, daEpochSize)
294294
assert.Equal(t, tr.expectedEpoch, epoch, "height %d epoch mismatch", tr.height)
295295

296-
start, end := CalculateEpochBoundaries(tr.height, daStartHeight, daEpochSize)
296+
start, end, _ := CalculateEpochBoundaries(tr.height, daStartHeight, daEpochSize)
297297
assert.Equal(t, tr.expectedStart, start, "height %d start mismatch", tr.height)
298298
assert.Equal(t, tr.expectedEnd, end, "height %d end mismatch", tr.height)
299299
}

0 commit comments

Comments
 (0)