Files
lighthouse/beacon_node/http_api/src/validator.rs
Pawan Dhananjay 1f6850fae2 Rust 1.84 lints (#6781)
* Fix few lints

* Fix remaining lints

* Use fully qualified syntax
2025-01-10 01:13:29 +00:00

22 lines
722 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)
.is_some_and(|v| v.pubkey == *pubkey)
})
.map(Result::Ok)
.transpose()
}