Skip to content

Fix: Use NextState.ConsolidatedAmounts instead of CurrentState in EpochReward#218

Closed
kamoallebabot-blip wants to merge 1 commit into
migalabs:masterfrom
kamoallebabot-blip:fix/electra-consolidated-amounts
Closed

Fix: Use NextState.ConsolidatedAmounts instead of CurrentState in EpochReward#218
kamoallebabot-blip wants to merge 1 commit into
migalabs:masterfrom
kamoallebabot-blip:fix/electra-consolidated-amounts

Conversation

@kamoallebabot-blip
Copy link
Copy Markdown

Fixes #215

Problem

Validators that are targets of consolidations (post-Electra) have their f_reward values inflated by exactly the consolidated amount (~32 ETH) due to incorrect timing when subtracting ConsolidatedAmounts from the epoch reward calculation.

Root Cause

The EpochReward() function in pkg/spec/metrics/standard.go was using CurrentState.ConsolidatedAmounts instead of NextState.ConsolidatedAmounts. This caused the subtraction to fail because the consolidated amount is only available in NextState during consolidation events.

The Fix

Changed line 31 in pkg/spec/metrics/standard.go from:

consolidatedAmount, ok := p.CurrentState.ConsolidatedAmounts[valIdx]

To:

consolidatedAmount, ok := p.NextState.ConsolidatedAmounts[valIdx]

This aligns with how Deposits are handled (line 42 uses p.NextState.Deposits).

Impact

  • Fixes inflated f_reward values for validators receiving consolidations
  • Resolves cascading errors in pool summaries and APR calculations
  • Allows proper historical data cleanup for epochs >= 411389 (post-Electra)

Testing

The fix resolves the symptoms where validators show f_reward >> f_max_reward for consolidated amounts, bringing f_reward back to expected ranges.

…chReward

Fixes migalabs#215

## Problem
Validators that are targets of consolidations (post-Electra) have their
f_reward values inflated by exactly the consolidated amount (~32 ETH) due to
incorrect timing when subtracting ConsolidatedAmounts from the epoch reward
calculation.

## Root Cause
EpochReward() function was using CurrentState.ConsolidatedAmounts which
doesn't contain the consolidated amount until NextState. This caused the
subtraction to fail and resulted in inflated f_reward values.

## Solution
Changed line 31 in pkg/spec/metrics/standard.go to use NextState.ConsolidatedAmounts
instead of CurrentState.ConsolidatedAmounts, aligning with how Deposits are
handled on line 42.

Before fix:
  consolidatedAmount, ok := p.CurrentState.ConsolidatedAmounts[valIdx]

After fix:
  consolidatedAmount, ok := p.NextState.ConsolidatedAmounts[valIdx]

This ensures consolidated amounts are properly subtracted from the reward
calculation for target validators.

## Testing
The fix resolves the symptoms where validators show f_reward >> f_max_reward
for consolidated amounts, bringing f_reward back to expected ranges.
@Zyra-V21
Copy link
Copy Markdown
Collaborator

Zyra-V21 commented Apr 7, 2026

Hi @kamoallebabot-blip, thanks for taking the time to dig into this and propose a fix!

Closing this PR because the proposed change was actually tried earlier and reverted after we found it introduces a different bug. Quick history so the rationale is documented:

  1. Jan 22, 2026 — commit eba4883 made exactly this change (CurrentStateNextState.ConsolidatedAmounts) for the same issue f_reward Inflated by Consolidated Amounts (Post-Electra Validators) #215.
  2. Jan 31, 2026 — commit ab95a42 reverted it. NextState.ConsolidatedAmounts actually contains consolidations queued for the next epoch transition, which haven't been applied to NextState.Balances yet — so subtracting them produces incorrect (often very negative) rewards. Verified locally with validator 2170445 at epoch 424365: the NextState version produced -64 ETH; reverting back to CurrentState produced the expected ~9k gwei.
  3. The real fix was on the other side of the pipeline: CurrentState.ConsolidatedAmounts was empty because processPendingConsolidations was only being called on NextState. ab95a42 added a call for CurrentState in PreProcessBundle (pkg/spec/metrics/state_electra.go), which is what populates the map the EpochReward formula reads.
  4. Several follow-up commits on dev (5461500, 4d43cdd, 0daa8dc, …) further refined the consolidation accounting (source-side ConsolidatedOutAmounts, deposit handling, bounds checks). The current state of pkg/spec/metrics/standard.go on dev already handles the consolidation-target case correctly.

So the symptom you saw is real, but the one-line change here would re-introduce the negative-reward bug. If you spot a case where consolidation-target rewards are still off on dev, please open an issue with the validator index + epoch and we'll take another look — that kind of repro is genuinely useful.

Thanks again for the contribution!

@Zyra-V21 Zyra-V21 closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

f_reward Inflated by Consolidated Amounts (Post-Electra Validators)

2 participants