# Dev Update #12 Hey :wave: in my [last update](https://hackmd.io/@kevinbogner/dev-update-11) I discussed the first part of the `attestation_rewards` endpoint, the `ideal_rewards`. In *this* update, I want to focus on the second and last part, the `total_rewards`. ```json { "execution_optimistic": false, "finalized": false, "data": [ { "ideal_rewards": [ { "effective_balance": "1000000000", "head": "2500", "target": "5000", "source": "5000" } ], "total_rewards": [ { "validator_index": "0", "head": "2000", "target": "2000", "source": "4000", "inclusion_delay": "2000" } ] } ] } ``` ## `total_rewards` The `total_rewards` describe the *actual rewards* a validator receives through attestations. To rephrase the logic I already explained in [earlier development updates](https://hackmd.io/@kevinbogner/dev-update-10#Actual-rewards): - Determine if the validator is *eligible* for rewards in the chosen epoch. If *not*, their reward is `0`. - Determine if the validator *voted correctly* for the `flag` (`head`,`target`, and `source`). - If the validator voted *correctly*, their reward is based on the combination of the `flag` and their `effective_balance`. - If the validator voted *incorrectly*, their reward is calculated differently depending on the `flag`: - For the `head` vote, the reward is `0`. - For the `target` and `source` votes, the reward is a negative value calculated by multiplying the base reward by the weight and dividing by a certain value. My *current* implementation for the `total_rewards` looks like the following: ```rust let index = participation_cache.eligible_validator_indices(); for validator_index in index { let eligible = match state.is_eligible_validator(previous_epoch, *validator_index) { Ok(eligible) => eligible, Err(_) => return Err(warp_utils::reject::custom_server_error("Unable to get eligible".to_owned())), }; let total_reward = if !eligible { 0u64 } else { let voted_correctly = participation_cache.get_unslashed_participating_indices(flag_index, previous_epoch).is_ok(); if voted_correctly { *ideal_rewards.get(&(&flag_index, effective_balance_eth)).unwrap_or(&0) } else { (-(base_reward as i64 as i128) * weight as i128 / WEIGHT_DENOMINATOR as i128) as u64 } }; ``` ## Next up To be able to merge this endpoint, there are still some things left to do. I need to get the `inclusion_delay`, convert the HashMap of `ideal_rewards` into a Vector, test the API manually, and make minor optimizations. Hopefully, I will be able to finish the `attestation_rewards` until the next update.