Correct reward denominator in op pool (#5047)

Closes #5016


  The op pool was using the wrong denominator when calculating proposer block rewards! This was mostly inconsequential as our studies of Lighthouse's block profitability already showed that it is very close to optimal. The wrong denominator was leftover from phase0 code, and wasn't properly updated for Altair.
This commit is contained in:
Michael Sproul
2025-05-20 11:06:40 +10:00
committed by GitHub
parent af87135e30
commit 805c2dc831
3 changed files with 29 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::lighthouse::{AttestationRewards, BlockReward, BlockRewardMeta};
use operation_pool::{AttMaxCover, MaxCover, RewardCache, SplitAttestation};
use operation_pool::{
AttMaxCover, MaxCover, RewardCache, SplitAttestation, PROPOSER_REWARD_DENOMINATOR,
};
use state_processing::{
common::get_attesting_indices_from_state,
per_block_processing::altair::sync_committee::compute_sync_aggregate_rewards,
@@ -65,13 +67,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut curr_epoch_total = 0;
for cover in &per_attestation_rewards {
for &reward in cover.fresh_validators_rewards.values() {
if cover.att.data.slot.epoch(T::EthSpec::slots_per_epoch()) == state.current_epoch()
{
curr_epoch_total += reward;
} else {
prev_epoch_total += reward;
}
if cover.att.data.slot.epoch(T::EthSpec::slots_per_epoch()) == state.current_epoch() {
curr_epoch_total += cover.score() as u64;
} else {
prev_epoch_total += cover.score() as u64;
}
}
@@ -80,7 +79,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Drop the covers.
let per_attestation_rewards = per_attestation_rewards
.into_iter()
.map(|cover| cover.fresh_validators_rewards)
.map(|cover| {
// Divide each reward numerator by the denominator. This can lead to the total being
// less than the sum of the individual rewards due to the fact that integer division
// does not distribute over addition.
let mut rewards = cover.fresh_validators_rewards;
rewards
.values_mut()
.for_each(|reward| *reward /= PROPOSER_REWARD_DENOMINATOR);
rewards
})
.collect();
// Add the attestation data if desired.