Skip to content

Commit

Permalink
chore: revert sszBytes utils
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jan 9, 2024
1 parent 3256b6f commit d1a3bd3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
21 changes: 1 addition & 20 deletions packages/beacon-node/src/util/sszBytes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {BitArray, deserializeUint8ArrayBitListFromBytes} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {BLSSignature, RootHex, Slot, ssz} from "@lodestar/types";
import {BLSSignature, RootHex, Slot} from "@lodestar/types";
import {toHex} from "@lodestar/utils";
import {BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB} from "@lodestar/params";
import {getStateTypeFromBytes} from "./multifork.js";

export type BlockRootHex = RootHex;
export type AttDataBase64 = string;
Expand Down Expand Up @@ -202,23 +200,6 @@ export function getSlotFromBlobSidecarSerialized(data: Uint8Array): Slot | null
return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_SIGNED_BLOB_SIDECAR);
}

type BeaconStateType =
| typeof ssz.phase0.BeaconState
| typeof ssz.altair.BeaconState
| typeof ssz.bellatrix.BeaconState
| typeof ssz.capella.BeaconState
| typeof ssz.deneb.BeaconState;

export function getValidatorsBytesFromStateBytes(config: ChainForkConfig, stateBytes: Uint8Array): Uint8Array {
const stateType = getStateTypeFromBytes(config, stateBytes) as BeaconStateType;
const dataView = new DataView(stateBytes.buffer, stateBytes.byteOffset, stateBytes.byteLength);
const fieldRanges = stateType.getFieldRanges(dataView, 0, stateBytes.length);
const allFields = Object.keys(stateType.fields);
const validatorsFieldIndex = allFields.indexOf("validators");
const validatorsRange = fieldRanges[validatorsFieldIndex];
return stateBytes.slice(validatorsRange.start, validatorsRange.end);
}

function getSlotFromOffset(data: Uint8Array, offset: number): Slot {
// TODO: Optimize
const dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
Expand Down
13 changes: 0 additions & 13 deletions packages/state-transition/src/util/sszBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ const SLOT_BYTE_COUNT = 8;
*/
export const VALIDATOR_BYTES_SIZE = 121;

const BLS_PUBKEY_SIZE = 48;

export function getWithdrawalCredentialFirstByteFromValidatorBytes(
validatorBytes: Uint8Array,
validatorIndex: number
): number | null {
if (validatorBytes.length < VALIDATOR_BYTES_SIZE * (validatorIndex + 1)) {
return null;
}

return validatorBytes[VALIDATOR_BYTES_SIZE * validatorIndex + BLS_PUBKEY_SIZE];
}

/**
* 8 + 32 = 40
* ```
Expand Down

0 comments on commit d1a3bd3

Please sign in to comment.