Files
lighthouse/beacon_node/http_api/src/validator.rs
Eitan Seri-Levi 268809a530 Rust clippy 1.87 lint fixes (#7471)
Fix clippy lints for `rustc` 1.87


  clippy complains about `BeaconChainError` being too large. I went on a bit of a boxing spree because of this. We may instead want to `Box` some of the `BeaconChainError` variants?
2025-05-16 05:03:00 +00:00

23 lines
754 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>, Box<BeaconChainError>> {
chain
.validator_index(pubkey)
.map_err(Box::new)?
.filter(|&index| {
state
.validators()
.get(index)
.is_some_and(|v| v.pubkey == *pubkey)
})
.map(Result::Ok)
.transpose()
}