Skip to content

Commit 6d596ed

Browse files
authored
Use SlotTicker instead of time.Ticker for attestation pool pruning (#15917)
* Use SlotTicker instead of time.Ticker for attestation pool pruning * Offset one second before slot start
1 parent 9153c5a commit 6d596ed

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

beacon-chain/operations/attestations/prune_expired.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010

1111
// pruneExpired prunes attestations pool on every slot interval.
1212
func (s *Service) pruneExpired() {
13-
ticker := time.NewTicker(s.cfg.pruneInterval)
14-
defer ticker.Stop()
13+
secondsPerSlot := params.BeaconConfig().SecondsPerSlot
14+
offset := time.Duration(secondsPerSlot-1) * time.Second
15+
slotTicker := slots.NewSlotTickerWithOffset(s.genesisTime, offset, secondsPerSlot)
16+
defer slotTicker.Done()
1517
for {
1618
select {
17-
case <-ticker.C:
19+
case <-slotTicker.C():
1820
s.pruneExpiredAtts()
1921
s.updateMetrics()
2022
case <-s.ctx.Done():

beacon-chain/operations/attestations/prune_expired_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
)
1818

1919
func TestPruneExpired_Ticker(t *testing.T) {
20-
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
20+
// Need timeout longer than the offset (secondsPerSlot - 1) + some buffer
21+
timeout := time.Duration(params.BeaconConfig().SecondsPerSlot+5) * time.Second
22+
ctx, cancel := context.WithTimeout(t.Context(), timeout)
2123
defer cancel()
2224

2325
s, err := NewService(ctx, &Config{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Ignored
2+
3+
- Use SlotTicker with offset instead of time.Ticker for attestation pool pruning to avoid conflicts with slot boundary operations

0 commit comments

Comments
 (0)