lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Fix phase0 block reward in rewards API

Open dknopik opened this issue 2 years ago • 1 comments

Issues Addressed

  • #4929
  • #4856

Proposed Changes

Instead of relying on compute_block_reward for phase0, a new custom implementation for compute_beacon_block_attestation_reward_base is used, which handles edge cases like attestations from validators that were slashed after attesting and proposals in the epoch before Altair correctly.

Additionally, this PR incorporates and improves the changes proposed in PR #4882.

Additional Info

Some points I'm unsure about:

  • I use BeaconChain::state_at_slot to obtain needed states (at most twice per calculation). Another approach is using the BlockReplayer to advance the passed state, which would avoid (maybe) expensive lookups from the cold DB. However I am unsure if the added complexity is worth it, and maybe this is even a non-issue due to smart caching or something else I am unaware of.
  • I build the committee caches for the states I fetch, but only because I need the total active balance. BeaconState::build_total_active_balance_cache is not pub, is that intentional?

dknopik avatar Jan 20 '24 21:01 dknopik

Ready for review - Happy to receive feedback, especially regarding the points listed in "Additional Info".

dknopik avatar Jan 31 '24 01:01 dknopik