From 04e19a4cad03d14e063a300f5cd35a535add1aee Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Wed, 11 Dec 2024 15:51:05 -0600 Subject: [PATCH] Add check to see if rewards-v2 is enabled update snapshot date in test --- internal/config/config.go | 40 ++++++++++++++++++- pkg/pipeline/pipeline.go | 1 + pkg/rewards/10_goldAvsODRewardAmounts.go | 12 +++++- pkg/rewards/11_goldStaging.go | 21 ++++++++-- pkg/rewards/12_goldFinal.go | 2 +- pkg/rewards/1_goldActiveRewards.go | 2 +- pkg/rewards/2_goldStakerRewardAmounts.go | 2 +- pkg/rewards/3_goldOperatorRewardAmounts.go | 2 +- pkg/rewards/4_goldRewardsForAll.go | 2 +- pkg/rewards/5_goldRfaeStakers.go | 2 +- pkg/rewards/6_goldRfaeOperators.go | 2 +- pkg/rewards/7_goldActiveODRewards.go | 12 +++++- pkg/rewards/8_goldOperatorODRewardAmounts.go | 11 ++++- pkg/rewards/9_goldStakerODRewardAmounts.go | 12 +++++- pkg/rewards/combinedRewards.go | 2 +- .../operatorAvsRegistrationSnaphots.go | 2 +- pkg/rewards/operatorAvsSplitSnapshots.go | 2 +- pkg/rewards/operatorAvsStrategySnapshots.go | 2 +- pkg/rewards/operatorDirectedRewards.go | 2 +- pkg/rewards/operatorPISplitSnapshots.go | 2 +- pkg/rewards/operatorShareSnapshots.go | 2 +- pkg/rewards/operatorShares.go | 2 +- pkg/rewards/rewards.go | 2 +- pkg/rewards/rewardsV2_test.go | 37 +++++++++++------ pkg/rewards/stakerDelegationSnapshots.go | 2 +- .../1_stakerStrategyPayouts.go | 2 +- .../2_operatorStrategyRewards.go | 2 +- .../3_rewardsForAllStrategyPayouts.go | 2 +- .../4_rfaeStakerStrategyPayouts.go | 2 +- .../5_rfaeOperatorStrategyPayout.go | 2 +- .../6_stakerOperatorStaging.go | 2 +- .../stakerOperators/7_stakerOperator.go | 2 +- pkg/rewards/stakerShareSnapshots.go | 2 +- pkg/rewards/stakerShares.go | 2 +- pkg/rewardsUtils/rewardsUtils.go | 2 +- 35 files changed, 150 insertions(+), 50 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index a6763ab1..a263bb5f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,7 @@ import ( "fmt" "strconv" "strings" + "time" "github.com/spf13/viper" ) @@ -254,14 +255,14 @@ func (c *Config) GetForkDates() (ForkMap, error) { Fork_Amazon: "1970-01-01", // Amazon hard fork was never on preprod as we backfilled Fork_Nile: "2024-08-14", // Last calculation end timestamp was 8-13: https://holesky.etherscan.io/tx/0xb5a6855e88c79312b7c0e1c9f59ae9890b97f157ea27e69e4f0fadada4712b64#eventlog Fork_Panama: "2024-10-01", - Fork_Arno: "2024-12-04", + Fork_Arno: "2024-12-12", }, nil case Chain_Holesky: return ForkMap{ Fork_Amazon: "1970-01-01", // Amazon hard fork was never on testnet as we backfilled Fork_Nile: "2024-08-13", // Last calculation end timestamp was 8-12: https://holesky.etherscan.io/tx/0x5fc81b5ed2a78b017ef313c181d8627737a97fef87eee85acedbe39fc8708c56#eventlog Fork_Panama: "2024-10-01", - Fork_Arno: "2024-12-12", + Fork_Arno: "2024-12-13", }, nil case Chain_Mainnet: return ForkMap{ @@ -296,6 +297,41 @@ func (c *Config) GetOperatorRestakedStrategiesStartBlock() uint64 { return 0 } +func (c *Config) ShouldSkipRewardsGeneration(blockNumber uint64) bool { + switch c.Chain { + case Chain_Preprod: + // During this period we deployed the rewards-v2 contracts before updating the sidecar. + // This results in missed events which have to be filled by some means. To fill them in, + // we needed to manually delete delete blocks >= 2871534 and re-index. The trouble here + // is that re-indexing introduces new state which was not present at the original process time. + if blockNumber >= 2871534 && blockNumber <= 2909856 { + return true + } + case Chain_Holesky: + // Skip rewards generation for holesky + case Chain_Mainnet: + // Skip rewards generation for mainnet + } + return false +} + +func (c *Config) IsRewardsV2EnabledForCutoffDate(cutoffDate string) (bool, error) { + forks, err := c.GetForkDates() + if err != nil { + return false, err + } + cutoffDateTime, err := time.Parse(time.DateOnly, cutoffDate) + if err != nil { + return false, errors.Join(fmt.Errorf("failed to parse cutoff date %s", cutoffDate), err) + } + arnoForkDateTime, err := time.Parse(time.DateOnly, forks[Fork_Arno]) + if err != nil { + return false, errors.Join(fmt.Errorf("failed to parse Arno fork date %s", forks[Fork_Arno]), err) + } + + return cutoffDateTime.Compare(arnoForkDateTime) >= 0, nil +} + // CanIgnoreIncorrectRewardsRoot returns true if the rewards root can be ignored for the given block number // // Due to inconsistencies in the rewards root calculation on testnet, we know that some roots diff --git a/pkg/pipeline/pipeline.go b/pkg/pipeline/pipeline.go index 957cdcaf..15d504d2 100644 --- a/pkg/pipeline/pipeline.go +++ b/pkg/pipeline/pipeline.go @@ -186,6 +186,7 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche distributionRoots, err := p.stateManager.GetSubmittedDistributionRoots(blockNumber) if err == nil && distributionRoots != nil { for _, rs := range distributionRoots { + rewardStartTime := time.Now() // first check to see if the root was disabled. If it was, it's possible we introduced changes that diff --git a/pkg/rewards/10_goldAvsODRewardAmounts.go b/pkg/rewards/10_goldAvsODRewardAmounts.go index bd5e7180..19b5f77e 100644 --- a/pkg/rewards/10_goldAvsODRewardAmounts.go +++ b/pkg/rewards/10_goldAvsODRewardAmounts.go @@ -65,6 +65,16 @@ SELECT * FROM operator_token_sums ` func (rc *RewardsCalculator) GenerateGold10AvsODRewardAmountsTable(snapshotDate string) error { + rewardsV2Enabled, err := rc.globalConfig.IsRewardsV2EnabledForCutoffDate(snapshotDate) + if err != nil { + rc.logger.Sugar().Errorw("Failed to check if rewards v2 is enabled", "error", err) + return err + } + if !rewardsV2Enabled { + rc.logger.Sugar().Infow("Rewards v2 is not enabled for this cutoff date, skipping GenerateGold10AvsODRewardAmountsTable") + return nil + } + allTableNames := rewardsUtils.GetGoldTableNames(snapshotDate) destTableName := allTableNames[rewardsUtils.Table_10_AvsODRewardAmounts] @@ -73,7 +83,7 @@ func (rc *RewardsCalculator) GenerateGold10AvsODRewardAmountsTable(snapshotDate zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_10_goldAvsODRewardAmountsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_10_goldAvsODRewardAmountsQuery, map[string]interface{}{ "destTableName": destTableName, "activeODRewardsTable": allTableNames[rewardsUtils.Table_7_ActiveODRewards], }) diff --git a/pkg/rewards/11_goldStaging.go b/pkg/rewards/11_goldStaging.go index 677078ae..2ad37727 100644 --- a/pkg/rewards/11_goldStaging.go +++ b/pkg/rewards/11_goldStaging.go @@ -56,6 +56,7 @@ rewards_for_all_earners_operators AS ( operator_tokens as amount FROM {{.rfaeOperatorTable}} ), +{{ if .enableRewardsV2 }} operator_od_rewards AS ( SELECT DISTINCT -- We can select DISTINCT here because the operator's tokens are the same for each strategy in the reward hash @@ -86,6 +87,7 @@ avs_od_rewards AS ( avs_tokens as amount FROM {{.avsODRewardAmountsTable}} ), +{{ end }} combined_rewards AS ( SELECT * FROM operator_rewards UNION ALL @@ -96,12 +98,14 @@ combined_rewards AS ( SELECT * FROM rewards_for_all_earners_stakers UNION ALL SELECT * FROM rewards_for_all_earners_operators +{{ if .enableRewardsV2 }} UNION ALL SELECT * FROM operator_od_rewards UNION ALL SELECT * FROM staker_od_rewards UNION ALL SELECT * FROM avs_od_rewards +{{ end }} ), -- Dedupe earners, primarily operators who are also their own staker. deduped_earners AS ( @@ -131,7 +135,14 @@ func (rc *RewardsCalculator) GenerateGold11StagingTable(snapshotDate string) err zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_11_goldStagingQuery, map[string]string{ + isRewardsV2Enabled, err := rc.globalConfig.IsRewardsV2EnabledForCutoffDate(snapshotDate) + if err != nil { + rc.logger.Sugar().Errorw("Failed to check if rewards v2 is enabled", "error", err) + return err + } + rc.logger.Sugar().Infow("Is RewardsV2 enabled?", "enabled", isRewardsV2Enabled) + + query, err := rewardsUtils.RenderQueryTemplate(_11_goldStagingQuery, map[string]interface{}{ "destTableName": destTableName, "stakerRewardAmountsTable": allTableNames[rewardsUtils.Table_2_StakerRewardAmounts], "operatorRewardAmountsTable": allTableNames[rewardsUtils.Table_3_OperatorRewardAmounts], @@ -141,6 +152,7 @@ func (rc *RewardsCalculator) GenerateGold11StagingTable(snapshotDate string) err "operatorODRewardAmountsTable": allTableNames[rewardsUtils.Table_8_OperatorODRewardAmounts], "stakerODRewardAmountsTable": allTableNames[rewardsUtils.Table_9_StakerODRewardAmounts], "avsODRewardAmountsTable": allTableNames[rewardsUtils.Table_10_AvsODRewardAmounts], + "enableRewardsV2": isRewardsV2Enabled, }) if err != nil { rc.logger.Sugar().Errorw("Failed to render query template", "error", err) @@ -167,21 +179,22 @@ func (rc *RewardsCalculator) ListGoldStagingRowsForSnapshot(snapshotDate string) allTableNames := rewardsUtils.GetGoldTableNames(snapshotDate) results := make([]*GoldStagingRow, 0) - query, err := rewardsUtils.RenderQueryTemplate(` + query := ` SELECT earner, snapshot::text as snapshot, reward_hash, token, amount - FROM {{.goldStagingTable}} WHERE DATE(snapshot) < @cutoffDate`, map[string]string{ + FROM {{.goldStagingTable}} WHERE DATE(snapshot) < @cutoffDate` + query, err := rewardsUtils.RenderQueryTemplate(query, map[string]interface{}{ "goldStagingTable": allTableNames[rewardsUtils.Table_11_GoldStaging], }) if err != nil { rc.logger.Sugar().Errorw("Failed to render query template", "error", err) return nil, err } - res := rc.grm.Raw(query, + res := rc.grm.Debug().Raw(query, sql.Named("cutoffDate", snapshotDate), ).Scan(&results) if res.Error != nil { diff --git a/pkg/rewards/12_goldFinal.go b/pkg/rewards/12_goldFinal.go index c65e7096..f993b7b2 100644 --- a/pkg/rewards/12_goldFinal.go +++ b/pkg/rewards/12_goldFinal.go @@ -33,7 +33,7 @@ func (rc *RewardsCalculator) GenerateGold12FinalTable(snapshotDate string) error zap.String("cutoffDate", snapshotDate), ) - query, err := rewardsUtils.RenderQueryTemplate(_12_goldFinalQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_12_goldFinalQuery, map[string]interface{}{ "goldStagingTable": allTableNames[rewardsUtils.Table_11_GoldStaging], }) if err != nil { diff --git a/pkg/rewards/1_goldActiveRewards.go b/pkg/rewards/1_goldActiveRewards.go index 9c9ad3c2..d5a7377a 100644 --- a/pkg/rewards/1_goldActiveRewards.go +++ b/pkg/rewards/1_goldActiveRewards.go @@ -112,7 +112,7 @@ func (r *RewardsCalculator) Generate1ActiveRewards(snapshotDate string) error { zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_1_goldActiveRewardsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_1_goldActiveRewardsQuery, map[string]interface{}{ "destTableName": destTableName, "rewardsStart": rewardsStart, "cutoffDate": snapshotDate, diff --git a/pkg/rewards/2_goldStakerRewardAmounts.go b/pkg/rewards/2_goldStakerRewardAmounts.go index a4f510cc..52cbcb76 100644 --- a/pkg/rewards/2_goldStakerRewardAmounts.go +++ b/pkg/rewards/2_goldStakerRewardAmounts.go @@ -153,7 +153,7 @@ func (rc *RewardsCalculator) GenerateGold2StakerRewardAmountsTable(snapshotDate zap.String("arnoHardforkDate", forks[config.Fork_Arno]), ) - query, err := rewardsUtils.RenderQueryTemplate(_2_goldStakerRewardAmountsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_2_goldStakerRewardAmountsQuery, map[string]interface{}{ "destTableName": destTableName, "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], }) diff --git a/pkg/rewards/3_goldOperatorRewardAmounts.go b/pkg/rewards/3_goldOperatorRewardAmounts.go index 787ec446..13e76ace 100644 --- a/pkg/rewards/3_goldOperatorRewardAmounts.go +++ b/pkg/rewards/3_goldOperatorRewardAmounts.go @@ -45,7 +45,7 @@ func (rc *RewardsCalculator) GenerateGold3OperatorRewardAmountsTable(snapshotDat zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_3_goldOperatorRewardAmountsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_3_goldOperatorRewardAmountsQuery, map[string]interface{}{ "destTableName": destTableName, "stakerRewardAmountsTable": allTableNames[rewardsUtils.Table_2_StakerRewardAmounts], }) diff --git a/pkg/rewards/4_goldRewardsForAll.go b/pkg/rewards/4_goldRewardsForAll.go index a9464c76..46038352 100644 --- a/pkg/rewards/4_goldRewardsForAll.go +++ b/pkg/rewards/4_goldRewardsForAll.go @@ -76,7 +76,7 @@ func (rc *RewardsCalculator) GenerateGold4RewardsForAllTable(snapshotDate string zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_4_goldRewardsForAllQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_4_goldRewardsForAllQuery, map[string]interface{}{ "destTableName": destTableName, "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], }) diff --git a/pkg/rewards/5_goldRfaeStakers.go b/pkg/rewards/5_goldRfaeStakers.go index 9d1fd7aa..af605f5f 100644 --- a/pkg/rewards/5_goldRfaeStakers.go +++ b/pkg/rewards/5_goldRfaeStakers.go @@ -142,7 +142,7 @@ func (rc *RewardsCalculator) GenerateGold5RfaeStakersTable(snapshotDate string, zap.String("arnoHardforkDate", forks[config.Fork_Arno]), ) - query, err := rewardsUtils.RenderQueryTemplate(_5_goldRfaeStakersQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_5_goldRfaeStakersQuery, map[string]interface{}{ "destTableName": destTableName, "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], }) diff --git a/pkg/rewards/6_goldRfaeOperators.go b/pkg/rewards/6_goldRfaeOperators.go index c17d80fe..2def909d 100644 --- a/pkg/rewards/6_goldRfaeOperators.go +++ b/pkg/rewards/6_goldRfaeOperators.go @@ -45,7 +45,7 @@ func (rc *RewardsCalculator) GenerateGold6RfaeOperatorsTable(snapshotDate string zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_6_goldRfaeOperatorsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_6_goldRfaeOperatorsQuery, map[string]interface{}{ "destTableName": destTableName, "rfaeStakersTable": allTableNames[rewardsUtils.Table_5_RfaeStakers], }) diff --git a/pkg/rewards/7_goldActiveODRewards.go b/pkg/rewards/7_goldActiveODRewards.go index ee84cc1d..902c9438 100644 --- a/pkg/rewards/7_goldActiveODRewards.go +++ b/pkg/rewards/7_goldActiveODRewards.go @@ -127,6 +127,16 @@ SELECT * FROM active_rewards_final // @param startDate: The lower bound of when to calculate rewards from. If we're running rewards for the first time, // this will be "1970-01-01". If this is a subsequent run, this will be the last snapshot date. func (r *RewardsCalculator) Generate7ActiveODRewards(snapshotDate string) error { + rewardsV2Enabled, err := r.globalConfig.IsRewardsV2EnabledForCutoffDate(snapshotDate) + if err != nil { + r.logger.Sugar().Errorw("Failed to check if rewards v2 is enabled", "error", err) + return err + } + if !rewardsV2Enabled { + r.logger.Sugar().Infow("Rewards v2 is not enabled for this cutoff date, skipping Generate7ActiveODRewards") + return nil + } + allTableNames := rewardsUtils.GetGoldTableNames(snapshotDate) destTableName := allTableNames[rewardsUtils.Table_7_ActiveODRewards] @@ -138,7 +148,7 @@ func (r *RewardsCalculator) Generate7ActiveODRewards(snapshotDate string) error zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_7_goldActiveODRewardsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_7_goldActiveODRewardsQuery, map[string]interface{}{ "destTableName": destTableName, "rewardsStart": rewardsStart, "cutoffDate": snapshotDate, diff --git a/pkg/rewards/8_goldOperatorODRewardAmounts.go b/pkg/rewards/8_goldOperatorODRewardAmounts.go index 8ae90773..5bb9718f 100644 --- a/pkg/rewards/8_goldOperatorODRewardAmounts.go +++ b/pkg/rewards/8_goldOperatorODRewardAmounts.go @@ -66,6 +66,15 @@ SELECT * FROM operator_splits ` func (rc *RewardsCalculator) GenerateGold8OperatorODRewardAmountsTable(snapshotDate string) error { + rewardsV2Enabled, err := rc.globalConfig.IsRewardsV2EnabledForCutoffDate(snapshotDate) + if err != nil { + rc.logger.Sugar().Errorw("Failed to check if rewards v2 is enabled", "error", err) + return err + } + if !rewardsV2Enabled { + rc.logger.Sugar().Infow("Rewards v2 is not enabled for this cutoff date, skipping GenerateGold8OperatorODRewardAmountsTable") + return nil + } allTableNames := rewardsUtils.GetGoldTableNames(snapshotDate) destTableName := allTableNames[rewardsUtils.Table_8_OperatorODRewardAmounts] @@ -74,7 +83,7 @@ func (rc *RewardsCalculator) GenerateGold8OperatorODRewardAmountsTable(snapshotD zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_8_goldOperatorODRewardAmountsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_8_goldOperatorODRewardAmountsQuery, map[string]interface{}{ "destTableName": destTableName, "activeODRewardsTable": allTableNames[rewardsUtils.Table_7_ActiveODRewards], }) diff --git a/pkg/rewards/9_goldStakerODRewardAmounts.go b/pkg/rewards/9_goldStakerODRewardAmounts.go index 5b66a75f..5956f39c 100644 --- a/pkg/rewards/9_goldStakerODRewardAmounts.go +++ b/pkg/rewards/9_goldStakerODRewardAmounts.go @@ -115,6 +115,16 @@ SELECT * FROM staker_reward_amounts ` func (rc *RewardsCalculator) GenerateGold9StakerODRewardAmountsTable(snapshotDate string) error { + rewardsV2Enabled, err := rc.globalConfig.IsRewardsV2EnabledForCutoffDate(snapshotDate) + if err != nil { + rc.logger.Sugar().Errorw("Failed to check if rewards v2 is enabled", "error", err) + return err + } + if !rewardsV2Enabled { + rc.logger.Sugar().Infow("Rewards v2 is not enabled for this cutoff date, skipping GenerateGold9StakerODRewardAmountsTable") + return nil + } + allTableNames := rewardsUtils.GetGoldTableNames(snapshotDate) destTableName := allTableNames[rewardsUtils.Table_9_StakerODRewardAmounts] @@ -123,7 +133,7 @@ func (rc *RewardsCalculator) GenerateGold9StakerODRewardAmountsTable(snapshotDat zap.String("destTableName", destTableName), ) - query, err := rewardsUtils.RenderQueryTemplate(_9_goldStakerODRewardAmountsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_9_goldStakerODRewardAmountsQuery, map[string]interface{}{ "destTableName": destTableName, "activeODRewardsTable": allTableNames[rewardsUtils.Table_7_ActiveODRewards], }) diff --git a/pkg/rewards/combinedRewards.go b/pkg/rewards/combinedRewards.go index 290eba6d..c4d90cf0 100644 --- a/pkg/rewards/combinedRewards.go +++ b/pkg/rewards/combinedRewards.go @@ -45,7 +45,7 @@ const rewardsCombinedQuery = ` func (r *RewardsCalculator) GenerateAndInsertCombinedRewards(snapshotDate string) error { tableName := "combined_rewards" - query, err := rewardsUtils.RenderQueryTemplate(rewardsCombinedQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(rewardsCombinedQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorAvsRegistrationSnaphots.go b/pkg/rewards/operatorAvsRegistrationSnaphots.go index 9ea856e3..fc16a4d7 100644 --- a/pkg/rewards/operatorAvsRegistrationSnaphots.go +++ b/pkg/rewards/operatorAvsRegistrationSnaphots.go @@ -105,7 +105,7 @@ CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, func (r *RewardsCalculator) GenerateAndInsertOperatorAvsRegistrationSnapshots(snapshotDate string) error { tableName := "operator_avs_registration_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(operatorAvsRegistrationSnapshotsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorAvsRegistrationSnapshotsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorAvsSplitSnapshots.go b/pkg/rewards/operatorAvsSplitSnapshots.go index 5456af2b..30a593d8 100644 --- a/pkg/rewards/operatorAvsSplitSnapshots.go +++ b/pkg/rewards/operatorAvsSplitSnapshots.go @@ -86,7 +86,7 @@ select * from final_results func (r *RewardsCalculator) GenerateAndInsertOperatorAvsSplitSnapshots(snapshotDate string) error { tableName := "operator_avs_split_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(operatorAvsSplitSnapshotQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorAvsSplitSnapshotQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorAvsStrategySnapshots.go b/pkg/rewards/operatorAvsStrategySnapshots.go index 7e4f2174..3a15d93f 100644 --- a/pkg/rewards/operatorAvsStrategySnapshots.go +++ b/pkg/rewards/operatorAvsStrategySnapshots.go @@ -144,7 +144,7 @@ func (r *RewardsCalculator) GenerateAndInsertOperatorAvsStrategySnapshots(snapsh tableName := "operator_avs_strategy_snapshots" contractAddresses := r.globalConfig.GetContractsMapForChain() - query, err := rewardsUtils.RenderQueryTemplate(operatorAvsStrategyWindowsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorAvsStrategyWindowsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorDirectedRewards.go b/pkg/rewards/operatorDirectedRewards.go index d0fa074c..9cc7d896 100644 --- a/pkg/rewards/operatorDirectedRewards.go +++ b/pkg/rewards/operatorDirectedRewards.go @@ -46,7 +46,7 @@ const operatorDirectedRewardsQuery = ` func (r *RewardsCalculator) GenerateAndInsertOperatorDirectedRewards(snapshotDate string) error { tableName := "operator_directed_rewards" - query, err := rewardsUtils.RenderQueryTemplate(operatorDirectedRewardsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorDirectedRewardsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorPISplitSnapshots.go b/pkg/rewards/operatorPISplitSnapshots.go index ef212e47..2f9a5ed7 100644 --- a/pkg/rewards/operatorPISplitSnapshots.go +++ b/pkg/rewards/operatorPISplitSnapshots.go @@ -85,7 +85,7 @@ select * from final_results func (r *RewardsCalculator) GenerateAndInsertOperatorPISplitSnapshots(snapshotDate string) error { tableName := "operator_pi_split_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(operatorPISplitSnapshotQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorPISplitSnapshotQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorShareSnapshots.go b/pkg/rewards/operatorShareSnapshots.go index f83e003e..35aa78d8 100644 --- a/pkg/rewards/operatorShareSnapshots.go +++ b/pkg/rewards/operatorShareSnapshots.go @@ -50,7 +50,7 @@ FROM func (r *RewardsCalculator) GenerateAndInsertOperatorShareSnapshots(snapshotDate string) error { tableName := "operator_share_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(operatorShareSnapshotsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorShareSnapshotsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/operatorShares.go b/pkg/rewards/operatorShares.go index 88c42517..3af9775a 100644 --- a/pkg/rewards/operatorShares.go +++ b/pkg/rewards/operatorShares.go @@ -19,7 +19,7 @@ const operatorSharesQuery = ` func (r *RewardsCalculator) GenerateAndInsertOperatorShares(snapshotDate string) error { tableName := "operator_shares" - query, err := rewardsUtils.RenderQueryTemplate(operatorSharesQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(operatorSharesQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/rewards.go b/pkg/rewards/rewards.go index 7c072e4e..c8d714c8 100644 --- a/pkg/rewards/rewards.go +++ b/pkg/rewards/rewards.go @@ -493,7 +493,7 @@ func (rc *RewardsCalculator) fetchRewardsForSnapshot(snapshotDate string) ([]*Re where snapshot <= date '{{.snapshotDate}}' group by 1, 2 order by snapshot desc - `, map[string]string{"snapshotDate": snapshotDate}) + `, map[string]interface{}{"snapshotDate": snapshotDate}) if err != nil { return nil, err diff --git a/pkg/rewards/rewardsV2_test.go b/pkg/rewards/rewardsV2_test.go index 49d9c6ee..cd890901 100644 --- a/pkg/rewards/rewardsV2_test.go +++ b/pkg/rewards/rewardsV2_test.go @@ -72,7 +72,7 @@ func Test_RewardsV2(t *testing.T) { t.Log("Hydrated tables") snapshotDates := []string{ - "2024-12-11", + "2024-12-12", } fmt.Printf("Hydration duration: %v\n", time.Since(testStart)) @@ -148,36 +148,47 @@ func Test_RewardsV2(t *testing.T) { // ------------------------------------------------------------------------ // Rewards V2 // ------------------------------------------------------------------------ + rewardsV2Enabled, err := cfg.IsRewardsV2EnabledForCutoffDate(snapshotDate) + assert.Nil(t, err) + fmt.Printf("Running gold_7_active_od_rewards\n") err = rc.Generate7ActiveODRewards(snapshotDate) assert.Nil(t, err) - rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_7_ActiveODRewards]) - assert.Nil(t, err) - fmt.Printf("\tRows in gold_7_active_od_rewards: %v - [time: %v]\n", rows, time.Since(testStart)) + if rewardsV2Enabled { + rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_7_ActiveODRewards]) + assert.Nil(t, err) + fmt.Printf("\tRows in gold_7_active_od_rewards: %v - [time: %v]\n", rows, time.Since(testStart)) + } testStart = time.Now() fmt.Printf("Running gold_8_operator_od_reward_amounts\n") err = rc.GenerateGold8OperatorODRewardAmountsTable(snapshotDate) assert.Nil(t, err) - rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_8_OperatorODRewardAmounts]) - assert.Nil(t, err) - fmt.Printf("\tRows in gold_8_operator_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + if rewardsV2Enabled { + rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_8_OperatorODRewardAmounts]) + assert.Nil(t, err) + fmt.Printf("\tRows in gold_8_operator_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + } testStart = time.Now() fmt.Printf("Running gold_9_staker_od_reward_amounts\n") err = rc.GenerateGold9StakerODRewardAmountsTable(snapshotDate) assert.Nil(t, err) - rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_9_StakerODRewardAmounts]) - assert.Nil(t, err) - fmt.Printf("\tRows in gold_9_staker_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + if rewardsV2Enabled { + rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_9_StakerODRewardAmounts]) + assert.Nil(t, err) + fmt.Printf("\tRows in gold_9_staker_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + } testStart = time.Now() fmt.Printf("Running gold_10_avs_od_reward_amounts\n") err = rc.GenerateGold10AvsODRewardAmountsTable(snapshotDate) assert.Nil(t, err) - rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_10_AvsODRewardAmounts]) - assert.Nil(t, err) - fmt.Printf("\tRows in gold_10_avs_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + if rewardsV2Enabled { + rows, err = getRowCountForTable(grm, goldTableNames[rewardsUtils.Table_10_AvsODRewardAmounts]) + assert.Nil(t, err) + fmt.Printf("\tRows in gold_10_avs_od_reward_amounts: %v - [time: %v]\n", rows, time.Since(testStart)) + } testStart = time.Now() fmt.Printf("Running gold_11_staging\n") diff --git a/pkg/rewards/stakerDelegationSnapshots.go b/pkg/rewards/stakerDelegationSnapshots.go index 58edc9ad..117d2018 100644 --- a/pkg/rewards/stakerDelegationSnapshots.go +++ b/pkg/rewards/stakerDelegationSnapshots.go @@ -62,7 +62,7 @@ select * from final_results func (r *RewardsCalculator) GenerateAndInsertStakerDelegationSnapshots(snapshotDate string) error { tableName := "staker_delegation_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(stakerDelegationSnapshotsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(stakerDelegationSnapshotsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/stakerOperators/1_stakerStrategyPayouts.go b/pkg/rewards/stakerOperators/1_stakerStrategyPayouts.go index 88bda541..6ad5dbcc 100644 --- a/pkg/rewards/stakerOperators/1_stakerStrategyPayouts.go +++ b/pkg/rewards/stakerOperators/1_stakerStrategyPayouts.go @@ -128,7 +128,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert1StakerStrategyPayouts(cut tableName := "sot_1_staker_strategy_payouts" allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) - query, err := rewardsUtils.RenderQueryTemplate(_1_stakerStrategyPayoutsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_1_stakerStrategyPayoutsQuery, map[string]interface{}{ "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], "stakerRewardAmountsTable": allTableNames[rewardsUtils.Table_2_StakerRewardAmounts], }) diff --git a/pkg/rewards/stakerOperators/2_operatorStrategyRewards.go b/pkg/rewards/stakerOperators/2_operatorStrategyRewards.go index 0a0824b6..d9fa1d15 100644 --- a/pkg/rewards/stakerOperators/2_operatorStrategyRewards.go +++ b/pkg/rewards/stakerOperators/2_operatorStrategyRewards.go @@ -112,7 +112,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert2OperatorStrategyRewards(c tableName := "sot_2_operator_strategy_rewards" allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) - query, err := rewardsUtils.RenderQueryTemplate(_2_operatorStrategyRewardsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_2_operatorStrategyRewardsQuery, map[string]interface{}{ "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], "operatorRewardAmountsTable": allTableNames[rewardsUtils.Table_3_OperatorRewardAmounts], }) diff --git a/pkg/rewards/stakerOperators/3_rewardsForAllStrategyPayouts.go b/pkg/rewards/stakerOperators/3_rewardsForAllStrategyPayouts.go index 4c95ad7b..082dd1eb 100644 --- a/pkg/rewards/stakerOperators/3_rewardsForAllStrategyPayouts.go +++ b/pkg/rewards/stakerOperators/3_rewardsForAllStrategyPayouts.go @@ -102,7 +102,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert3RewardsForAllStrategyPayo tableName := "sot_3_rewards_for_all_strategy_payout" allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) - query, err := rewardsUtils.RenderQueryTemplate(_3_rewardsForAllStrategyPayoutsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_3_rewardsForAllStrategyPayoutsQuery, map[string]interface{}{ "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], "rewardsForAllTable": allTableNames[rewardsUtils.Table_4_RewardsForAll], }) diff --git a/pkg/rewards/stakerOperators/4_rfaeStakerStrategyPayouts.go b/pkg/rewards/stakerOperators/4_rfaeStakerStrategyPayouts.go index dfb1f71b..4968c0a1 100644 --- a/pkg/rewards/stakerOperators/4_rfaeStakerStrategyPayouts.go +++ b/pkg/rewards/stakerOperators/4_rfaeStakerStrategyPayouts.go @@ -134,7 +134,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert4RfaeStakerStrategyPayout( tableName := "sot_4_rfae_staker_strategy_payout" allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) - query, err := rewardsUtils.RenderQueryTemplate(_4_rfaeStakerStrategyPayoutsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_4_rfaeStakerStrategyPayoutsQuery, map[string]interface{}{ "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], "rfaeStakerTable": allTableNames[rewardsUtils.Table_5_RfaeStakers], }) diff --git a/pkg/rewards/stakerOperators/5_rfaeOperatorStrategyPayout.go b/pkg/rewards/stakerOperators/5_rfaeOperatorStrategyPayout.go index 7a532572..a0d35ce3 100644 --- a/pkg/rewards/stakerOperators/5_rfaeOperatorStrategyPayout.go +++ b/pkg/rewards/stakerOperators/5_rfaeOperatorStrategyPayout.go @@ -123,7 +123,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert5RfaeOperatorStrategyPayou tableName := "sot_5_rfae_operator_strategy_payout" allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) - query, err := rewardsUtils.RenderQueryTemplate(_5_rfaeOperatorStrategyPayoutsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_5_rfaeOperatorStrategyPayoutsQuery, map[string]interface{}{ "activeRewardsTable": allTableNames[rewardsUtils.Table_1_ActiveRewards], "rfaeOperatorTable": allTableNames[rewardsUtils.Table_6_RfaeOperators], }) diff --git a/pkg/rewards/stakerOperators/6_stakerOperatorStaging.go b/pkg/rewards/stakerOperators/6_stakerOperatorStaging.go index 151c6021..514f98eb 100644 --- a/pkg/rewards/stakerOperators/6_stakerOperatorStaging.go +++ b/pkg/rewards/stakerOperators/6_stakerOperatorStaging.go @@ -113,7 +113,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert6StakerOperatorStaging(cut zap.String("cutoffDate", cutoffDate), ) - query, err := rewardsUtils.RenderQueryTemplate(_6_stakerOperatorsStaging, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_6_stakerOperatorsStaging, map[string]interface{}{ "destTableName": destTableName, }) if err != nil { diff --git a/pkg/rewards/stakerOperators/7_stakerOperator.go b/pkg/rewards/stakerOperators/7_stakerOperator.go index 8d54d54d..2f5bb9f6 100644 --- a/pkg/rewards/stakerOperators/7_stakerOperator.go +++ b/pkg/rewards/stakerOperators/7_stakerOperator.go @@ -62,7 +62,7 @@ func (sog *StakerOperatorsGenerator) GenerateAndInsert7StakerOperator(cutoffDate zap.String("cutoffDate", cutoffDate), ) - query, err := rewardsUtils.RenderQueryTemplate(_7_stakerOperator, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(_7_stakerOperator, map[string]interface{}{ "destTableName": destTableName, "stakerOperatorStaging": allTableNames[rewardsUtils.Sot_6_StakerOperatorStaging], }) diff --git a/pkg/rewards/stakerShareSnapshots.go b/pkg/rewards/stakerShareSnapshots.go index f2a2640c..1fdace1b 100644 --- a/pkg/rewards/stakerShareSnapshots.go +++ b/pkg/rewards/stakerShareSnapshots.go @@ -50,7 +50,7 @@ CROSS JOIN func (r *RewardsCalculator) GenerateAndInsertStakerShareSnapshots(snapshotDate string) error { tableName := "staker_share_snapshots" - query, err := rewardsUtils.RenderQueryTemplate(stakerShareSnapshotsQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(stakerShareSnapshotsQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewards/stakerShares.go b/pkg/rewards/stakerShares.go index 66fda671..a8b16171 100644 --- a/pkg/rewards/stakerShares.go +++ b/pkg/rewards/stakerShares.go @@ -21,7 +21,7 @@ const stakerSharesQuery = ` func (r *RewardsCalculator) GenerateAndInsertStakerShares(snapshotDate string) error { tableName := "staker_shares" - query, err := rewardsUtils.RenderQueryTemplate(stakerSharesQuery, map[string]string{ + query, err := rewardsUtils.RenderQueryTemplate(stakerSharesQuery, map[string]interface{}{ "cutoffDate": snapshotDate, }) if err != nil { diff --git a/pkg/rewardsUtils/rewardsUtils.go b/pkg/rewardsUtils/rewardsUtils.go index 10ab3b6e..5d5ac980 100644 --- a/pkg/rewardsUtils/rewardsUtils.go +++ b/pkg/rewardsUtils/rewardsUtils.go @@ -54,7 +54,7 @@ func GetGoldTableNames(snapshotDate string) map[string]string { return tableNames } -func RenderQueryTemplate(query string, variables map[string]string) (string, error) { +func RenderQueryTemplate(query string, variables map[string]interface{}) (string, error) { queryTmpl := template.Must(template.New("").Parse(query)) var dest bytes.Buffer