Skip to content

Commit c144990

Browse files
committed
clean
1 parent 4da32d9 commit c144990

File tree

9 files changed

+26
-376
lines changed

9 files changed

+26
-376
lines changed

internal/config/config.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ type RewardsConfig struct {
105105
ValidateRewardsRoot bool
106106
GenerateStakerOperatorsTable bool
107107
CalculateRewardsDaily bool
108-
WithdrawalQueueWindow float64 // Duration in days for withdrawal queue period (14.0 for mainnet, 0.0069 for testnet/preprod ~10 min)
109108
RewardsV2_2Enabled bool
110109
}
111110

@@ -215,7 +214,6 @@ var (
215214
RewardsValidateRewardsRoot = "rewards.validate_rewards_root"
216215
RewardsGenerateStakerOperatorsTable = "rewards.generate_staker_operators_table"
217216
RewardsCalculateRewardsDaily = "rewards.calculate_rewards_daily"
218-
RewardsWithdrawalQueueWindow = "rewards.withdrawal_queue_window"
219217
RewardsV2_2Enabled = "rewards.v2_2_enabled"
220218

221219
EthereumRpcBaseUrl = "ethereum.rpc_url"
@@ -251,18 +249,6 @@ var (
251249
CoingeckoApiKey = "coingecko.api-key"
252250
)
253251

254-
// getDefaultWithdrawalQueueDuration returns the default withdrawal queue duration in days based on chain
255-
func getDefaultWithdrawalQueueDuration(chain Chain) float64 {
256-
switch chain {
257-
case Chain_Mainnet:
258-
return 14.0 // Mainnet uses 14-day withdrawal queue
259-
case Chain_Preprod, Chain_Holesky, Chain_Sepolia, Chain_Hoodi, Chain_PreprodHoodi:
260-
return 10.0 / (24.0 * 60.0) // Testnet/preprod uses 10 minutes = ~0.0069 days
261-
default:
262-
return 14.0 // Default to mainnet behavior
263-
}
264-
}
265-
266252
func FloatWithDefault(value, defaultValue float64) float64 {
267253
if value == 0.0 {
268254
return defaultValue
@@ -271,11 +257,9 @@ func FloatWithDefault(value, defaultValue float64) float64 {
271257
}
272258

273259
func NewConfig() *Config {
274-
chain := Chain(StringWithDefault(viper.GetString(normalizeFlagName("chain")), "holesky"))
275-
276260
return &Config{
277261
Debug: viper.GetBool(normalizeFlagName("debug")),
278-
Chain: chain,
262+
Chain: Chain(StringWithDefault(viper.GetString(normalizeFlagName("chain")), "holesky")),
279263

280264
EthereumRpcConfig: EthereumRpcConfig{
281265
BaseUrl: viper.GetString(normalizeFlagName(EthereumRpcBaseUrl)),
@@ -323,7 +307,6 @@ func NewConfig() *Config {
323307
ValidateRewardsRoot: viper.GetBool(normalizeFlagName(RewardsValidateRewardsRoot)),
324308
GenerateStakerOperatorsTable: viper.GetBool(normalizeFlagName(RewardsGenerateStakerOperatorsTable)),
325309
CalculateRewardsDaily: viper.GetBool(normalizeFlagName(RewardsCalculateRewardsDaily)),
326-
WithdrawalQueueWindow: FloatWithDefault(viper.GetFloat64(normalizeFlagName(RewardsWithdrawalQueueWindow)), getDefaultWithdrawalQueueDuration(chain)),
327310
RewardsV2_2Enabled: viper.GetBool(normalizeFlagName(RewardsV2_2Enabled)),
328311
},
329312

pkg/postgres/migrations/202512150000_operatorAllocationSnapshotsTable/up.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ type Migration struct{}
1212
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
1313
queries := []string{
1414
// Create operator_allocation_snapshots table for unique stake calculations
15-
// Stores daily snapshots of operator allocations (magnitude) per operator set
15+
// Stores daily snapshots of operator allocations (magnitude and max_magnitude) per operator set
1616
`CREATE TABLE IF NOT EXISTS operator_allocation_snapshots (
1717
operator varchar not null,
1818
avs varchar not null,
1919
strategy varchar not null,
2020
operator_set_id bigint not null,
2121
magnitude numeric not null,
22+
max_magnitude numeric not null default 0,
2223
snapshot date not null,
2324
primary key (operator, avs, strategy, operator_set_id, snapshot)
2425
)`,
@@ -30,6 +31,11 @@ func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
3031
// Index for efficient allocation queries
3132
`CREATE INDEX IF NOT EXISTS idx_operator_allocations_effective_date
3233
ON operator_allocations(operator, avs, strategy, operator_set_id, effective_date)`,
34+
35+
// Create index for max_magnitude queries for performance
36+
`CREATE INDEX IF NOT EXISTS idx_operator_allocation_snapshots_max_magnitude
37+
ON operator_allocation_snapshots(operator, strategy, snapshot)
38+
WHERE max_magnitude > 0`,
3339
}
3440

3541
for _, query := range queries {

pkg/postgres/migrations/202512160000_addSlashableUntilToOperatorRegistrationSnapshots/up.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

pkg/postgres/migrations/202512161200_addMaxMagnitudeToAllocationSnapshots/up.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

pkg/postgres/migrations/migrator.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ import (
8383
_202507301421_crossChainRegistryTables "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202507301421_crossChainRegistryTables"
8484
_202511051502_keyRotationScheduled "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202511051502_keyRotationScheduled"
8585
_202512150000_operatorAllocationSnapshotsTable "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202512150000_operatorAllocationSnapshotsTable"
86-
_202512160000_addSlashableUntilToOperatorRegistrationSnapshots "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202512160000_addSlashableUntilToOperatorRegistrationSnapshots"
87-
_202512161200_addMaxMagnitudeToAllocationSnapshots "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202512161200_addMaxMagnitudeToAllocationSnapshots"
8886
_202601260000_uniqueAndTotalStakeRewardSubmissions "github.com/Layr-Labs/sidecar/pkg/postgres/migrations/202601260000_uniqueAndTotalStakeRewardSubmissions"
8987
)
9088

@@ -231,8 +229,6 @@ func (m *Migrator) MigrateAll() error {
231229
&_202507301346_taskMailboxTables.Migration{},
232230
&_202511051502_keyRotationScheduled.Migration{},
233231
&_202512150000_operatorAllocationSnapshotsTable.Migration{},
234-
&_202512160000_addSlashableUntilToOperatorRegistrationSnapshots.Migration{},
235-
&_202512161200_addMaxMagnitudeToAllocationSnapshots.Migration{},
236232
&_202601260000_uniqueAndTotalStakeRewardSubmissions.Migration{},
237233
}
238234

pkg/rewards/operatorSetOperatorRegistrationSnapshots.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// Entry Exit
2121
// Since exits (deregistrations) are rounded down, we must only look at the day 2 snapshot on a pipeline run on day 3.
2222
const operatorSetOperatorRegistrationSnapshotsQuery = `
23-
insert into operator_set_operator_registration_snapshots (operator, avs, operator_set_id, snapshot, slashable_until)
23+
insert into operator_set_operator_registration_snapshots (operator, avs, operator_set_id, snapshot)
2424
WITH state_changes as (
2525
select
2626
osor.*,
@@ -74,26 +74,7 @@ marked_statuses AS (
7474
block_time AS start_time,
7575
-- Mark the next_block_time as the end_time for the range
7676
-- Use coalesce because if the next_block_time for a registration is not closed, then we use cutoff_date
77-
COALESCE(next_block_time, '{{.cutoffDate}}')::timestamp AS end_time,
78-
-- Calculate slashable_until based on deregistration
79-
-- Deregistrations: slashability queue for unique stake rewards
80-
-- NULL = still active (no deregistration)
81-
--
82-
-- NOTE: Design Decision - Time vs Blocks
83-
-- - Sidecar uses TIME: adds configurable days (14 days on mainnet, ~10 minutes on testnets)
84-
-- - Contracts use BLOCKS: adds ~100,800 blocks (14 days * 24 * 60 * 60 / 12 sec/block)
85-
-- - This matches withdrawal queue behavior (stakerShareSnapshots.go:63)
86-
-- - Time is continuous; blocks can be missed on-chain (acceptable edge case)
87-
-- - Daily snapshot granularity makes minute-level precision differences insignificant
88-
CASE
89-
WHEN next_is_active = FALSE THEN
90-
-- Deregistration with slashability period (environment-specific)
91-
DATE(COALESCE(next_block_time, '{{.cutoffDate}}')::timestamp) + ({{.withdrawalQueueWindow}} * INTERVAL '1 day')
92-
WHEN next_is_active IS NULL THEN
93-
-- Still active (no deregistration event): NULL
94-
NULL
95-
END AS slashable_until_date,
96-
is_active
77+
COALESCE(next_block_time, '{{.cutoffDate}}')::timestamp AS end_time
9778
FROM removed_same_day_deregistrations
9879
WHERE is_active = TRUE
9980
),
@@ -105,8 +86,7 @@ registration_windows_extra as (
10586
operator_set_id,
10687
date_trunc('day', start_time) + interval '1' day as start_time,
10788
-- End time is non-inclusive because the operator is not registered to the operator set at the end time OR it is current timestamp rounded down
108-
date_trunc('day', end_time) as end_time,
109-
slashable_until_date
89+
date_trunc('day', end_time) as end_time
11090
FROM registration_periods
11191
),
11292
-- Ignore start_time and end_time that last less than a day
@@ -122,18 +102,15 @@ SELECT
122102
operator,
123103
avs,
124104
operator_set_id,
125-
d AS snapshot,
126-
slashable_until_date AS slashable_until
105+
d AS snapshot
127106
FROM cleaned_records
128107
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
129-
on conflict on constraint uniq_operator_set_operator_registration_snapshots
130-
DO UPDATE SET slashable_until = EXCLUDED.slashable_until;
108+
on conflict on constraint uniq_operator_set_operator_registration_snapshots do nothing;
131109
`
132110

133111
func (r *RewardsCalculator) GenerateAndInsertOperatorSetOperatorRegistrationSnapshots(snapshotDate string) error {
134112
query, err := rewardsUtils.RenderQueryTemplate(operatorSetOperatorRegistrationSnapshotsQuery, map[string]interface{}{
135-
"cutoffDate": snapshotDate,
136-
"withdrawalQueueWindow": r.globalConfig.Rewards.WithdrawalQueueWindow,
113+
"cutoffDate": snapshotDate,
137114
})
138115
if err != nil {
139116
r.logger.Sugar().Errorw("Failed to render operator set operator registration snapshots query", "error", err)

0 commit comments

Comments
 (0)