Skip to content

Commit

Permalink
Use readonlyValuesListOfLeafNodeStruct in createEpochContext
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Aug 30, 2021
1 parent 714bcd7 commit c100e92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export function beforeProcessEpoch<T extends allForks.BeaconState>(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++) {
Expand Down

0 comments on commit c100e92

Please sign in to comment.