Skip to content

Commit

Permalink
Merge pull request #389 from gobitfly/NOBIDS/el-rewards-on-head
Browse files Browse the repository at this point in the history
moving maintainTable to onHead
  • Loading branch information
remoterami authored Jun 5, 2024
2 parents fd721e8 + 3ce76bc commit 3fb392f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions backend/pkg/exporter/modules/execution_payloads_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

type executionPayloadsExporter struct {
ModuleContext ModuleContext
ExportMutex *sync.Mutex
ModuleContext ModuleContext
ExportMutex *sync.Mutex
CachedViewMutex *sync.Mutex
}

func NewExecutionPayloadsExporter(moduleContext ModuleContext) ModuleInterface {
Expand All @@ -30,7 +31,17 @@ func NewExecutionPayloadsExporter(moduleContext ModuleContext) ModuleInterface {
}

func (d *executionPayloadsExporter) OnHead(event *constypes.StandardEventHeadResponse) (err error) {
return nil // nop
// if mutex is locked, return early
if !d.ExportMutex.TryLock() {
log.Infof("execution payloads exporter is already running")
return nil
}
defer d.ExportMutex.Unlock()
err = d.maintainTable()
if err != nil {
return fmt.Errorf("error maintaining table: %w", err)
}
return nil
}

func (d *executionPayloadsExporter) Init() error {
Expand All @@ -48,16 +59,11 @@ func (d *executionPayloadsExporter) OnChainReorg(event *constypes.StandardEventC
// can take however long it wants to run, is run in a separate goroutine, so no need to worry about blocking
func (d *executionPayloadsExporter) OnFinalizedCheckpoint(event *constypes.StandardFinalizedCheckpointResponse) (err error) {
// if mutex is locked, return early
if !d.ExportMutex.TryLock() {
if !d.CachedViewMutex.TryLock() {
log.Infof("execution payloads exporter is already running")
return nil
}
defer d.ExportMutex.Unlock()

err = d.maintainTable()
if err != nil {
return fmt.Errorf("error maintaining table: %w", err)
}
defer d.CachedViewMutex.Unlock()

start := time.Now()
// update cached view
Expand Down

0 comments on commit 3fb392f

Please sign in to comment.