Skip to content

Commit 11b9e55

Browse files
committed
add operator_set_id
1 parent 44ed5f7 commit 11b9e55

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

pkg/postgres/migrations/202511141700_withdrawalQueueAndAllocationRounding/up.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,23 @@ type Migration struct {
1313
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
1414
queries := []string{
1515
// =============================================================================
16-
// PART 1: Enhance queued_slashing_withdrawals to support withdrawal queue
16+
// PART 1: Withdrawal queue - no schema changes needed
1717
// =============================================================================
18-
19-
// Add completion tracking (timestamps can be derived from blocks table via FK)
20-
`alter table queued_slashing_withdrawals add column if not exists completed boolean default false`,
21-
`alter table queued_slashing_withdrawals add column if not exists completion_block_number bigint`,
22-
23-
// Add FK constraint for completion block
24-
`alter table queued_slashing_withdrawals add constraint fk_completion_block foreign key (completion_block_number) references blocks(number) on delete set null`,
25-
26-
// =============================================================================
27-
// PART 2: Create indexes for efficient withdrawal queue queries
28-
// =============================================================================
29-
30-
// Index for finding active (non-completed) withdrawals
31-
`create index if not exists idx_queued_withdrawals_active on queued_slashing_withdrawals(staker, operator, completed) where completed = false`,
32-
33-
// Index for completion queries
34-
`create index if not exists idx_queued_withdrawals_completed on queued_slashing_withdrawals(completion_block_number) where completed = true`,
18+
// Note: Withdrawal queue logic uses withdrawable_date to determine when
19+
// shares should stop earning rewards. No completion tracking needed for
20+
// rewards calculation as withdrawable_date is derived from queued_date + 14 days.
3521

3622
// =============================================================================
37-
// PART 3: Update operator_allocations table for rounding logic
23+
// PART 2: Update operator_allocations table for rounding logic
3824
// =============================================================================
3925

4026
// Add effective_date column for allocation/deallocation rounding
4127
// This is a computed value based on magnitude changes (round UP for increases, DOWN for decreases)
4228
// block_timestamp can be derived from block_number FK to blocks table
4329
`alter table operator_allocations add column if not exists effective_date date`,
4430

45-
// Create index for effective_date queries
46-
`create index if not exists idx_operator_allocations_effective_date on operator_allocations(operator, avs, strategy, effective_date)`,
31+
// Create index for effective_date queries (includes operator_set_id for proper partitioning)
32+
`create index if not exists idx_operator_allocations_effective_date on operator_allocations(operator, avs, strategy, operator_set_id, effective_date)`,
4733
}
4834

4935
for _, query := range queries {

pkg/rewards/deallocationQueueShareSnapshots.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,29 @@ import (
2525
// NOTE: This handles DECREASES (deallocations). Increases (allocations) are simpler
2626
// because they round UP, so they naturally start earning on effective_date.
2727
const deallocationQueueShareSnapshotsQuery = `
28+
insert into deallocation_queue_snapshots(
29+
operator,
30+
avs,
31+
operator_set_id,
32+
strategy,
33+
magnitude_decrease,
34+
block_date,
35+
effective_date,
36+
snapshot
37+
)
2838
with deallocation_adjustments as (
2939
select
3040
oa.operator,
3141
oa.avs,
42+
oa.operator_set_id,
3243
oa.strategy,
3344
oa.magnitude as new_magnitude,
3445
oa.effective_date,
3546
date(b.block_time) as block_date,
3647
oa.block_number,
3748
-- Get previous allocation to calculate the difference
3849
lag(oa.magnitude) over (
39-
partition by oa.operator, oa.avs, oa.strategy
50+
partition by oa.operator, oa.avs, oa.operator_set_id, oa.strategy
4051
order by oa.block_number, oa.log_index
4152
) as prev_magnitude
4253
from operator_allocations oa
@@ -52,6 +63,7 @@ const deallocationQueueShareSnapshotsQuery = `
5263
select
5364
operator,
5465
avs,
66+
operator_set_id,
5567
strategy,
5668
new_magnitude,
5769
prev_magnitude,
@@ -64,18 +76,10 @@ const deallocationQueueShareSnapshotsQuery = `
6476
prev_magnitude is not null
6577
and new_magnitude::numeric < prev_magnitude::numeric
6678
)
67-
insert into deallocation_queue_snapshots(
68-
operator,
69-
avs,
70-
strategy,
71-
magnitude_decrease,
72-
block_date,
73-
effective_date,
74-
snapshot
75-
)
7679
select
7780
operator,
7881
avs,
82+
operator_set_id,
7983
strategy,
8084
magnitude_decrease,
8185
block_date,
@@ -88,6 +92,7 @@ const deallocationQueueShareSnapshotsQuery = `
8892
type DeallocationQueueSnapshot struct {
8993
Operator string `gorm:"column:operator;primaryKey"`
9094
Avs string `gorm:"column:avs;primaryKey"`
95+
OperatorSetId string `gorm:"column:operator_set_id;primaryKey"`
9196
Strategy string `gorm:"column:strategy;primaryKey"`
9297
MagnitudeDecrease string `gorm:"column:magnitude_decrease"`
9398
BlockDate string `gorm:"column:block_date"`

0 commit comments

Comments
 (0)