Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Apr 15, 2024
1 parent f631fd9 commit 7dda166
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/state-transition/src/cache/stateCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import bls from "@chainsafe/bls";
import {CoordType} from "@chainsafe/bls/types";
import {BeaconConfig} from "@lodestar/config";
import {loadState} from "../util/loadState/loadState.js";
import {EpochCache, EpochCacheImmutableData, EpochCacheOpts} from "./epochCache.js";
Expand Down Expand Up @@ -176,25 +174,26 @@ export function loadCachedBeaconState<T extends BeaconStateAllForks & BeaconStat
stateBytes,
seedValidatorsBytes
);
const {finalizedPubkey2index, finalizedIndex2pubkey} = cachedSeedState.epochCtx;
// Get the validators sub tree once for all the loop
const validators = migratedState.validators;
for (const validatorIndex of modifiedValidators) {
const validator = validators.getReadonly(validatorIndex);
const pubkey = validator.pubkey;
finalizedPubkey2index.set(pubkey, validatorIndex);
finalizedIndex2pubkey[validatorIndex] = bls.PublicKey.fromBytes(pubkey, CoordType.jacobian);
}

return createCachedBeaconState(
const state = createCachedBeaconState(
migratedState,
{
config: cachedSeedState.config,
finalizedPubkey2index,
finalizedIndex2pubkey,
finalizedPubkey2index: cachedSeedState.epochCtx.finalizedPubkey2index,
finalizedIndex2pubkey: cachedSeedState.epochCtx.finalizedIndex2pubkey,
},
{...(opts ?? {}), ...{skipSyncPubkeys: true}}
) as T;

// Get the validators sub tree once for all the loop
const validators = migratedState.validators;
for (const validatorIndex of modifiedValidators) {
const validator = validators.getReadonly(validatorIndex);
const pubkey = validator.pubkey;
state.epochCtx.addUnFinalizedPubkey(validatorIndex, pubkey);
}

return state;
}

/**
Expand Down

0 comments on commit 7dda166

Please sign in to comment.