lodestar icon indicating copy to clipboard operation
lodestar copied to clipboard

Avoid accessing config, pubkey2index, index2pubkey from CachedBeaconState in beacon-node

Open twoeths opened this issue 1 month ago • 2 comments

Problem description

as part of #8650 once we switch to using native state transition, we don't have a CachedBeaconStateAltair or CachedBeaconStateAllForks anymore so we should not access config, pubkey2index, index2pubkey from it

Solution description

we need to implement a global cache and use it instead, something like:

export type GlobalCache {
  config: BeaconConfig;
  pubkey2index: PubkeyIndexMap;
  index2pubkey: Index2PubkeyCache;
}

Additional context

No response

twoeths avatar Dec 02 '25 07:12 twoeths

one way to make sure it works is to have config as a private property of EpochCache class

twoeths avatar Dec 02 '25 07:12 twoeths

in lighthouse it also has a ValidatorPubkeyCache

pub struct ValidatorPubkeyCache<T: BeaconChainTypes> {
    pubkeys: Vec<PublicKey>,
    indices: HashMap<PublicKeyBytes, usize>,
    pubkey_bytes: Vec<PublicKeyBytes>,
    _phantom: PhantomData<T>,
}

we can think about it later if we should implement something like that for now we already have everything in BeaconChain: pubkey2index, index2pubkey, config we should be able to use it in beacon-node instead of getting from any CachedBeaconStateAllForks

twoeths avatar Dec 09 '25 07:12 twoeths

need to think about how to populate pubkey2index, index2pubkey for the 1st time when we boost a beacon-node https://github.com/ChainSafe/lodestar/blob/889b1c44754fdfe6acd826fc10b5b0013d9a6faa/packages/beacon-node/src/chain/chain.ts#L325

we don't have a full BeaconState anymore, maybe IBeaconStateView should provide a function for us extract needed data, so that it works in all cases

update: need to populate it from cli instead. At cli, we always have BeaconState bytes there and we can extract pubkey2index, index2pubkey

twoeths avatar Dec 12 '25 07:12 twoeths