Skip to content

Commit

Permalink
Add extra metadata to block rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Oct 8, 2021
1 parent a6cb5af commit 189c31a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion beacon_node/beacon_chain/src/block_reward.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::lighthouse::{AttestationRewards, BlockReward};
use eth2::lighthouse::{AttestationRewards, BlockReward, BlockRewardMeta};
use operation_pool::{AttMaxCover, MaxCover};
use std::collections::HashMap;
use types::{BeaconBlockRef, BeaconState, EthSpec, Hash256, RelativeEpoch};
Expand Down Expand Up @@ -78,8 +78,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
per_attestation_rewards,
};

let meta = BlockRewardMeta {
slot: block.slot(),
parent_slot: state.latest_block_header().slot,
proposer_index: block.proposer_index(),
graffiti: block.body().graffiti().as_utf8_lossy(),
};

Ok(BlockReward {
block_root,
meta,
attestation_rewards,
})
}
Expand Down
2 changes: 1 addition & 1 deletion common/eth2/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ssz::four_byte_option_impl;
use ssz_derive::{Decode, Encode};
use store::{AnchorInfo, Split};

pub use block_rewards::{AttestationRewards, BlockReward, BlockRewardsQuery};
pub use block_rewards::{AttestationRewards, BlockReward, BlockRewardMeta, BlockRewardsQuery};
pub use eth2_libp2p::{types::SyncState, PeerInfo};

// Define "legacy" implementations of `Option<T>` which use four bytes for encoding the union
Expand Down
10 changes: 10 additions & 0 deletions common/eth2/src/lighthouse/block_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ use types::{Hash256, Slot};
pub struct BlockReward {
/// Block root of the block that these rewards are for.
pub block_root: Hash256,
/// Metadata about the block, particularly reward-relevant metadata.
pub meta: BlockRewardMeta,
/// Rewards due to attestations.
pub attestation_rewards: AttestationRewards,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct BlockRewardMeta {
pub slot: Slot,
pub parent_slot: Slot,
pub proposer_index: u64,
pub graffiti: String,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct AttestationRewards {
/// Total block reward from attestations included.
Expand Down

0 comments on commit 189c31a

Please sign in to comment.