Skip to content

Commit a4d9185

Browse files
committed
Revert "Optimise HTTP validator lookups"
This reverts commit ca9dc8e with some modifications.
1 parent fcfd02a commit a4d9185

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
654654
})
655655
})
656656
.and_then(|mut snapshot| {
657-
// Regardless of where we got the state from, attempt to build all the
658-
// caches except the tree hash cache.
657+
// Regardless of where we got the state from, attempt to build the committee
658+
// caches.
659659
snapshot
660660
.beacon_state
661-
.build_all_caches(&self.spec)
661+
.build_all_committee_caches(&self.spec)
662662
.map_err(Into::into)
663663
.map(|()| snapshot)
664664
})?;

beacon_node/http_api/src/lib.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -668,34 +668,17 @@ pub fn serve<T: BeaconChainTypes>(
668668
"Invalid validator ID".to_string(),
669669
))
670670
}))
671-
.and(log_filter.clone())
672671
.and(warp::path::end())
673672
.and_then(
674-
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId, log| {
673+
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId| {
675674
blocking_json_task(move || {
676675
let (data, execution_optimistic) = state_id
677676
.map_state_and_execution_optimistic(
678677
&chain,
679678
|state, execution_optimistic| {
680679
let index_opt = match &validator_id {
681680
ValidatorId::PublicKey(pubkey) => {
682-
// Fast path: use the pubkey cache which is probably
683-
// initialised at the head.
684-
match state.get_validator_index_read_only(pubkey) {
685-
Ok(result) => result,
686-
Err(e) => {
687-
// Slow path, fall back to iteration.
688-
debug!(
689-
log,
690-
"Validator look-up cache miss";
691-
"reason" => ?e,
692-
);
693-
state
694-
.validators()
695-
.iter()
696-
.position(|v| v.pubkey == *pubkey)
697-
}
698-
}
681+
state.validators().iter().position(|v| v.pubkey == *pubkey)
699682
}
700683
ValidatorId::Index(index) => Some(*index as usize),
701684
};

consensus/types/src/beacon_state.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -447,21 +447,6 @@ impl<T: EthSpec> BeaconState<T> {
447447
Ok(self.pubkey_cache().get(pubkey))
448448
}
449449

450-
/// Immutable variant of `get_validator_index` which errors if the cache is not up to date.
451-
pub fn get_validator_index_read_only(
452-
&self,
453-
pubkey: &PublicKeyBytes,
454-
) -> Result<Option<usize>, Error> {
455-
let pubkey_cache = self.pubkey_cache();
456-
if pubkey_cache.len() != self.validators().len() {
457-
return Err(Error::PubkeyCacheIncomplete {
458-
cache_len: pubkey_cache.len(),
459-
registry_len: self.validators().len(),
460-
});
461-
}
462-
Ok(pubkey_cache.get(pubkey))
463-
}
464-
465450
/// The epoch corresponding to `self.slot()`.
466451
pub fn current_epoch(&self) -> Epoch {
467452
self.slot().epoch(T::slots_per_epoch())

0 commit comments

Comments
 (0)