Implement API for block rewards (#2628)

## Proposed Changes

Add an API endpoint for retrieving detailed information about block rewards.

For information on usage see [the docs](https://github.com/sigp/lighthouse/blob/block-rewards-api/book/src/api-lighthouse.md#lighthouseblock_rewards), and the source.
This commit is contained in:
Michael Sproul
2022-01-27 01:06:02 +00:00
parent 013a3cc3e0
commit e70daaa3b6
14 changed files with 366 additions and 16 deletions

View File

@@ -53,6 +53,7 @@ use crate::{
},
metrics, BeaconChain, BeaconChainError, BeaconChainTypes,
};
use eth2::types::EventKind;
use fork_choice::{ForkChoice, ForkChoiceStore, PayloadVerificationStatus};
use parking_lot::RwLockReadGuard;
use proto_array::Block as ProtoBlock;
@@ -1165,6 +1166,18 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
metrics::stop_timer(committee_timer);
/*
* If we have block reward listeners, compute the block reward and push it to the
* event handler.
*/
if let Some(ref event_handler) = chain.event_handler {
if event_handler.has_block_reward_subscribers() {
let block_reward =
chain.compute_block_reward(block.message(), block_root, &state)?;
event_handler.register(EventKind::BlockReward(block_reward));
}
}
/*
* Perform `per_block_processing` on the block and state, returning early if the block is
* invalid.