mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Consensus context with proposer index caching (#3604)
## Issue Addressed Closes https://github.com/sigp/lighthouse/issues/2371 ## Proposed Changes Backport some changes from `tree-states` that remove duplicated calculations of the `proposer_index`. With this change the proposer index should be calculated only once for each block, and then plumbed through to every place it is required. ## Additional Info In future I hope to add more data to the consensus context that is cached on a per-epoch basis, like the effective balances of validators and the base rewards. There are some other changes to remove indexing in tests that were also useful for `tree-states` (the `tree-states` types don't implement `Index`).
This commit is contained in:
@@ -76,6 +76,7 @@ pub fn block_proposal_signature_set<'a, T, F, Payload: ExecPayload<T>>(
|
||||
get_pubkey: F,
|
||||
signed_block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
verified_proposer_index: Option<u64>,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<SignatureSet<'a>>
|
||||
where
|
||||
@@ -83,8 +84,12 @@ where
|
||||
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
||||
{
|
||||
let block = signed_block.message();
|
||||
let proposer_index = state.get_beacon_proposer_index(block.slot(), spec)? as u64;
|
||||
|
||||
let proposer_index = if let Some(proposer_index) = verified_proposer_index {
|
||||
proposer_index
|
||||
} else {
|
||||
state.get_beacon_proposer_index(block.slot(), spec)? as u64
|
||||
};
|
||||
if proposer_index != block.proposer_index() {
|
||||
return Err(Error::IncorrectBlockProposer {
|
||||
block: block.proposer_index(),
|
||||
@@ -156,13 +161,18 @@ pub fn randao_signature_set<'a, T, F, Payload: ExecPayload<T>>(
|
||||
state: &'a BeaconState<T>,
|
||||
get_pubkey: F,
|
||||
block: BeaconBlockRef<'a, T, Payload>,
|
||||
verified_proposer_index: Option<u64>,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<SignatureSet<'a>>
|
||||
where
|
||||
T: EthSpec,
|
||||
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
||||
{
|
||||
let proposer_index = state.get_beacon_proposer_index(block.slot(), spec)?;
|
||||
let proposer_index = if let Some(proposer_index) = verified_proposer_index {
|
||||
proposer_index
|
||||
} else {
|
||||
state.get_beacon_proposer_index(block.slot(), spec)? as u64
|
||||
};
|
||||
|
||||
let domain = spec.get_domain(
|
||||
block.slot().epoch(T::slots_per_epoch()),
|
||||
@@ -178,7 +188,7 @@ where
|
||||
|
||||
Ok(SignatureSet::single_pubkey(
|
||||
block.body().randao_reveal(),
|
||||
get_pubkey(proposer_index).ok_or(Error::ValidatorUnknown(proposer_index as u64))?,
|
||||
get_pubkey(proposer_index as usize).ok_or(Error::ValidatorUnknown(proposer_index))?,
|
||||
message,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user