Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Revert "Optimise HTTP validator lookups" #3658

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})
})
.and_then(|mut snapshot| {
// Regardless of where we got the state from, attempt to build all the
// caches except the tree hash cache.
// Regardless of where we got the state from, attempt to build the committee
// caches.
snapshot
.beacon_state
.build_all_caches(&self.spec)
.build_all_committee_caches(&self.spec)
.map_err(Into::into)
.map(|()| snapshot)
})?;
Expand Down
21 changes: 2 additions & 19 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,34 +668,17 @@ pub fn serve<T: BeaconChainTypes>(
"Invalid validator ID".to_string(),
))
}))
.and(log_filter.clone())
.and(warp::path::end())
.and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId, log| {
|state_id: StateId, chain: Arc<BeaconChain<T>>, validator_id: ValidatorId| {
blocking_json_task(move || {
let (data, execution_optimistic) = state_id
.map_state_and_execution_optimistic(
&chain,
|state, execution_optimistic| {
let index_opt = match &validator_id {
ValidatorId::PublicKey(pubkey) => {
// Fast path: use the pubkey cache which is probably
// initialised at the head.
match state.get_validator_index_read_only(pubkey) {
Ok(result) => result,
Err(e) => {
// Slow path, fall back to iteration.
debug!(
log,
"Validator look-up cache miss";
"reason" => ?e,
);
state
.validators()
.iter()
.position(|v| v.pubkey == *pubkey)
}
}
state.validators().iter().position(|v| v.pubkey == *pubkey)
}
ValidatorId::Index(index) => Some(*index as usize),
};
Expand Down
15 changes: 0 additions & 15 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,6 @@ impl<T: EthSpec> BeaconState<T> {
Ok(self.pubkey_cache().get(pubkey))
}

/// Immutable variant of `get_validator_index` which errors if the cache is not up to date.
pub fn get_validator_index_read_only(
&self,
pubkey: &PublicKeyBytes,
) -> Result<Option<usize>, Error> {
let pubkey_cache = self.pubkey_cache();
if pubkey_cache.len() != self.validators().len() {
return Err(Error::PubkeyCacheIncomplete {
cache_len: pubkey_cache.len(),
registry_len: self.validators().len(),
});
}
Ok(pubkey_cache.get(pubkey))
}

/// The epoch corresponding to `self.slot()`.
pub fn current_epoch(&self) -> Epoch {
self.slot().epoch(T::slots_per_epoch())
Expand Down