mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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
This commit is contained in:
@@ -10,11 +10,13 @@ import (
|
|||||||
|
|
||||||
// pruneExpired prunes attestations pool on every slot interval.
|
// pruneExpired prunes attestations pool on every slot interval.
|
||||||
func (s *Service) pruneExpired() {
|
func (s *Service) pruneExpired() {
|
||||||
ticker := time.NewTicker(s.cfg.pruneInterval)
|
secondsPerSlot := params.BeaconConfig().SecondsPerSlot
|
||||||
defer ticker.Stop()
|
offset := time.Duration(secondsPerSlot-1) * time.Second
|
||||||
|
slotTicker := slots.NewSlotTickerWithOffset(s.genesisTime, offset, secondsPerSlot)
|
||||||
|
defer slotTicker.Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-slotTicker.C():
|
||||||
s.pruneExpiredAtts()
|
s.pruneExpiredAtts()
|
||||||
s.updateMetrics()
|
s.updateMetrics()
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPruneExpired_Ticker(t *testing.T) {
|
func TestPruneExpired_Ticker(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
|
// Need timeout longer than the offset (secondsPerSlot - 1) + some buffer
|
||||||
|
timeout := time.Duration(params.BeaconConfig().SecondsPerSlot+5) * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(t.Context(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
s, err := NewService(ctx, &Config{
|
s, err := NewService(ctx, &Config{
|
||||||
|
|||||||
3
changelog/ttsao_use-slot-ticker-pruning.md
Normal file
3
changelog/ttsao_use-slot-ticker-pruning.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Ignored
|
||||||
|
|
||||||
|
- Use SlotTicker with offset instead of time.Ticker for attestation pool pruning to avoid conflicts with slot boundary operations
|
||||||
Reference in New Issue
Block a user