Skip to content

Commit

Permalink
chore: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Feb 26, 2024
1 parent 405fef5 commit 827ec62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export function getNotSeenValidatorsFn(state: CachedBeaconStateAllForks): GetNot
state
);

return (epoch: Epoch, committee: number[] | Uint32Array) => {
return (epoch: Epoch, committee: Uint32Array) => {
const participants =
epoch === stateEpoch ? currentEpochParticipants : epoch === stateEpoch - 1 ? previousEpochParticipants : null;
if (participants === null) {
Expand Down Expand Up @@ -426,7 +426,7 @@ export function getNotSeenValidatorsFn(state: CachedBeaconStateAllForks): GetNot
const currentParticipation = altairState.currentEpochParticipation.getAll();
const stateEpoch = computeEpochAtSlot(state.slot);

return (epoch: Epoch, committee: number[] | Uint32Array) => {
return (epoch: Epoch, committee: Uint32Array) => {
const participationStatus =
epoch === stateEpoch ? currentParticipation : epoch === stateEpoch - 1 ? previousParticipation : null;

Expand Down
14 changes: 10 additions & 4 deletions packages/state-transition/src/util/shuffle.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {digest} from "@chainsafe/as-sha256";
import {SHUFFLE_ROUND_COUNT} from "@lodestar/params";
import {ValidatorIndex, Bytes32} from "@lodestar/types";
import {Bytes32} from "@lodestar/types";
import {assert, bytesToBigInt} from "@lodestar/utils";

// ArrayLike<number> but with settable indices
type Shuffleable = {
readonly length: number;
[index: number]: number;
};

// ShuffleList shuffles a list, using the given seed for randomness. Mutates the input list.
export function shuffleList(input: Uint32Array | ValidatorIndex[], seed: Bytes32): void {
export function shuffleList(input: Shuffleable, seed: Bytes32): void {
innerShuffleList(input, seed, true);
}

// UnshuffleList undoes a list shuffling using the seed of the shuffling. Mutates the input list.
export function unshuffleList(input: Uint32Array | ValidatorIndex[], seed: Bytes32): void {
export function unshuffleList(input: Shuffleable, seed: Bytes32): void {
innerShuffleList(input, seed, false);
}

Expand Down Expand Up @@ -70,7 +76,7 @@ function setPositionUint32(value: number, buf: Buffer): void {
}

// Shuffles or unshuffles, depending on the `dir` (true for shuffling, false for unshuffling
function innerShuffleList(input: Uint32Array | ValidatorIndex[], seed: Bytes32, dir: boolean): void {
function innerShuffleList(input: Shuffleable, seed: Bytes32, dir: boolean): void {
if (input.length <= 1) {
// nothing to (un)shuffle
return;
Expand Down

0 comments on commit 827ec62

Please sign in to comment.