Skip to content

Slow API calls for slots that are not synced #824

@pscott

Description

@pscott

Description

Slow API calls when trying to fetch data about some slot that is not currently synced but smaller than the current slot (as provided by the slot_clock).

Present Behaviour

When starting a fresh sync (no DB), the beacon node starts by syncing up the chain. Making an API call that asks for data that is not synced yet, but smaller than the current slot clock will make a call to state_root_at_slot, which will in turn start skipping slots until it gets to correct slot.

} else {
// 4. The request slot is later than the head slot.
//
// Use `per_slot_processing` to advance the head state to the present slot,
// assuming that all slots do not contain a block (i.e., they are skipped slots).
let mut state = beacon_chain.head()?.beacon_state;
let spec = &T::EthSpec::default_spec();
for _ in state.slot.as_u64()..slot.as_u64() {
// Ensure the next epoch state caches are built in case of an epoch transition.
state.build_committee_cache(RelativeEpoch::Next, spec)?;
state_processing::per_slot_processing(&mut state, None, spec)?;
}
// Note: this is an expensive operation. Once the tree hash cache is implement it may be
// used here.
Ok(state.canonical_root())

This can result in a very, very long API call (I personally witnessed a 19 minutes long API call).
Correct me if I'm wrong but by skipping slots we assume that they were skip slots (i.e they did not contain any block), so it makes the result invalid?

Expected Behaviour

I see two options here:

  1. Return an error saying (slot is higher than current synced head)
  2. Keep our present behaviour but log some kind of warning, so that the user knows what's happening.

Steps to resolve

Choose an option, and implement it, most probably in the piece of code linked earlier in this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions