@@ -4,9 +4,10 @@ import (
44 "database/sql"
55 "errors"
66 "fmt"
7- "github.com/Layr-Labs/sidecar/pkg/utils"
87 "time"
98
9+ "github.com/Layr-Labs/sidecar/pkg/utils"
10+
1011 "github.com/Layr-Labs/sidecar/pkg/metrics"
1112 "github.com/Layr-Labs/sidecar/pkg/metrics/metricsTypes"
1213 "github.com/Layr-Labs/sidecar/pkg/rewards/rewardsTypes"
@@ -496,8 +497,26 @@ func (rc *RewardsCalculator) DeleteCorruptedRewardsFromBlockHeight(blockHeight u
496497
497498 // purge from gold table
498499 if lowerBoundSnapshot != nil {
499- rc .logger .Sugar ().Infow ("Purging rewards from gold table where snapshot >=" , "snapshotDate" , lowerBoundSnapshot .SnapshotDate )
500- res = rc .grm .Exec (`delete from gold_table where snapshot >= @snapshotDate` , sql .Named ("snapshotDate" , lowerBoundSnapshot .SnapshotDate ))
500+ rc .logger .Sugar ().Infow ("Purging rewards from gold table" )
501+ query := `
502+ with all_combined_rewards as (
503+ select
504+ distinct(reward_hash) as reward_hash
505+ from (
506+ select reward_hash from combined_rewards where block_number > @blockHeight
507+ union all
508+ select reward_hash from operator_directed_rewards where block_number > @blockHeight
509+ union all
510+ select
511+ odosrs.reward_hash
512+ from operator_directed_operator_set_reward_submissions as odosrs
513+ where odosrs.block_number > @blockHeight
514+ ) as t
515+ )
516+ delete from gold_table
517+ where reward_hash in (select reward_hash from all_combined_rewards)
518+ `
519+ res = rc .grm .Exec (query , sql .Named ("blockHeight" , blockHeight ))
501520 } else {
502521 // if the lower bound is nil, ther we're deleting everything
503522 rc .logger .Sugar ().Infow ("Purging all rewards from gold table" )
0 commit comments