From f2fcdfecf3eeaab5615b286c2061cbae73702bea Mon Sep 17 00:00:00 2001 From: NC Date: Thu, 4 Apr 2024 19:12:56 +0800 Subject: [PATCH] Undo unrelated renaming --- packages/beacon-node/src/chain/chain.ts | 4 ++-- .../beacon-node/src/chain/genesis/genesis.ts | 4 ++-- .../stateCache/persistentCheckpointsCache.ts | 4 ++-- .../e2e/eth1/eth1ForBlockProduction.test.ts | 4 ++-- .../spec/presets/epoch_processing.test.ts | 4 ++-- .../test/spec/presets/finality.test.ts | 4 ++-- .../test/spec/presets/fork.test.ts | 4 ++-- .../test/spec/presets/fork_choice.test.ts | 4 ++-- .../test/spec/presets/operations.test.ts | 4 ++-- .../test/spec/presets/rewards.test.ts | 4 ++-- .../test/spec/presets/sanity.test.ts | 6 ++--- .../test/spec/presets/transition.test.ts | 4 ++-- .../impl/validator/duties/proposer.test.ts | 6 ++--- .../unit/chain/forkChoice/forkChoice.test.ts | 6 ++--- .../validation/blsToExecutionChange.test.ts | 4 ++-- .../chain/validation/voluntaryExit.test.ts | 4 ++-- .../test/unit/eth1/utils/deposits.test.ts | 4 ++-- .../test/utils/cachedBeaconState.ts | 6 ++--- .../test/utils/networkWithMockDb.ts | 4 ++-- packages/beacon-node/test/utils/state.ts | 10 ++++----- .../state-transition/src/cache/stateCache.ts | 10 ++++----- packages/state-transition/src/index.ts | 4 ++-- packages/state-transition/src/util/genesis.ts | 4 ++-- .../test/perf/analyzeEpochs.ts | 4 ++-- .../processEffectiveBalanceUpdates.test.ts | 4 ++-- packages/state-transition/test/perf/util.ts | 8 +++---- .../perf/util/loadState/loadState.test.ts | 4 ++-- .../test/unit/cachedBeaconState.test.ts | 22 +++++++++---------- .../test/unit/upgradeState.test.ts | 6 ++--- .../test/unit/util/cachedBeaconState.test.ts | 4 ++-- .../test/unit/util/deposit.test.ts | 8 +++---- .../state-transition/test/utils/capella.ts | 6 ++--- packages/state-transition/test/utils/state.ts | 8 +++---- .../test/utils/testFileCache.ts | 12 +++------- 34 files changed, 96 insertions(+), 102 deletions(-) diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index 5a80ae3dfa99..00ce58df32c6 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -5,7 +5,7 @@ import { CachedBeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch, - createFinalizedCachedBeaconState, + createCachedBeaconState, EffectiveBalanceIncrements, getEffectiveBalanceIncrementsZeroInactive, isCachedBeaconState, @@ -226,7 +226,7 @@ export class BeaconChain implements IBeaconChain { const cachedState = isCachedBeaconState(anchorState) && opts.skipCreateStateCacheIfAvailable ? anchorState - : createFinalizedCachedBeaconState(anchorState, { + : createCachedBeaconState(anchorState, { config, finalizedPubkey2index: new PubkeyIndexMap(), finalizedIndex2pubkey: [], diff --git a/packages/beacon-node/src/chain/genesis/genesis.ts b/packages/beacon-node/src/chain/genesis/genesis.ts index 4b172fd8a9a2..979476c69530 100644 --- a/packages/beacon-node/src/chain/genesis/genesis.ts +++ b/packages/beacon-node/src/chain/genesis/genesis.ts @@ -9,7 +9,7 @@ import { applyTimestamp, applyEth1BlockHash, CachedBeaconStateAllForks, - createFinalizedCachedBeaconState, + createCachedBeaconState, BeaconStateAllForks, createEmptyEpochCacheImmutableData, getActiveValidatorIndices, @@ -86,7 +86,7 @@ export class GenesisBuilder implements IGenesisBuilder { } // TODO - PENDING: Ensure EpochCacheImmutableData is created only once - this.state = createFinalizedCachedBeaconState(stateView, createEmptyEpochCacheImmutableData(config, stateView)); + this.state = createCachedBeaconState(stateView, createEmptyEpochCacheImmutableData(config, stateView)); this.config = this.state.config; this.activatedValidatorCount = getActiveValidatorIndices(stateView, GENESIS_EPOCH).length; } diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 17cc40e570d3..b4f3612bb536 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -3,7 +3,7 @@ import {phase0, Epoch, RootHex} from "@lodestar/types"; import {CachedBeaconStateAllForks, computeStartSlotAtEpoch, getBlockRootAtSlot} from "@lodestar/state-transition"; import {Logger, MapDef, sleep} from "@lodestar/utils"; import {routes} from "@lodestar/api"; -import {loadUnfinalizedCachedBeaconState} from "@lodestar/state-transition"; +import {loadCachedBeaconState} from "@lodestar/state-transition"; import {INTERVALS_PER_SLOT} from "@lodestar/params"; import {Metrics} from "../../metrics/index.js"; import {IClock} from "../../util/clock.js"; @@ -214,7 +214,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { } sszTimer?.(); const timer = this.metrics?.stateReloadDuration.startTimer(); - const newCachedState = loadUnfinalizedCachedBeaconState( + const newCachedState = loadCachedBeaconState( seedState, stateBytes, { diff --git a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts index 34ac4ca46824..1a80d95c1fdc 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts @@ -14,7 +14,7 @@ import {BeaconDb} from "../../../src/db/index.js"; import {generateState} from "../../utils/state.js"; import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; import {getGoerliRpcUrl} from "../../testParams.js"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; const dbLocation = "./.__testdb"; @@ -112,7 +112,7 @@ describe.skip("eth1 / Eth1Provider", function () { config ); - const state = createFinalizedCachedBeaconStateTest(tbState, config); + const state = createCachedBeaconStateTest(tbState, config); const result = await eth1ForBlockProduction.getEth1DataAndDeposits(state); expect(result.eth1Data).toEqual(latestEth1Data); diff --git a/packages/beacon-node/test/spec/presets/epoch_processing.test.ts b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts index c61ee22d1698..a244762143f3 100644 --- a/packages/beacon-node/test/spec/presets/epoch_processing.test.ts +++ b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts @@ -9,7 +9,7 @@ import { import * as epochFns from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; import {ACTIVE_PRESET} from "@lodestar/params"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; import {RunnerType, TestRunnerFn} from "../utils/types.js"; @@ -64,7 +64,7 @@ const epochProcessing = return { testFunction: (testcase) => { const stateTB = testcase.pre.clone(); - const state = createFinalizedCachedBeaconStateTest(stateTB, config); + const state = createCachedBeaconStateTest(stateTB, config); const epochTransitionCache = beforeProcessEpoch(state, {assertCorrectProgressiveBalances}); diff --git a/packages/beacon-node/test/spec/presets/finality.test.ts b/packages/beacon-node/test/spec/presets/finality.test.ts index c1a22740785f..0ec4017064f4 100644 --- a/packages/beacon-node/test/spec/presets/finality.test.ts +++ b/packages/beacon-node/test/spec/presets/finality.test.ts @@ -7,7 +7,7 @@ import { } from "@lodestar/state-transition"; import {altair, bellatrix, ssz} from "@lodestar/types"; import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; @@ -20,7 +20,7 @@ import {specTestIterator} from "../utils/specTestIterator.js"; const finality: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { - let state = createFinalizedCachedBeaconStateTest(testcase.pre, getConfig(fork)); + let state = createCachedBeaconStateTest(testcase.pre, getConfig(fork)); const verify = shouldVerify(testcase); for (let i = 0; i < testcase.meta.blocks_count; i++) { const signedBlock = testcase[`blocks_${i}`] as bellatrix.SignedBeaconBlock; diff --git a/packages/beacon-node/test/spec/presets/fork.test.ts b/packages/beacon-node/test/spec/presets/fork.test.ts index 1a2634680e8a..c121e651fcea 100644 --- a/packages/beacon-node/test/spec/presets/fork.test.ts +++ b/packages/beacon-node/test/spec/presets/fork.test.ts @@ -12,7 +12,7 @@ import {phase0, ssz} from "@lodestar/types"; import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {specTestIterator} from "../utils/specTestIterator.js"; @@ -23,7 +23,7 @@ const fork: TestRunnerFn = (forkNext) => { return { testFunction: (testcase) => { - const preState = createFinalizedCachedBeaconStateTest(testcase.pre, config); + const preState = createCachedBeaconStateTest(testcase.pre, config); switch (forkNext) { case ForkName.phase0: diff --git a/packages/beacon-node/test/spec/presets/fork_choice.test.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts index cd439ea2fbc0..49d78cc42f6a 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.test.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -11,7 +11,7 @@ import {ACTIVE_PRESET, ForkSeq, isForkBlobs} from "@lodestar/params"; import {BeaconChain, ChainEvent} from "../../../src/chain/index.js"; import {ClockEvent} from "../../../src/util/clock.js"; import {computeInclusionProof} from "../../../src/util/blobs.js"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {testLogger} from "../../utils/logger.js"; import {getConfig} from "../../utils/config.js"; import {RunnerType, TestRunnerFn} from "../utils/types.js"; @@ -60,7 +60,7 @@ const forkChoiceTest = const {steps, anchorState} = testcase; const currentSlot = anchorState.slot; const config = getConfig(fork); - const state = createFinalizedCachedBeaconStateTest(anchorState, config); + const state = createCachedBeaconStateTest(anchorState, config); /** This is to track test's tickTime to be used in proposer boost */ let tickTime = 0; diff --git a/packages/beacon-node/test/spec/presets/operations.test.ts b/packages/beacon-node/test/spec/presets/operations.test.ts index 3a91b91ed904..2c4ae22475a5 100644 --- a/packages/beacon-node/test/spec/presets/operations.test.ts +++ b/packages/beacon-node/test/spec/presets/operations.test.ts @@ -13,7 +13,7 @@ import {ssz, phase0, altair, bellatrix, capella, electra} from "@lodestar/types" import {InputType} from "@lodestar/spec-test-util"; import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; import {BaseSpecTest, RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; @@ -111,7 +111,7 @@ const operations: TestRunnerFn = (fork, testFunction: (testcase) => { const state = testcase.pre.clone(); const epoch = (state.fork as phase0.Fork).epoch; - const cachedState = createFinalizedCachedBeaconStateTest(state, getConfig(fork, epoch)); + const cachedState = createCachedBeaconStateTest(state, getConfig(fork, epoch)); operationFn(cachedState, testcase); state.commit(); diff --git a/packages/beacon-node/test/spec/presets/rewards.test.ts b/packages/beacon-node/test/spec/presets/rewards.test.ts index 061ed2ff3cde..426245242d84 100644 --- a/packages/beacon-node/test/spec/presets/rewards.test.ts +++ b/packages/beacon-node/test/spec/presets/rewards.test.ts @@ -5,7 +5,7 @@ import {BeaconStateAllForks, beforeProcessEpoch} from "@lodestar/state-transitio import {getRewardsAndPenalties} from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; import {ACTIVE_PRESET} from "@lodestar/params"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; import {RunnerType, TestRunnerFn} from "../utils/types.js"; @@ -21,7 +21,7 @@ const rewards: TestRunnerFn = (fork) => { return { testFunction: (testcase) => { const config = getConfig(fork); - const wrappedState = createFinalizedCachedBeaconStateTest(testcase.pre, config); + const wrappedState = createCachedBeaconStateTest(testcase.pre, config); const epochTransitionCache = beforeProcessEpoch(wrappedState, {assertCorrectProgressiveBalances}); // To debug this test and get granular results you can tweak inputs to get more granular results diff --git a/packages/beacon-node/test/spec/presets/sanity.test.ts b/packages/beacon-node/test/spec/presets/sanity.test.ts index 223fab0ded08..57afb8cf3d28 100644 --- a/packages/beacon-node/test/spec/presets/sanity.test.ts +++ b/packages/beacon-node/test/spec/presets/sanity.test.ts @@ -10,7 +10,7 @@ import { import {allForks, deneb, ssz} from "@lodestar/types"; import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; @@ -35,7 +35,7 @@ const sanitySlots: TestRunnerFn = (for return { testFunction: (testcase) => { const stateTB = testcase.pre.clone(); - const state = createFinalizedCachedBeaconStateTest(stateTB, getConfig(fork)); + const state = createCachedBeaconStateTest(stateTB, getConfig(fork)); const postState = processSlots(state, state.slot + bnToNum(testcase.slots), {assertCorrectProgressiveBalances}); // TODO: May be part of runStateTranstion, necessary to commit again? postState.commit(); @@ -62,7 +62,7 @@ const sanityBlocks: TestRunnerFn = (f return { testFunction: (testcase) => { const stateTB = testcase.pre; - let wrappedState = createFinalizedCachedBeaconStateTest(stateTB, getConfig(fork)); + let wrappedState = createCachedBeaconStateTest(stateTB, getConfig(fork)); const verify = shouldVerify(testcase); for (let i = 0; i < testcase.meta.blocks_count; i++) { const signedBlock = testcase[`blocks_${i}`] as deneb.SignedBeaconBlock; diff --git a/packages/beacon-node/test/spec/presets/transition.test.ts b/packages/beacon-node/test/spec/presets/transition.test.ts index f5cb0decdea1..1f98dbb41f58 100644 --- a/packages/beacon-node/test/spec/presets/transition.test.ts +++ b/packages/beacon-node/test/spec/presets/transition.test.ts @@ -11,7 +11,7 @@ import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; import {config} from "@lodestar/config/default"; import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; @@ -51,7 +51,7 @@ const transition = const forkEpoch = bnToNum(meta.fork_epoch); const testConfig = createChainForkConfig(getTransitionConfig(forkNext, forkEpoch)); - let state = createFinalizedCachedBeaconStateTest(testcase.pre, testConfig); + let state = createCachedBeaconStateTest(testcase.pre, testConfig); for (let i = 0; i < meta.blocks_count; i++) { const signedBlock = testcase[`blocks_${i}`] as allForks.SignedBeaconBlock; state = stateTransition(state, signedBlock, { diff --git a/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts b/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts index 0cd43e9231a7..bf9544ad683e 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts @@ -7,14 +7,14 @@ import {FAR_FUTURE_EPOCH} from "../../../../../../src/constants/index.js"; import {SYNC_TOLERANCE_EPOCHS, getValidatorApi} from "../../../../../../src/api/impl/validator/index.js"; import {generateState, zeroProtoBlock} from "../../../../../utils/state.js"; import {generateValidators} from "../../../../../utils/validator.js"; -import {createFinalizedCachedBeaconStateTest} from "../../../../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../../../../utils/cachedBeaconState.js"; import {SyncState} from "../../../../../../src/sync/interface.js"; describe("get proposers api impl", function () { let api: ReturnType; let modules: ApiTestModules; let state: BeaconStateAllForks; - let cachedState: ReturnType; + let cachedState: ReturnType; beforeEach(function () { vi.useFakeTimers({now: 0}); @@ -33,7 +33,7 @@ describe("get proposers api impl", function () { }, config ); - cachedState = createFinalizedCachedBeaconStateTest(state, config); + cachedState = createCachedBeaconStateTest(state, config); modules.chain.getHeadStateAtCurrentEpoch.mockResolvedValue(cachedState); modules.forkChoice.getHead.mockReturnValue(zeroProtoBlock); diff --git a/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts b/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts index 78b7ea2310b7..20b6fc8d7a00 100644 --- a/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts +++ b/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts @@ -12,7 +12,7 @@ import {phase0, Slot, ssz, ValidatorIndex} from "@lodestar/types"; import {getTemporaryBlockHeader, processSlots} from "@lodestar/state-transition"; import {ChainEventEmitter, computeAnchorCheckpoint, initializeForkChoice} from "../../../../src/chain/index.js"; import {generateSignedBlockAtSlot} from "../../../utils/typeGenerator.js"; -import {createFinalizedCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; import {generateState} from "../../../utils/state.js"; import {generateValidators} from "../../../utils/validator.js"; @@ -21,7 +21,7 @@ vi.unmock("@lodestar/fork-choice"); describe("LodestarForkChoice", function () { let forkChoice: ForkChoice; - const anchorState = createFinalizedCachedBeaconStateTest( + const anchorState = createCachedBeaconStateTest( generateState( { slot: 0, @@ -53,7 +53,7 @@ describe("LodestarForkChoice", function () { let state: CachedBeaconStateAllForks; beforeAll(() => { - state = createFinalizedCachedBeaconStateTest(anchorState, config); + state = createCachedBeaconStateTest(anchorState, config); }); beforeEach(() => { diff --git a/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts b/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts index 3791a4a25878..f83b900beb69 100644 --- a/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts @@ -19,7 +19,7 @@ import {generateState} from "../../../utils/state.js"; import {validateGossipBlsToExecutionChange} from "../../../../src/chain/validation/blsToExecutionChange.js"; import {BlsToExecutionChangeErrorCode} from "../../../../src/chain/errors/blsToExecutionChangeError.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; -import {createFinalizedCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; describe("validate bls to execution change", () => { let chainStub: MockedBeaconChain; @@ -70,7 +70,7 @@ describe("validate bls to execution change", () => { // Generate the state const _state = generateState(stateEmpty, defaultConfig); const config = createBeaconConfig(defaultConfig, _state.genesisValidatorsRoot); - const state = createFinalizedCachedBeaconStateTest(_state, config); + const state = createCachedBeaconStateTest(_state, config); // Gen a valid blsToExecutionChange for first val const blsToExecutionChange = { diff --git a/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts b/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts index 7e7b2d5cca74..3966815c28ce 100644 --- a/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts @@ -16,7 +16,7 @@ import {generateState} from "../../../utils/state.js"; import {validateGossipVoluntaryExit} from "../../../../src/chain/validation/voluntaryExit.js"; import {VoluntaryExitErrorCode} from "../../../../src/chain/errors/voluntaryExitError.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; -import {createFinalizedCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; describe("validate voluntary exit", () => { let chainStub: MockedBeaconChain; @@ -58,7 +58,7 @@ describe("validate voluntary exit", () => { signedVoluntaryExit = {message: voluntaryExit, signature: sk.sign(signingRoot).toBytes()}; const _state = generateState(stateEmpty, config); - state = createFinalizedCachedBeaconStateTest(_state, createBeaconConfig(config, _state.genesisValidatorsRoot)); + state = createCachedBeaconStateTest(_state, createBeaconConfig(config, _state.genesisValidatorsRoot)); }); beforeEach(() => { diff --git a/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts b/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts index 6355eb5d6723..6cc3ae8f1ce0 100644 --- a/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts @@ -9,7 +9,7 @@ import {generateState} from "../../../utils/state.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; import {getDeposits, getDepositsWithProofs, DepositGetter} from "../../../../src/eth1/utils/deposits.js"; import {DepositTree} from "../../../../src/db/repositories/depositDataRoot.js"; -import {createFinalizedCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; describe("eth1 / util / deposits", function () { describe("getDeposits", () => { @@ -116,7 +116,7 @@ describe("eth1 / util / deposits", function () { const state = postElectra ? generateState({slot: postElectraSlot, eth1DepositIndex}, postElectraConfig) : generateState({eth1DepositIndex}); - const cachedState = createFinalizedCachedBeaconStateTest( + const cachedState = createCachedBeaconStateTest( state, postElectra ? postElectraConfig : createChainForkConfig({}) ); diff --git a/packages/beacon-node/test/utils/cachedBeaconState.ts b/packages/beacon-node/test/utils/cachedBeaconState.ts index f647ccbd1265..3efb16b6250f 100644 --- a/packages/beacon-node/test/utils/cachedBeaconState.ts +++ b/packages/beacon-node/test/utils/cachedBeaconState.ts @@ -1,14 +1,14 @@ import { BeaconStateAllForks, BeaconStateCache, - createFinalizedCachedBeaconState, + createCachedBeaconState, createEmptyEpochCacheImmutableData, } from "@lodestar/state-transition"; import {ChainForkConfig} from "@lodestar/config"; -export function createFinalizedCachedBeaconStateTest( +export function createCachedBeaconStateTest( state: T, chainConfig: ChainForkConfig ): T & BeaconStateCache { - return createFinalizedCachedBeaconState(state, createEmptyEpochCacheImmutableData(chainConfig, state)); + return createCachedBeaconState(state, createEmptyEpochCacheImmutableData(chainConfig, state)); } diff --git a/packages/beacon-node/test/utils/networkWithMockDb.ts b/packages/beacon-node/test/utils/networkWithMockDb.ts index e1c4fd8b1a1a..f8a4a6181d2f 100644 --- a/packages/beacon-node/test/utils/networkWithMockDb.ts +++ b/packages/beacon-node/test/utils/networkWithMockDb.ts @@ -8,7 +8,7 @@ import {GossipHandlers, Network, NetworkInitModules, getReqRespHandlers} from ". import {NetworkOptions, defaultNetworkOptions} from "../../src/network/options.js"; import {GetReqRespHandlerFn} from "../../src/network/reqresp/types.js"; import {getMockedBeaconDb} from "../mocks/mockedBeaconDb.js"; -import {createFinalizedCachedBeaconStateTest} from "./cachedBeaconState.js"; +import {createCachedBeaconStateTest} from "./cachedBeaconState.js"; import {ClockStatic} from "./clock.js"; import {testLogger} from "./logger.js"; import {generateState} from "./state.js"; @@ -64,7 +64,7 @@ export async function getNetworkForTest( // mock timer does not work on worker thread clock: new ClockStatic(startSlot, Math.floor(Date.now() / 1000) - startSlot * beaconConfig.SECONDS_PER_SLOT), metrics: null, - anchorState: createFinalizedCachedBeaconStateTest(state, beaconConfig), + anchorState: createCachedBeaconStateTest(state, beaconConfig), eth1: new Eth1ForBlockProductionDisabled(), executionEngine: new ExecutionEngineDisabled(), } diff --git a/packages/beacon-node/test/utils/state.ts b/packages/beacon-node/test/utils/state.ts index a15c57524bab..779ad4c684d4 100644 --- a/packages/beacon-node/test/utils/state.ts +++ b/packages/beacon-node/test/utils/state.ts @@ -3,7 +3,7 @@ import {config as minimalConfig} from "@lodestar/config/default"; import { BeaconStateAllForks, CachedBeaconStateAllForks, - createFinalizedCachedBeaconState, + createCachedBeaconState, PubkeyIndexMap, CachedBeaconStateBellatrix, BeaconStateBellatrix, @@ -110,7 +110,7 @@ export function generateState( export function generateCachedState(opts?: TestBeaconState): CachedBeaconStateAllForks { const config = getConfig(ForkName.phase0); const state = generateState(opts, config); - return createFinalizedCachedBeaconState(state, { + return createCachedBeaconState(state, { config: createBeaconConfig(config, state.genesisValidatorsRoot), // This is a performance test, there's no need to have a global shared cache of keys finalizedPubkey2index: new PubkeyIndexMap(), @@ -124,7 +124,7 @@ export function generateCachedState(opts?: TestBeaconState): CachedBeaconStateAl export function generateCachedAltairState(opts?: TestBeaconState, altairForkEpoch = 0): CachedBeaconStateAllForks { const config = getConfig(ForkName.altair, altairForkEpoch); const state = generateState(opts, config); - return createFinalizedCachedBeaconState(state, { + return createCachedBeaconState(state, { config: createBeaconConfig(config, state.genesisValidatorsRoot), // This is a performance test, there's no need to have a global shared cache of keys finalizedPubkey2index: new PubkeyIndexMap(), @@ -138,7 +138,7 @@ export function generateCachedAltairState(opts?: TestBeaconState, altairForkEpoc export function generateCachedBellatrixState(opts?: TestBeaconState): CachedBeaconStateBellatrix { const config = getConfig(ForkName.bellatrix); const state = generateState(opts, config); - return createFinalizedCachedBeaconState(state as BeaconStateBellatrix, { + return createCachedBeaconState(state as BeaconStateBellatrix, { config: createBeaconConfig(config, state.genesisValidatorsRoot), // This is a performance test, there's no need to have a global shared cache of keys finalizedPubkey2index: new PubkeyIndexMap(), @@ -152,7 +152,7 @@ export function generateCachedBellatrixState(opts?: TestBeaconState): CachedBeac export function generateCachedElectraState(opts?: TestBeaconState): CachedBeaconStateElectra { const config = getConfig(ForkName.electra); const state = generateState(opts, config); - return createFinalizedCachedBeaconState(state as BeaconStateElectra, { + return createCachedBeaconState(state as BeaconStateElectra, { config: createBeaconConfig(config, state.genesisValidatorsRoot), finalizedPubkey2index: new PubkeyIndexMap(), finalizedIndex2pubkey: [], diff --git a/packages/state-transition/src/cache/stateCache.ts b/packages/state-transition/src/cache/stateCache.ts index 332940bd7cbc..bc110cd8de92 100644 --- a/packages/state-transition/src/cache/stateCache.ts +++ b/packages/state-transition/src/cache/stateCache.ts @@ -138,9 +138,9 @@ export type CachedBeaconStateAllForks = CachedBeaconState; export type CachedBeaconStateExecutions = CachedBeaconState; /** * Create CachedBeaconState computing a new EpochCache instance - * Note: this is intended for finalized state only + * TODO ELECTRA: rename this to createFinalizedCachedBeaconState() as it's intended for finalized state only */ -export function createFinalizedCachedBeaconState( +export function createCachedBeaconState( state: T, immutableData: EpochCacheImmutableData, opts?: EpochCacheOpts @@ -162,9 +162,9 @@ export function createFinalizedCachedBeaconState( * Create a CachedBeaconState given a cached seed state and state bytes * This guarantees that the returned state shares the same tree with the seed state * Check loadState() api for more details - * Note: This only loads unfinalized beacon state + * // TODO: rename to loadUnfinalizedCachedBeaconState() due to ELECTRA */ -export function loadUnfinalizedCachedBeaconState( +export function loadCachedBeaconState( cachedSeedState: T, stateBytes: Uint8Array, opts?: EpochCacheOpts, @@ -186,7 +186,7 @@ export function loadUnfinalizedCachedBeaconState seedState.epochCtx.currentShuffling; - createFinalizedCachedBeaconState( + createCachedBeaconState( migratedState, { config: seedState.config, diff --git a/packages/state-transition/test/unit/cachedBeaconState.test.ts b/packages/state-transition/test/unit/cachedBeaconState.test.ts index 9db65f23d933..4b0c05f00d87 100644 --- a/packages/state-transition/test/unit/cachedBeaconState.test.ts +++ b/packages/state-transition/test/unit/cachedBeaconState.test.ts @@ -4,9 +4,9 @@ import {Epoch, ssz, RootHex} from "@lodestar/types"; import {toHexString} from "@lodestar/utils"; import {config as defaultConfig} from "@lodestar/config/default"; import {createBeaconConfig, createChainForkConfig} from "@lodestar/config"; -import {createFinalizedCachedBeaconStateTest} from "../utils/state.js"; +import {createCachedBeaconStateTest} from "../utils/state.js"; import {PubkeyIndexMap} from "../../src/cache/pubkeyCache.js"; -import {createFinalizedCachedBeaconState, loadUnfinalizedCachedBeaconState} from "../../src/cache/stateCache.js"; +import {createCachedBeaconState, loadCachedBeaconState} from "../../src/cache/stateCache.js"; import {interopPubkeysCached} from "../utils/interop.js"; import {modifyStateSameValidator, newStateWithValidators} from "../utils/capella.js"; import {EpochShuffling, getShufflingDecisionBlock} from "../../src/util/epochShuffling.js"; @@ -14,7 +14,7 @@ import {EpochShuffling, getShufflingDecisionBlock} from "../../src/util/epochShu describe("CachedBeaconState", () => { it("Clone and mutate", () => { const stateView = ssz.altair.BeaconState.defaultViewDU(); - const state1 = createFinalizedCachedBeaconStateTest(stateView); + const state1 = createCachedBeaconStateTest(stateView); const state2 = state1.clone(); state1.slot = 1; @@ -31,7 +31,7 @@ describe("CachedBeaconState", () => { it("Clone and mutate cache pre-Electra", () => { const stateView = ssz.altair.BeaconState.defaultViewDU(); - const state1 = createFinalizedCachedBeaconStateTest(stateView); + const state1 = createCachedBeaconStateTest(stateView); const pubkey1 = fromHexString( "0x84105a985058fc8740a48bf1ede9d223ef09e8c6b1735ba0a55cf4a9ff2ff92376b778798365e488dab07a652eb04576" @@ -56,7 +56,7 @@ describe("CachedBeaconState", () => { /* eslint-disable @typescript-eslint/naming-convention */ it("Clone and mutate cache post-Electra", () => { const stateView = ssz.electra.BeaconState.defaultViewDU(); - const state1 = createFinalizedCachedBeaconStateTest( + const state1 = createCachedBeaconStateTest( stateView, createChainForkConfig({ ALTAIR_FORK_EPOCH: 0, @@ -113,13 +113,13 @@ describe("CachedBeaconState", () => { expect(toHexString(cp1.serialize())).toBe(toHexString(cp2.serialize())); }); - describe("loadUnfinalizedCachedBeaconState", () => { + describe("loadCachedBeaconState", () => { const numValidator = 16; const pubkeys = interopPubkeysCached(2 * numValidator); const stateView = newStateWithValidators(numValidator); const config = createBeaconConfig(defaultConfig, stateView.genesisValidatorsRoot); - const seedState = createFinalizedCachedBeaconState( + const seedState = createCachedBeaconState( stateView, { config, @@ -132,7 +132,7 @@ describe("CachedBeaconState", () => { const capellaStateType = ssz.capella.BeaconState; for (let validatorCountDelta = -numValidator; validatorCountDelta <= numValidator; validatorCountDelta++) { - const testName = `loadUnfinalizedCachedBeaconState - ${validatorCountDelta > 0 ? "more" : "less"} ${Math.abs( + const testName = `loadCachedBeaconState - ${validatorCountDelta > 0 ? "more" : "less"} ${Math.abs( validatorCountDelta )} validators`; it(testName, () => { @@ -189,7 +189,7 @@ describe("CachedBeaconState", () => { // confirm loadState() result const stateBytes = state.serialize(); - const newCachedState = loadUnfinalizedCachedBeaconState(seedState, stateBytes, {skipSyncCommitteeCache: true}); + const newCachedState = loadCachedBeaconState(seedState, stateBytes, {skipSyncCommitteeCache: true}); const newStateBytes = newCachedState.serialize(); expect(newStateBytes).toEqual(stateBytes); expect(newCachedState.hashTreeRoot()).toEqual(state.hashTreeRoot()); @@ -217,7 +217,7 @@ describe("CachedBeaconState", () => { return null; }; - const cachedState = createFinalizedCachedBeaconState( + const cachedState = createCachedBeaconState( state, { config, @@ -231,7 +231,7 @@ describe("CachedBeaconState", () => { expect(newCachedState.epochCtx).toEqual(cachedState.epochCtx); } - // confirm loadUnfinalizedCachedBeaconState() result + // confirm loadCachedBeaconState() result for (let i = 0; i < newCachedState.validators.length; i++) { expect(newCachedState.epochCtx.finalizedPubkey2index.get(newCachedState.validators.get(i).pubkey)).toBe(i); expect(newCachedState.epochCtx.finalizedIndex2pubkey[i].toBytes()).toEqual(pubkeys[i]); diff --git a/packages/state-transition/test/unit/upgradeState.test.ts b/packages/state-transition/test/unit/upgradeState.test.ts index 19af491ce7e6..a130fe21341c 100644 --- a/packages/state-transition/test/unit/upgradeState.test.ts +++ b/packages/state-transition/test/unit/upgradeState.test.ts @@ -6,14 +6,14 @@ import {config as chainConfig} from "@lodestar/config/default"; import {upgradeStateToDeneb} from "../../src/slot/upgradeStateToDeneb.js"; import {upgradeStateToElectra} from "../../src/slot/upgradeStateToElectra.js"; -import {createFinalizedCachedBeaconState} from "../../src/cache/stateCache.js"; +import {createCachedBeaconState} from "../../src/cache/stateCache.js"; import {PubkeyIndexMap} from "../../src/cache/pubkeyCache.js"; describe("upgradeState", () => { it("upgradeStateToDeneb", () => { const capellaState = ssz.capella.BeaconState.defaultViewDU(); const config = getConfig(ForkName.capella); - const stateView = createFinalizedCachedBeaconState( + const stateView = createCachedBeaconState( capellaState, { config: createBeaconConfig(config, capellaState.genesisValidatorsRoot), @@ -28,7 +28,7 @@ describe("upgradeState", () => { it("upgradeStateToElectra", () => { const denebState = ssz.deneb.BeaconState.defaultViewDU(); const config = getConfig(ForkName.deneb); - const stateView = createFinalizedCachedBeaconState( + const stateView = createCachedBeaconState( denebState, { config: createBeaconConfig(config, denebState.genesisValidatorsRoot), diff --git a/packages/state-transition/test/unit/util/cachedBeaconState.test.ts b/packages/state-transition/test/unit/util/cachedBeaconState.test.ts index 6e8378694749..057107b25427 100644 --- a/packages/state-transition/test/unit/util/cachedBeaconState.test.ts +++ b/packages/state-transition/test/unit/util/cachedBeaconState.test.ts @@ -2,13 +2,13 @@ import {describe, it} from "vitest"; import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; -import {createFinalizedCachedBeaconState, PubkeyIndexMap} from "../../../src/index.js"; +import {createCachedBeaconState, PubkeyIndexMap} from "../../../src/index.js"; describe("CachedBeaconState", () => { it("Create empty CachedBeaconState", () => { const emptyState = ssz.phase0.BeaconState.defaultViewDU(); - createFinalizedCachedBeaconState(emptyState, { + createCachedBeaconState(emptyState, { config: createBeaconConfig(config, emptyState.genesisValidatorsRoot), finalizedPubkey2index: new PubkeyIndexMap(), finalizedIndex2pubkey: [], diff --git a/packages/state-transition/test/unit/util/deposit.test.ts b/packages/state-transition/test/unit/util/deposit.test.ts index 2eb889955eb4..e8f7f7a86af8 100644 --- a/packages/state-transition/test/unit/util/deposit.test.ts +++ b/packages/state-transition/test/unit/util/deposit.test.ts @@ -3,12 +3,12 @@ import {ssz} from "@lodestar/types"; import {createChainForkConfig} from "@lodestar/config"; import {MAX_DEPOSITS} from "@lodestar/params"; import {CachedBeaconStateElectra, getEth1DepositCount} from "../../../src/index.js"; -import {createFinalizedCachedBeaconStateTest} from "../../utils/state.js"; +import {createCachedBeaconStateTest} from "../../utils/state.js"; describe("getEth1DepositCount", () => { it("Pre Electra", () => { const stateView = ssz.altair.BeaconState.defaultViewDU(); - const preElectraState = createFinalizedCachedBeaconStateTest(stateView); + const preElectraState = createCachedBeaconStateTest(stateView); if (preElectraState.epochCtx.isAfterElectra()) { throw Error("Not a pre-Electra state"); @@ -26,7 +26,7 @@ describe("getEth1DepositCount", () => { }); it("Post Electra with eth1 deposit", () => { const stateView = ssz.electra.BeaconState.defaultViewDU(); - const postElectraState = createFinalizedCachedBeaconStateTest( + const postElectraState = createCachedBeaconStateTest( stateView, createChainForkConfig({ /* eslint-disable @typescript-eslint/naming-convention */ @@ -60,7 +60,7 @@ describe("getEth1DepositCount", () => { }); it("Post Electra without eth1 deposit", () => { const stateView = ssz.electra.BeaconState.defaultViewDU(); - const postElectraState = createFinalizedCachedBeaconStateTest( + const postElectraState = createCachedBeaconStateTest( stateView, createChainForkConfig({ /* eslint-disable @typescript-eslint/naming-convention */ diff --git a/packages/state-transition/test/utils/capella.ts b/packages/state-transition/test/utils/capella.ts index 1a71e79f82eb..7ef9248a5675 100644 --- a/packages/state-transition/test/utils/capella.ts +++ b/packages/state-transition/test/utils/capella.ts @@ -8,7 +8,7 @@ import { SLOTS_PER_HISTORICAL_ROOT, } from "@lodestar/params"; import {BeaconStateCapella, CachedBeaconStateCapella} from "../../src/index.js"; -import {createFinalizedCachedBeaconStateTest} from "./state.js"; +import {createCachedBeaconStateTest} from "./state.js"; import {mulberry32} from "./rand.js"; import {interopPubkeysCached} from "./interop.js"; @@ -63,11 +63,11 @@ export function getExpectedWithdrawalsTestData(vc: number, opts: WithdrawalOpts) state.commit(); - return createFinalizedCachedBeaconStateTest(state, config, {skipSyncPubkeys: true}); + return createCachedBeaconStateTest(state, config, {skipSyncPubkeys: true}); } export function newStateWithValidators(numValidator: number): BeaconStateCapella { - // use real pubkeys to test loadUnfinalizedCachedBeaconState api + // use real pubkeys to test loadCachedBeaconState api const pubkeys = interopPubkeysCached(numValidator); const capellaStateType = ssz.capella.BeaconState; const stateView = capellaStateType.defaultViewDU(); diff --git a/packages/state-transition/test/utils/state.ts b/packages/state-transition/test/utils/state.ts index 99933718721e..b466d03fd2af 100644 --- a/packages/state-transition/test/utils/state.ts +++ b/packages/state-transition/test/utils/state.ts @@ -17,7 +17,7 @@ import { BeaconStatePhase0, CachedBeaconStateAllForks, BeaconStateAllForks, - createFinalizedCachedBeaconState, + createCachedBeaconState, PubkeyIndexMap, } from "../../src/index.js"; import {BeaconStateCache} from "../../src/cache/stateCache.js"; @@ -89,7 +89,7 @@ export function generateCachedState( opts: TestBeaconState = {} ): CachedBeaconStateAllForks { const state = generateState(opts); - return createFinalizedCachedBeaconState(state, { + return createCachedBeaconState(state, { config: createBeaconConfig(config, state.genesisValidatorsRoot), // This is a test state, there's no need to have a global shared cache of keys finalizedPubkey2index: new PubkeyIndexMap(), @@ -97,12 +97,12 @@ export function generateCachedState( }); } -export function createFinalizedCachedBeaconStateTest( +export function createCachedBeaconStateTest( state: T, configCustom: ChainForkConfig = config, opts?: EpochCacheOpts ): T & BeaconStateCache { - return createFinalizedCachedBeaconState( + return createCachedBeaconState( state, { config: createBeaconConfig(configCustom, state.genesisValidatorsRoot), diff --git a/packages/state-transition/test/utils/testFileCache.ts b/packages/state-transition/test/utils/testFileCache.ts index 83e70040de46..e752f3c36e68 100644 --- a/packages/state-transition/test/utils/testFileCache.ts +++ b/packages/state-transition/test/utils/testFileCache.ts @@ -7,7 +7,7 @@ import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; import {allForks} from "@lodestar/types"; import {CachedBeaconStateAllForks, computeEpochAtSlot} from "../../src/index.js"; import {testCachePath} from "../cache.js"; -import {createFinalizedCachedBeaconStateTest} from "../utils/state.js"; +import {createCachedBeaconStateTest} from "../utils/state.js"; import {getInfuraBeaconUrl} from "./infura.js"; /** @@ -40,10 +40,7 @@ export async function getNetworkCachedState( if (fs.existsSync(filepath)) { const stateSsz = fs.readFileSync(filepath); - return createFinalizedCachedBeaconStateTest( - config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), - config - ); + return createCachedBeaconStateTest(config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), config); } else { const stateSsz = await tryEach([ () => downloadTestFile(fileId), @@ -62,10 +59,7 @@ export async function getNetworkCachedState( ]); fs.writeFileSync(filepath, stateSsz); - return createFinalizedCachedBeaconStateTest( - config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), - config - ); + return createCachedBeaconStateTest(config.getForkTypes(slot).BeaconState.deserializeToViewDU(stateSsz), config); } }