Skip to content

Commit

Permalink
add(exporter): cooldowns for payload exporter & rewards finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
invis-bitfly authored and guybrush committed Jan 15, 2025
1 parent e35300d commit 7c01d98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/pkg/exporter/modules/execution_payloads_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/big"
"sync"
"time"

"github.com/gobitfly/beaconchain/pkg/commons/db"
"github.com/gobitfly/beaconchain/pkg/commons/log"
Expand All @@ -21,6 +22,7 @@ import (
type executionPayloadsExporter struct {
ModuleContext ModuleContext
ExportMutex *sync.Mutex
CooldownTs time.Time
}

func NewExecutionPayloadsExporter(moduleContext ModuleContext) ModuleInterface {
Expand All @@ -31,6 +33,10 @@ func NewExecutionPayloadsExporter(moduleContext ModuleContext) ModuleInterface {
}

func (d *executionPayloadsExporter) OnHead(event *constypes.StandardEventHeadResponse) (err error) {
if time.Now().Before(d.CooldownTs) {
log.Warnf("execution rewards finalizer is on cooldown till %s", d.CooldownTs)
return nil
}
// if mutex is locked, return early
if !d.ExportMutex.TryLock() {
log.Infof("execution payloads exporter is already running")
Expand All @@ -39,6 +45,7 @@ func (d *executionPayloadsExporter) OnHead(event *constypes.StandardEventHeadRes
defer d.ExportMutex.Unlock()
err = d.maintainTable()
if err != nil {
d.CooldownTs = time.Now().Add(1 * time.Minute)
return fmt.Errorf("error maintaining table: %w", err)
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (d *executionRewardsFinalizer) OnFinalizedCheckpoint(event *constypes.Stand
func (d *executionRewardsFinalizer) OnHead(event *constypes.StandardEventHeadResponse) (err error) {
if time.Now().Before(d.CooldownTs) {
log.Warnf("execution rewards finalizer is on cooldown till %s", d.CooldownTs)
return nil
}
// if mutex is locked, return early
if !d.ExportMutex.TryLock() {
Expand Down

0 comments on commit 7c01d98

Please sign in to comment.