Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve browser support #6384

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/light-client/src/transport/rest.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import EventEmitter from "events";
import StrictEventEmitter from "strict-event-emitter-types";
import {allForks, SyncPeriod} from "@lodestar/types";
import {Api, ApiError, routes} from "@lodestar/api";
import {ForkName} from "@lodestar/params";
import {LightClientTransport} from "./interface.js";
import {type StrictEventEmitter} from "strict-event-emitter-types";
import {type allForks, type SyncPeriod} from "@lodestar/types";
import {type Api, ApiError, routes} from "@lodestar/api";
import {type ForkName} from "@lodestar/params";
import {type LightClientTransport} from "./interface.js";

export type LightClientRestEvents = {
[routes.events.EventType.lightClientFinalityUpdate]: allForks.LightClientFinalityUpdate;
[routes.events.EventType.lightClientOptimisticUpdate]: allForks.LightClientOptimisticUpdate;
};

type RestEvents = StrictEventEmitter<EventEmitter, LightClientRestEvents>;

export class LightClientRestTransport extends (EventEmitter as {new (): RestEvents}) implements LightClientTransport {
export class LightClientRestTransport implements LightClientTransport {
private controller = new AbortController();
private readonly eventEmitter: StrictEventEmitter<EventEmitter, LightClientRestEvents> = new EventEmitter();
private subscribedEventstream = false;

constructor(private readonly api: Api) {
super();
}
constructor(private readonly api: Api) {}

async getUpdates(
startPeriod: SyncPeriod,
Expand Down
4 changes: 3 additions & 1 deletion packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ presetStatus.frozen = true;
* The active preset can be manually overridden with `setActivePreset`
*/
export const ACTIVE_PRESET =
userSelectedPreset ?? PresetName[process?.env?.LODESTAR_PRESET as PresetName] ?? PresetName.mainnet;
userSelectedPreset ??
(typeof process !== "undefined" ? PresetName[process?.env?.LODESTAR_PRESET as PresetName] : undefined) ??
PresetName.mainnet;
export const activePreset = {...presets[ACTIVE_PRESET], ...userOverrides};

// These variables must be exported individually and explicitly
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/util/sszBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const VALIDATOR_BYTES_SIZE = 121;
*/
const SLOT_BYTES_POSITION_IN_STATE = 40;

export function getForkFromStateBytes(config: ChainForkConfig, bytes: Buffer | Uint8Array): ForkSeq {
export function getForkFromStateBytes(config: ChainForkConfig, bytes: Uint8Array): ForkSeq {
const slot = bytesToInt(bytes.subarray(SLOT_BYTES_POSITION_IN_STATE, SLOT_BYTES_POSITION_IN_STATE + SLOT_BYTE_COUNT));
return config.getForkSeq(slot);
}

export function getStateTypeFromBytes(
config: ChainForkConfig,
bytes: Buffer | Uint8Array
bytes: Uint8Array
): allForks.AllForksSSZTypes["BeaconState"] {
const slot = getStateSlotFromBytes(bytes);
return config.getForkTypes(slot).BeaconState;
Expand Down