mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-07 18:51:45 +00:00
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?
23 lines
754 B
Rust
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()
|
|
}
|