From c100e9251bf11e0041975ca7571859f4bd4459ed Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Mon, 30 Aug 2021 22:06:31 +0200 Subject: [PATCH] Use readonlyValuesListOfLeafNodeStruct in createEpochContext --- .../src/allForks/util/epochContext.ts | 8 +++----- .../src/allForks/util/epochProcess.ts | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/beacon-state-transition/src/allForks/util/epochContext.ts b/packages/beacon-state-transition/src/allForks/util/epochContext.ts index c91f9dc53d4..2064dbe6749 100644 --- a/packages/beacon-state-transition/src/allForks/util/epochContext.ts +++ b/packages/beacon-state-transition/src/allForks/util/epochContext.ts @@ -1,4 +1,4 @@ -import {ByteVector, hash, toHexString, BitList, List, readonlyValues} from "@chainsafe/ssz"; +import {ByteVector, hash, toHexString, BitList, List, readonlyValuesListOfLeafNodeStruct} from "@chainsafe/ssz"; import bls, {CoordType, PublicKey} from "@chainsafe/bls"; import { BLSSignature, @@ -118,13 +118,11 @@ export function createEpochContext( const nextActiveIndices: ValidatorIndex[] = []; const effectiveBalancesArr: Gwei[] = []; - const validators: phase0.Validator[] = Array.from(readonlyValues(state.validators)); + const validators = readonlyValuesListOfLeafNodeStruct(state.validators); const validatorCount = validators.length; for (let i = 0; i < validatorCount; i++) { - // TODO - SLOW CODE - 🐢🐢🐢🐢🐢🐢🐢🐢🐢 - // Use a struct representation in the leaf nodes of the validators tree to have fast reads and slow writes - const validator = validators[i].valueOf() as typeof validators[0]; + const validator = validators[i]; if (isActiveValidator(validator, previousEpoch)) { previousActiveIndices.push(i); diff --git a/packages/beacon-state-transition/src/allForks/util/epochProcess.ts b/packages/beacon-state-transition/src/allForks/util/epochProcess.ts index a9d52fb3784..0798fcd0b38 100644 --- a/packages/beacon-state-transition/src/allForks/util/epochProcess.ts +++ b/packages/beacon-state-transition/src/allForks/util/epochProcess.ts @@ -251,7 +251,7 @@ export function beforeProcessEpoch(state: Cached // To optimize memory each validator node in `state.validators` is represented with a special node type // `BranchNodeStruct` that represents the data as struct internally. This utility grabs the struct data directrly // from the nodes without any extra transformation. The returned `validators` array contains native JS objects. - const validators: phase0.Validator[] = readonlyValuesListOfLeafNodeStruct(state.validators); + const validators = readonlyValuesListOfLeafNodeStruct(state.validators); const validatorCount = validators.length; for (let i = 0; i < validatorCount; i++) {