mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
## Issue Addressed #4582 ## Proposed Changes Add a new v3 block fetching flow that can decide to return a Full OR Blinded payload ## Additional Info Co-authored-by: Michael Sproul <micsproul@gmail.com>
22 lines
724 B
Rust
22 lines
724 B
Rust
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
|
use types::{BeaconState, PublicKeyBytes};
|
|
|
|
/// Uses the `chain.validator_pubkey_cache` to resolve a pubkey to a validator
|
|
/// index and then ensures that the validator exists in the given `state`.
|
|
pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
|
|
chain: &BeaconChain<T>,
|
|
state: &BeaconState<T::EthSpec>,
|
|
pubkey: &PublicKeyBytes,
|
|
) -> Result<Option<usize>, BeaconChainError> {
|
|
chain
|
|
.validator_index(pubkey)?
|
|
.filter(|&index| {
|
|
state
|
|
.validators()
|
|
.get(index)
|
|
.map_or(false, |v| v.pubkey == *pubkey)
|
|
})
|
|
.map(Result::Ok)
|
|
.transpose()
|
|
}
|