-
Notifications
You must be signed in to change notification settings - Fork 3
perf: combine rewards tables by removing snapshot date suffix #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
83d6e1d to
3d9eb27
Compare
9f42954 to
1335f78
Compare
1335f78 to
7527e61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: SQL Template Syntax Error
The DeleteCorruptedRewardsFromBlockHeight function incorrectly uses Go template syntax {{.generatedRewardsSnapshotId}} within raw SQL query strings. These queries are then executed with sql.Named parameters, which expect SQL placeholder syntax (e.g., @generatedRewardsSnapshotId). This mismatch results in literal {{.generatedRewardsSnapshotId}} text in the executed SQL, causing syntax errors. The correct approach is to use @generatedRewardsSnapshotId for SQL named parameters or properly render the string as a template.
Additionally, if no previous snapshot is found (i.e., gorm.ErrRecordNotFound for previousSnapshot), the previousSnapshot variable remains nil, leading to a panic when previousSnapshot.Id is subsequently accessed.
pkg/rewards/rewards.go#L410-L431
sidecar/pkg/rewards/rewards.go
Lines 410 to 431 in 7527e61
| for _, tableName := range rewardsUtils.RewardsTableBaseNames { | |
| rc.logger.Sugar().Infow("Deleting rows from rewards table", "tableName", tableName) | |
| dropQuery := fmt.Sprintf("delete from %s where generated_rewards_snapshot_id >= {{.generatedRewardsSnapshotId}}", tableName) | |
| res := rc.grm.Exec(dropQuery, sql.Named("generatedRewardsSnapshotId", previousSnapshot.Id)) | |
| if res.Error != nil { | |
| rc.logger.Sugar().Errorw("Failed to delete rows from rewards table", "error", res.Error, "tableName", tableName) | |
| return res.Error | |
| } | |
| rc.logger.Sugar().Infow("Deleted rows from rewards table", | |
| "tableName", tableName, | |
| "recordsDeleted", res.RowsAffected) | |
| } | |
| // Also delete from generated_rewards_snapshots table | |
| res = rc.grm.Exec("delete from generated_rewards_snapshots where id >= {{.generatedRewardsSnapshotId}}", | |
| sql.Named("generatedRewardsSnapshotId", previousSnapshot.Id)) | |
| if res.Error != nil { | |
| rc.logger.Sugar().Errorw("Failed to delete from generated_rewards_snapshots", "error", res.Error) | |
| return res.Error | |
| } | |
| return nil |
Bug: Incorrect Table Pattern Causes Migration Failure
The ExistingTablePattern for the rewards_gold_10_avs_od_reward_amounts sub-migration is incorrectly set to gold_[0-9]+_staker_avs_od_reward_amounts_[0-9_]+$. The pattern includes an erroneous "staker_" prefix and should be gold_[0-9]+_avs_od_reward_amounts_[0-9_]+$. This prevents the migration from finding and processing the correct existing avs_od_reward_amounts tables.
pkg/postgres/migrations/202505301218_migrateRewardsTables/up.go#L354-L355
sidecar/pkg/postgres/migrations/202505301218_migrateRewardsTables/up.go
Lines 354 to 355 in 7527e61
| NewTableName: "rewards_gold_10_avs_od_reward_amounts", | |
| ExistingTablePattern: "gold_[0-9]+_staker_avs_od_reward_amounts_[0-9_]+$", |
Was this report helpful? Give feedback by reacting with 👍 or 👎
6e92d01 to
d49be48
Compare
58ba633 to
c6cb895
Compare
improve migration add back function fix
6ba2306 to
7e6ac5b
Compare
Description
Remove suffix of gold tables and add
generated_rewards_snapshot_idcolumn. This will prune gold tables and improve on table sizes.Fixes #403
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: