From 4ec9d82bf2925f125153821050c44ea5307996c3 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 18 Mar 2024 13:12:22 +0700 Subject: [PATCH 1/8] feat: implement ValidatorNodeStructType --- packages/types/src/phase0/sszTypes.ts | 20 +----- packages/types/src/phase0/validator.ts | 67 +++++++++++++++++++ .../types/test/unit/phase0/sszTypes.test.ts | 24 +++++++ 3 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 packages/types/src/phase0/validator.ts create mode 100644 packages/types/test/unit/phase0/sszTypes.test.ts diff --git a/packages/types/src/phase0/sszTypes.ts b/packages/types/src/phase0/sszTypes.ts index 6bafdb8fc3a7..4586a46054ed 100644 --- a/packages/types/src/phase0/sszTypes.ts +++ b/packages/types/src/phase0/sszTypes.ts @@ -2,12 +2,12 @@ import { BitListType, BitVectorType, ContainerType, - ContainerNodeStructType, ListBasicType, ListCompositeType, VectorBasicType, ListUintNum64Type, VectorCompositeType, + ListUintNum64Type, } from "@chainsafe/ssz"; import { ATTESTATION_SUBNET_COUNT, @@ -29,15 +29,14 @@ import { VALIDATOR_REGISTRY_LIMIT, } from "@lodestar/params"; import * as primitiveSsz from "../primitive/sszTypes.js"; +import {ValidatorNodeStruct} from "./validator.js"; const { - Boolean, Bytes32, UintNum64, UintBn64, Slot, Epoch, - EpochInf, CommitteeIndex, ValidatorIndex, Root, @@ -226,21 +225,6 @@ export const HistoricalBatchRoots = new ContainerType( {typeName: "HistoricalBatchRoots", jsonCase: "eth2"} ); -export const ValidatorContainer = new ContainerType( - { - pubkey: BLSPubkey, - withdrawalCredentials: Bytes32, - effectiveBalance: UintNum64, - slashed: Boolean, - activationEligibilityEpoch: EpochInf, - activationEpoch: EpochInf, - exitEpoch: EpochInf, - withdrawableEpoch: EpochInf, - }, - {typeName: "Validator", jsonCase: "eth2"} -); - -export const ValidatorNodeStruct = new ContainerNodeStructType(ValidatorContainer.fields, ValidatorContainer.opts); // The main Validator type is the 'ContainerNodeStructType' version export const Validator = ValidatorNodeStruct; diff --git a/packages/types/src/phase0/validator.ts b/packages/types/src/phase0/validator.ts new file mode 100644 index 000000000000..f5d54507990f --- /dev/null +++ b/packages/types/src/phase0/validator.ts @@ -0,0 +1,67 @@ +import {ByteViews, ContainerNodeStructType, ValueOfFields} from "@chainsafe/ssz"; +import * as primitiveSsz from "../primitive/sszTypes.js"; + +const {Boolean, Bytes32, UintNum64, BLSPubkey, EpochInf} = primitiveSsz; + +const NUMBER_2_POW_32 = 2 ** 32; + +export const ValidatorType = { + pubkey: BLSPubkey, + withdrawalCredentials: Bytes32, + effectiveBalance: UintNum64, + slashed: Boolean, + activationEligibilityEpoch: EpochInf, + activationEpoch: EpochInf, + exitEpoch: EpochInf, + withdrawableEpoch: EpochInf, +}; + +/** + * Improve serialization performance for state.validators.serialize(); + */ +export class ValidatorNodeStructType extends ContainerNodeStructType { + constructor() { + super(ValidatorType, {typeName: "Validator", jsonCase: "eth2"}); + } + + value_serializeToBytes( + {uint8Array: output, dataView}: ByteViews, + offset: number, + validator: ValueOfFields + ): number { + output.set(validator.pubkey, offset); + offset += 48; + output.set(validator.withdrawalCredentials, offset); + offset += 32; + const {effectiveBalance, activationEligibilityEpoch, activationEpoch, exitEpoch, withdrawableEpoch} = validator; + // TODO: writeUintNum64? + dataView.setUint32(offset, effectiveBalance & 0xffffffff, true); + offset += 4; + dataView.setUint32(offset, (effectiveBalance / NUMBER_2_POW_32) & 0xffffffff, true); + offset += 4; + output[offset] = validator.slashed ? 1 : 0; + offset += 1; + offset = writeEpochInf(dataView, offset, activationEligibilityEpoch); + offset = writeEpochInf(dataView, offset, activationEpoch); + offset = writeEpochInf(dataView, offset, exitEpoch); + offset = writeEpochInf(dataView, offset, withdrawableEpoch); + + return offset; + } +} + +function writeEpochInf(dataView: DataView, offset: number, value: number): number { + if (value === Infinity) { + dataView.setUint32(offset, 0xffffffff, true); + offset += 4; + dataView.setUint32(offset, 0xffffffff, true); + offset += 4; + } else { + dataView.setUint32(offset, value & 0xffffffff, true); + offset += 4; + dataView.setUint32(offset, (value / NUMBER_2_POW_32) & 0xffffffff, true); + offset += 4; + } + return offset; +} +export const ValidatorNodeStruct = new ValidatorNodeStructType(); diff --git a/packages/types/test/unit/phase0/sszTypes.test.ts b/packages/types/test/unit/phase0/sszTypes.test.ts new file mode 100644 index 000000000000..c4508bd6fa9a --- /dev/null +++ b/packages/types/test/unit/phase0/sszTypes.test.ts @@ -0,0 +1,24 @@ +import {ContainerType} from "@chainsafe/ssz"; +import {describe, it, expect} from "vitest"; +import {ssz} from "../../../src/index.js"; +import {ValidatorType} from "../../../src/phase0/validator.js"; + +const ValidatorContainer = new ContainerType(ValidatorType, {typeName: "Validator", jsonCase: "eth2"}); + +describe("Validator ssz types", function () { + it("should serialize to the same value", () => { + const validator = ValidatorContainer.defaultValue(); + validator.activationEligibilityEpoch = 10; + validator.activationEpoch = 11; + validator.exitEpoch = Infinity; + validator.slashed = false; + validator.effectiveBalance = 31000000000; + validator.withdrawableEpoch = 13; + validator.pubkey = Buffer.alloc(48, 100); + validator.withdrawalCredentials = Buffer.alloc(32, 100); + + const serialized = ValidatorContainer.serialize(validator); + const serialized2 = ssz.phase0.Validator.serialize(validator); + expect(serialized).toEqual(serialized2); + }); +}); From 74b2b6a5b1b93d964f57c78ba4eb532c0ab25770 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 19 Mar 2024 13:37:08 +0700 Subject: [PATCH 2/8] chore: update serializeState.test.ts perf test --- .../test/perf/util/serializeState.test.ts | 27 ++++++++++++++++--- packages/types/src/phase0/validator.ts | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/state-transition/test/perf/util/serializeState.test.ts b/packages/state-transition/test/perf/util/serializeState.test.ts index 5bd6c6b38e6a..add85859b492 100644 --- a/packages/state-transition/test/perf/util/serializeState.test.ts +++ b/packages/state-transition/test/perf/util/serializeState.test.ts @@ -1,6 +1,6 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {ssz} from "@lodestar/types"; -import {generatePerfTestCachedStateAltair} from "../util.js"; +import {cachedStateAltairPopulateCaches, generatePerfTestCachedStateAltair} from "../util.js"; /** * This shows different statistics between allocating memory once vs every time. @@ -13,8 +13,9 @@ describe.skip("serialize state and validators", function () { // increasing this may have different statistics due to gc time minMs: 60_000, }); - const valicatorCount = 1_500_000; - const seedState = generatePerfTestCachedStateAltair({vc: 1_500_000, goBackOneSlot: false}); + // change to 170_000 for holesky size + const valicatorCount = 20_000; + const seedState = generatePerfTestCachedStateAltair({vc: valicatorCount, goBackOneSlot: false}); /** * Allocate memory every time, on a Mac M1: @@ -35,6 +36,17 @@ describe.skip("serialize state and validators", function () { }, }); + // now cache nodes + cachedStateAltairPopulateCaches(seedState); + + itBench({ + id: `serialize state ${valicatorCount} validators using new serializeToBytes() method`, + fn: () => { + stateBytes.fill(0); + seedState.serializeToBytes({uint8Array: stateBytes, dataView: stateDataView}, 0); + }, + }); + itBench({ id: `serialize altair state ${valicatorCount} validators`, fn: () => { @@ -80,7 +92,7 @@ describe.skip("serialize state and validators", function () { * this is 3x faster than the previous approach. */ const NUMBER_2_POW_32 = 2 ** 32; - const output = new Uint8Array(121 * 1_500_000); + const output = new Uint8Array(121 * valicatorCount); const dataView = new DataView(output.buffer, output.byteOffset, output.byteLength); // this caches validators nodes which is what happen after we run a state transition const validators = seedState.validators.getAllReadonlyValues(); @@ -119,4 +131,11 @@ describe.skip("serialize state and validators", function () { } }, }); + + itBench({ + id: `serialize ${valicatorCount} validators from state `, + fn: () => { + seedState.validators.serializeToBytes({uint8Array: output, dataView}, 0); + }, + }); }); diff --git a/packages/types/src/phase0/validator.ts b/packages/types/src/phase0/validator.ts index f5d54507990f..fc20457baee5 100644 --- a/packages/types/src/phase0/validator.ts +++ b/packages/types/src/phase0/validator.ts @@ -34,7 +34,7 @@ export class ValidatorNodeStructType extends ContainerNodeStructType Date: Tue, 19 Mar 2024 13:47:39 +0700 Subject: [PATCH 3/8] fix: use ViewDU.serializeToBytes() api for PersistentCPCache --- .../src/chain/stateCache/persistentCheckpointsCache.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 4aea5ad53a6a..5ee65819ae0f 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -649,8 +649,8 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { this.metrics?.persistedStateAllocCount.inc(); stateBytes = state.serialize(); } - persistedKey = await this.datastore.write(cpPersist, stateBytes); timer?.(); + persistedKey = await this.datastore.write(cpPersist, stateBytes); } persistCount++; this.logger.verbose("Pruned checkpoint state from memory and persisted to disk", { @@ -723,7 +723,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { if (bufferWithKey) { const stateBytes = bufferWithKey.buffer; const dataView = new DataView(stateBytes.buffer, stateBytes.byteOffset, stateBytes.byteLength); - state.type.tree_serializeToBytes({uint8Array: stateBytes, dataView}, 0, state.node); + state.serializeToBytes({uint8Array: stateBytes, dataView}, 0); return bufferWithKey; } } @@ -736,10 +736,8 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { * - As monitored on holesky as of Jan 2024, it helps save ~500ms state reload time (4.3s vs 3.8s) * - Also `serializeState.test.ts` perf test shows a lot of differences allocating validators bytes once vs every time, * This is 2x - 3x faster than allocating memory every time. - * TODO: consider serializing validators manually like in `serializeState.test.ts` perf test, this could be 3x faster than this */ private serializeStateValidators(state: CachedBeaconStateAllForks): BufferWithKey | null { - // const validatorsSszTimer = this.metrics?.stateReloadValidatorsSszDuration.startTimer(); const type = state.type.fields.validators; const size = type.tree_serializedSize(state.validators.node); if (this.bufferPool) { @@ -747,7 +745,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { if (bufferWithKey) { const validatorsBytes = bufferWithKey.buffer; const dataView = new DataView(validatorsBytes.buffer, validatorsBytes.byteOffset, validatorsBytes.byteLength); - type.tree_serializeToBytes({uint8Array: validatorsBytes, dataView}, 0, state.validators.node); + state.validators.serializeToBytes({uint8Array: validatorsBytes, dataView}, 0); return bufferWithKey; } } From 78eb7682f611b215b6b43533a44842b1e24a8aff Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 19 Mar 2024 13:53:27 +0700 Subject: [PATCH 4/8] fix: merge issue --- packages/types/src/phase0/sszTypes.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/types/src/phase0/sszTypes.ts b/packages/types/src/phase0/sszTypes.ts index 4586a46054ed..9eb2a13e5fae 100644 --- a/packages/types/src/phase0/sszTypes.ts +++ b/packages/types/src/phase0/sszTypes.ts @@ -7,7 +7,6 @@ import { VectorBasicType, ListUintNum64Type, VectorCompositeType, - ListUintNum64Type, } from "@chainsafe/ssz"; import { ATTESTATION_SUBNET_COUNT, From 3c0e644003c2428f9a94e8a43c59d6cf524612d6 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 19 Mar 2024 15:12:59 +0700 Subject: [PATCH 5/8] chore: make constants --- packages/types/src/phase0/validator.ts | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/types/src/phase0/validator.ts b/packages/types/src/phase0/validator.ts index fc20457baee5..fd98dca0ecbd 100644 --- a/packages/types/src/phase0/validator.ts +++ b/packages/types/src/phase0/validator.ts @@ -3,8 +3,17 @@ import * as primitiveSsz from "../primitive/sszTypes.js"; const {Boolean, Bytes32, UintNum64, BLSPubkey, EpochInf} = primitiveSsz; +// this is to work with uint32, see https://github.com/ChainSafe/ssz/blob/ssz-v0.15.1/packages/ssz/src/type/uint.ts const NUMBER_2_POW_32 = 2 ** 32; +/** + * Below constants are respective to their ssz type in `ValidatorType`. + */ +const UINT32_SIZE = 4; +const PUBKEY_SIZE = 48; +const WITHDRAWAL_CREDENTIALS_SIZE = 32; +const SLASHED_SIZE = 1; + export const ValidatorType = { pubkey: BLSPubkey, withdrawalCredentials: Bytes32, @@ -30,17 +39,17 @@ export class ValidatorNodeStructType extends ContainerNodeStructType ): number { output.set(validator.pubkey, offset); - offset += 48; + offset += PUBKEY_SIZE; output.set(validator.withdrawalCredentials, offset); - offset += 32; + offset += WITHDRAWAL_CREDENTIALS_SIZE; const {effectiveBalance, activationEligibilityEpoch, activationEpoch, exitEpoch, withdrawableEpoch} = validator; // effectiveBalance is UintNum64 dataView.setUint32(offset, effectiveBalance & 0xffffffff, true); - offset += 4; + offset += UINT32_SIZE; dataView.setUint32(offset, (effectiveBalance / NUMBER_2_POW_32) & 0xffffffff, true); - offset += 4; + offset += UINT32_SIZE; output[offset] = validator.slashed ? 1 : 0; - offset += 1; + offset += SLASHED_SIZE; offset = writeEpochInf(dataView, offset, activationEligibilityEpoch); offset = writeEpochInf(dataView, offset, activationEpoch); offset = writeEpochInf(dataView, offset, exitEpoch); @@ -53,14 +62,14 @@ export class ValidatorNodeStructType extends ContainerNodeStructType Date: Tue, 26 Mar 2024 10:23:55 +0700 Subject: [PATCH 6/8] fix: address PR comments --- .../stateCache/persistentCheckpointsCache.ts | 2 +- .../src/metrics/metrics/lodestar.ts | 6 ++-- .../test/perf/util/serializeState.test.ts | 2 +- packages/types/src/phase0/validator.ts | 2 +- .../types/test/unit/phase0/sszTypes.test.ts | 31 ++++++++++++------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 5ee65819ae0f..30d3d7b5b816 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -640,7 +640,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { this.metrics?.statePersistSecFromSlot.observe(this.clock?.secFromSlot(this.clock?.currentSlot ?? 0) ?? 0); const cpPersist = {epoch: epoch, root: epochBoundaryRoot}; { - const timer = this.metrics?.statePersistDuration.startTimer(); + const timer = this.metrics?.stateSszDuration.startTimer(); // automatically free the buffer pool after this scope using stateBytesWithKey = this.serializeState(state); let stateBytes = stateBytesWithKey?.buffer; diff --git a/packages/beacon-node/src/metrics/metrics/lodestar.ts b/packages/beacon-node/src/metrics/metrics/lodestar.ts index 4f82969cff81..771377acaac4 100644 --- a/packages/beacon-node/src/metrics/metrics/lodestar.ts +++ b/packages/beacon-node/src/metrics/metrics/lodestar.ts @@ -1195,9 +1195,9 @@ export function createLodestarMetrics( help: "Histogram of cloned count per state every time state.clone() is called", buckets: [1, 2, 5, 10, 50, 250], }), - statePersistDuration: register.histogram({ - name: "lodestar_cp_state_cache_state_persist_seconds", - help: "Histogram of time to persist state to db", + stateSszDuration: register.histogram({ + name: "lodestar_cp_state_cache_state_ssz_seconds", + help: "Histogram of time to serialize state to db", buckets: [0.1, 0.5, 1, 2, 3, 4], }), statePruneFromMemoryCount: register.gauge({ diff --git a/packages/state-transition/test/perf/util/serializeState.test.ts b/packages/state-transition/test/perf/util/serializeState.test.ts index add85859b492..518871bd6a82 100644 --- a/packages/state-transition/test/perf/util/serializeState.test.ts +++ b/packages/state-transition/test/perf/util/serializeState.test.ts @@ -13,7 +13,7 @@ describe.skip("serialize state and validators", function () { // increasing this may have different statistics due to gc time minMs: 60_000, }); - // change to 170_000 for holesky size + // change to 1_700_000 for holesky size const valicatorCount = 20_000; const seedState = generatePerfTestCachedStateAltair({vc: valicatorCount, goBackOneSlot: false}); diff --git a/packages/types/src/phase0/validator.ts b/packages/types/src/phase0/validator.ts index fd98dca0ecbd..3c2f72aac509 100644 --- a/packages/types/src/phase0/validator.ts +++ b/packages/types/src/phase0/validator.ts @@ -6,7 +6,7 @@ const {Boolean, Bytes32, UintNum64, BLSPubkey, EpochInf} = primitiveSsz; // this is to work with uint32, see https://github.com/ChainSafe/ssz/blob/ssz-v0.15.1/packages/ssz/src/type/uint.ts const NUMBER_2_POW_32 = 2 ** 32; -/** +/* * Below constants are respective to their ssz type in `ValidatorType`. */ const UINT32_SIZE = 4; diff --git a/packages/types/test/unit/phase0/sszTypes.test.ts b/packages/types/test/unit/phase0/sszTypes.test.ts index c4508bd6fa9a..0cda0fc888f6 100644 --- a/packages/types/test/unit/phase0/sszTypes.test.ts +++ b/packages/types/test/unit/phase0/sszTypes.test.ts @@ -7,18 +7,25 @@ const ValidatorContainer = new ContainerType(ValidatorType, {typeName: "Validato describe("Validator ssz types", function () { it("should serialize to the same value", () => { - const validator = ValidatorContainer.defaultValue(); - validator.activationEligibilityEpoch = 10; - validator.activationEpoch = 11; - validator.exitEpoch = Infinity; - validator.slashed = false; - validator.effectiveBalance = 31000000000; - validator.withdrawableEpoch = 13; - validator.pubkey = Buffer.alloc(48, 100); - validator.withdrawalCredentials = Buffer.alloc(32, 100); + const seedValidator = { + activationEligibilityEpoch: 10, + activationEpoch: 11, + exitEpoch: Infinity, + slashed: false, + withdrawableEpoch: 13, + pubkey: Buffer.alloc(48, 100), + withdrawalCredentials: Buffer.alloc(32, 100), + }; - const serialized = ValidatorContainer.serialize(validator); - const serialized2 = ssz.phase0.Validator.serialize(validator); - expect(serialized).toEqual(serialized2); + const validators = [ + {...seedValidator, effectiveBalance: 31000000000, slashed: false}, + {...seedValidator, effectiveBalance: 32000000000, slashed: true}, + ]; + + for (const validator of validators) { + const serialized = ValidatorContainer.serialize(validator); + const serialized2 = ssz.phase0.Validator.serialize(validator); + expect(serialized).toEqual(serialized2); + } }); }); From 121edfe328cef373f27d6e800ef1c5dfa6e849e3 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 26 Mar 2024 10:41:27 +0700 Subject: [PATCH 7/8] fix: merge unstable --- .../test/e2e/chain/stateCache/nHistoricalStates.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts index 6d35329ba272..c48a00455f87 100644 --- a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts +++ b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts @@ -399,10 +399,10 @@ describe( )?.value ).toEqual(reloadCount); - const persistMetricValues = await (followupBn.metrics?.cpStateCache.statePersistDuration as Histogram).get(); + const stateSszMetricValues = await (followupBn.metrics?.cpStateCache.stateSszDuration as Histogram).get(); expect( - persistMetricValues?.values.find( - (value) => value.metricName === "lodestar_cp_state_cache_state_persist_seconds_count" + stateSszMetricValues?.values.find( + (value) => value.metricName === "lodestar_cp_state_cache_state_ssz_seconds_count" )?.value ).toEqual(persistCount); From f8c669b02885eb2c997a823046a8eb8b227539bd Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 27 Mar 2024 08:31:24 +0700 Subject: [PATCH 8/8] chore: refactor metric name --- .../src/chain/stateCache/persistentCheckpointsCache.ts | 2 +- packages/beacon-node/src/metrics/metrics/lodestar.ts | 4 ++-- .../test/e2e/chain/stateCache/nHistoricalStates.test.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 30d3d7b5b816..3b38123de838 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -640,7 +640,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { this.metrics?.statePersistSecFromSlot.observe(this.clock?.secFromSlot(this.clock?.currentSlot ?? 0) ?? 0); const cpPersist = {epoch: epoch, root: epochBoundaryRoot}; { - const timer = this.metrics?.stateSszDuration.startTimer(); + const timer = this.metrics?.stateSerializeDuration.startTimer(); // automatically free the buffer pool after this scope using stateBytesWithKey = this.serializeState(state); let stateBytes = stateBytesWithKey?.buffer; diff --git a/packages/beacon-node/src/metrics/metrics/lodestar.ts b/packages/beacon-node/src/metrics/metrics/lodestar.ts index 771377acaac4..e6b4d2f5a683 100644 --- a/packages/beacon-node/src/metrics/metrics/lodestar.ts +++ b/packages/beacon-node/src/metrics/metrics/lodestar.ts @@ -1195,8 +1195,8 @@ export function createLodestarMetrics( help: "Histogram of cloned count per state every time state.clone() is called", buckets: [1, 2, 5, 10, 50, 250], }), - stateSszDuration: register.histogram({ - name: "lodestar_cp_state_cache_state_ssz_seconds", + stateSerializeDuration: register.histogram({ + name: "lodestar_cp_state_cache_state_serialize_seconds", help: "Histogram of time to serialize state to db", buckets: [0.1, 0.5, 1, 2, 3, 4], }), diff --git a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts index c48a00455f87..fe6293519596 100644 --- a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts +++ b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts @@ -399,10 +399,10 @@ describe( )?.value ).toEqual(reloadCount); - const stateSszMetricValues = await (followupBn.metrics?.cpStateCache.stateSszDuration as Histogram).get(); + const stateSszMetricValues = await (followupBn.metrics?.cpStateCache.stateSerializeDuration as Histogram).get(); expect( stateSszMetricValues?.values.find( - (value) => value.metricName === "lodestar_cp_state_cache_state_ssz_seconds_count" + (value) => value.metricName === "lodestar_cp_state_cache_state_serialize_seconds_count" )?.value ).toEqual(persistCount);