From 82638d891775c555bf4eb2554b31ffa68b2a9ed4 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sat, 17 Aug 2024 13:36:27 +0200 Subject: [PATCH] prevent duplicate processing of epochstats --- indexer/beacon/epochstats.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/indexer/beacon/epochstats.go b/indexer/beacon/epochstats.go index 20f38f9..d83f1c6 100644 --- a/indexer/beacon/epochstats.go +++ b/indexer/beacon/epochstats.go @@ -25,12 +25,14 @@ type EpochStats struct { dependentRoot phase0.Root dependentState *epochState - requestedMutex sync.Mutex - requestedBy []*Client - ready bool - readyChanMutex sync.Mutex - readyChan chan bool - isInDb bool + requestedMutex sync.Mutex + requestedBy []*Client + ready bool + readyChanMutex sync.Mutex + readyChan chan bool + processingMutex sync.Mutex + processing bool + isInDb bool precalcBaseRoot phase0.Root precalcValues *EpochStatsValues @@ -305,6 +307,20 @@ func (es *EpochStats) processState(indexer *Indexer) { if es.dependentState == nil || es.dependentState.loadingStatus != 2 { return } + + es.processingMutex.Lock() + if es.processing { + es.processingMutex.Unlock() + return + } + + es.processing = true + es.processingMutex.Unlock() + + defer func() { + es.processing = false + }() + t1 := time.Now() chainState := indexer.consensusPool.GetChainState()