Skip to content

Commit

Permalink
feat(update-validator-rewards): less tip double counting
Browse files Browse the repository at this point in the history
MEV rewards and tips overlap. We weight them by how often each is paid
and calculate from there.
  • Loading branch information
alextes committed Dec 3, 2024
1 parent be6989f commit 8c2a4ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/bin/update-validator-rewards/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ async fn get_tips_since_london<'a>(pool: impl PgExecutor<'a>) -> sqlx::Result<Gw
.map(|row| GweiNewtype(row.tips_since_london.round() as i64))
}

async fn get_tips_reward<'a>(
// Tips and MEV rewards overlap. Whenever a validator is paid MEV rewards they are not paid
// tips, or rather they are included in the MEV bid already. We estimate roughly 90% of slots are
// handled by mev blocks. Therefore we estimate only 10% of tips paid on-chain are tips earned by
// validators.
const TIPS_REWARD_FACTOR: f64 = 0.1;

async fn calc_tips_reward<'a>(
executor: impl PgExecutor<'a>,
effective_balance_sum: GweiNewtype,
) -> sqlx::Result<ValidatorReward> {
let GweiNewtype(tips_since_london) = get_tips_since_london(executor).await?;
debug!("tips since london {}", tips_since_london);

let tips_per_year = tips_since_london as f64 / get_days_since_london() as f64 * 365.25;
let tips_per_year =
tips_since_london as f64 / get_days_since_london() as f64 * 365.25 * TIPS_REWARD_FACTOR;
let single_validator_share =
(32_f64 * EthNewtype::GWEI_PER_ETH as f64) / effective_balance_sum.0 as f64;
debug!("single validator share {}", tips_since_london);
Expand Down Expand Up @@ -81,7 +88,7 @@ const EPOCHS_PER_YEAR: f64 = 365.25 * EPOCHS_PER_DAY;
const BASE_REWARD_FACTOR: u8 = 64;

// Consider staying in Gwei until the last moment instead of converting early.
pub fn get_issuance_reward(GweiNewtype(effective_balance_sum): GweiNewtype) -> ValidatorReward {
pub fn calc_issuance_reward(GweiNewtype(effective_balance_sum): GweiNewtype) -> ValidatorReward {
let active_validators = effective_balance_sum as f64 / GWEI_PER_ETH_F64 / 32f64;

// Balance at stake (Gwei)
Expand Down Expand Up @@ -126,11 +133,11 @@ struct ValidatorRewards {
async fn get_validator_rewards(db_pool: &PgPool, beacon_node: &BeaconNodeHttp) -> ValidatorRewards {
let last_effective_balance_sum =
balances::get_last_effective_balance_sum(db_pool, beacon_node).await;
let issuance_reward = get_issuance_reward(last_effective_balance_sum);
let tips_reward = get_tips_reward(db_pool, last_effective_balance_sum)
let issuance_reward = calc_issuance_reward(last_effective_balance_sum);
let tips_reward = calc_tips_reward(db_pool, last_effective_balance_sum)
.await
.unwrap();
let mev = mev_blocks::get_mev_reward(db_pool, last_effective_balance_sum)
let mev = mev_blocks::calc_mev_reward(db_pool, last_effective_balance_sum)
.await
.unwrap();

Expand Down
8 changes: 6 additions & 2 deletions src/bin/update-validator-rewards/mev_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ pub async fn sync_mev_blocks(
info!(start_slot, "no more blocks to process");
}

pub async fn get_mev_reward(
// MEV rewards include tips, in order to avoid double counting we estimate 90% of slots use
// mev-boost and therefore only 90% of slots see the average MEV bid paid out to them.
const MEV_REWARD_FACTOR: f64 = 0.9;

pub async fn calc_mev_reward(
executor: impl PgExecutor<'_>,
effective_balance_sum: GweiNewtype,
) -> Result<ValidatorReward> {
Expand All @@ -59,7 +63,7 @@ pub async fn get_mev_reward(

let effective_balance_sum_eth: EthNewtype = effective_balance_sum.into();
let active_validators: f64 = (effective_balance_sum_eth.0 / 32.0).floor();
let annual_reward_eth = mev_per_slot.0 * SLOTS_PER_YEAR / active_validators;
let annual_reward_eth = mev_per_slot.0 * SLOTS_PER_YEAR * MEV_REWARD_FACTOR / active_validators;
let annual_reward = EthNewtype(annual_reward_eth).into();
let apr = annual_reward_eth / 32f64;

Expand Down

0 comments on commit 8c2a4ab

Please sign in to comment.