Skip to content

Commit

Permalink
Renamed LightclientHeaderUpdate -> LightclientOptimisticHeaderUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo authored and dapplion committed Jun 26, 2022
1 parent ed1c0aa commit ba36147
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/beacon/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {RouteDef, TypeJson} from "../../utils/index.js";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

export type LightclientHeaderUpdate = {
export type LightclientOptimisticHeaderUpdate = {
syncAggregate: altair.SyncAggregate;
attestedHeader: phase0.BeaconBlockHeader;
};
Expand Down Expand Up @@ -63,7 +63,7 @@ export type EventData = {
newHeadState: RootHex;
epoch: Epoch;
};
[EventType.lightclientOptimisticUpdate]: LightclientHeaderUpdate;
[EventType.lightclientOptimisticUpdate]: LightclientOptimisticHeaderUpdate;
[EventType.lightclientFinalizedUpdate]: LightclientFinalizedUpdate;
};

Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/beacon/routes/lightclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
ReqEmpty,
} from "../../utils/index.js";
import {queryParseProofPathsArr, querySerializeProofPathsArr} from "../../utils/serdes.js";
import {LightclientHeaderUpdate, LightclientFinalizedUpdate} from "./events.js";
import {LightclientOptimisticHeaderUpdate, LightclientFinalizedUpdate} from "./events.js";

// Re-export for convenience when importing routes.lightclient.LightclientHeaderUpdate
export {LightclientHeaderUpdate, LightclientFinalizedUpdate};
// Re-export for convenience when importing routes.lightclient.LightclientOptimisticHeaderUpdate
export {LightclientOptimisticHeaderUpdate, LightclientFinalizedUpdate};

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down Expand Up @@ -46,7 +46,7 @@ export type Api = {
* Returns the latest optimistic head update available. Clients should use the SSE type `light_client_optimistic_update`
* unless to get the very first head update after syncing, or if SSE are not supported by the server.
*/
getOptimisticUpdate(): Promise<{data: LightclientHeaderUpdate}>;
getOptimisticUpdate(): Promise<{data: LightclientOptimisticHeaderUpdate}>;
getFinalityUpdate(): Promise<{data: LightclientFinalizedUpdate}>;
/**
* Fetch a bootstrapping state with a proof to a trusted block root.
Expand Down
2 changes: 1 addition & 1 deletion packages/light-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class Lightclient {
* Processes new optimistic header updates in only known synced sync periods.
* This headerUpdate may update the head if there's enough participation.
*/
private processOptimisticUpdate(headerUpdate: routes.events.LightclientHeaderUpdate): void {
private processOptimisticUpdate(headerUpdate: routes.events.LightclientOptimisticHeaderUpdate): void {
const {attestedHeader: header, syncAggregate} = headerUpdate;

// Prevent registering updates for slots to far ahead
Expand Down
4 changes: 2 additions & 2 deletions packages/light-client/test/lightclientApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class LightclientServerApi implements routes.lightclient.Api {
readonly states = new Map<RootHex, BeaconStateAltair>();
readonly updates = new Map<SyncPeriod, altair.LightClientUpdate>();
readonly snapshots = new Map<RootHex, routes.lightclient.LightclientSnapshotWithProof>();
latestHeadUpdate: routes.lightclient.LightclientHeaderUpdate | null = null;
latestHeadUpdate: routes.lightclient.LightclientOptimisticHeaderUpdate | null = null;
finalized: routes.lightclient.LightclientFinalizedUpdate | null = null;

async getStateProof(stateId: string, paths: JsonPath[]): Promise<{data: Proof}> {
Expand All @@ -63,7 +63,7 @@ export class LightclientServerApi implements routes.lightclient.Api {
return {data: updates};
}

async getOptimisticUpdate(): Promise<{data: routes.lightclient.LightclientHeaderUpdate}> {
async getOptimisticUpdate(): Promise<{data: routes.lightclient.LightclientOptimisticHeaderUpdate}> {
if (!this.latestHeadUpdate) throw Error("No latest head update");
return {data: this.latestHeadUpdate};
}
Expand Down
3 changes: 2 additions & 1 deletion packages/light-client/test/unit/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("Lightclient sync", () => {

// So the first call to getLatestHeadUpdate() doesn't error, store the latest snapshot as latest header update
lightclientServerApi.latestHeadUpdate = committeeUpdateToLatestHeadUpdate(lastInMap(lightclientServerApi.updates));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
lightclientServerApi.finalized = committeeUpdateToLatestFinalizedHeadUpdate(
lastInMap(lightclientServerApi.updates)
);
Expand Down Expand Up @@ -130,7 +131,7 @@ describe("Lightclient sync", () => {
bodyRoot: SOME_HASH,
};

const headUpdate: routes.lightclient.LightclientHeaderUpdate = {
const headUpdate: routes.lightclient.LightclientOptimisticHeaderUpdate = {
attestedHeader: header,
syncAggregate: syncCommittee.signHeader(config, header),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/light-client/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function computeMerkleBranch(

export function committeeUpdateToLatestHeadUpdate(
committeeUpdate: altair.LightClientUpdate
): routes.lightclient.LightclientHeaderUpdate {
): routes.lightclient.LightclientOptimisticHeaderUpdate {
return {
attestedHeader: committeeUpdate.attestedHeader,
syncAggregate: {
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/src/chain/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export interface IChainEvents {
[ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithHex) => void;
[ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithHex) => void;

[ChainEvent.lightclientOptimisticUpdate]: (headerUpdate: routes.events.LightclientHeaderUpdate) => void;
[ChainEvent.lightclientOptimisticUpdate]: (optimisticUpdate: routes.events.LightclientOptimisticHeaderUpdate) => void;
[ChainEvent.lightclientFinalizedUpdate]: (finalizedUpdate: routes.events.LightclientFinalizedUpdate) => void;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/lodestar/src/chain/lightClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class LightClientServer {
*/
private readonly prevHeadData = new Map<BlockRooHex, SyncAttestedData>();
private checkpointHeaders = new Map<BlockRooHex, phase0.BeaconBlockHeader>();
private latestHeadUpdate: routes.lightclient.LightclientHeaderUpdate | null = null;
private latestHeadUpdate: routes.lightclient.LightclientOptimisticHeaderUpdate | null = null;

private readonly zero: Pick<altair.LightClientUpdate, "finalityBranch" | "finalizedHeader">;
private finalized: routes.lightclient.LightclientFinalizedUpdate | null = null;
Expand Down Expand Up @@ -302,7 +302,7 @@ export class LightClientServer {
* API ROUTE to poll LightclientHeaderUpdate.
* Clients should use the SSE type `light_client_optimistic_update` if available
*/
async getOptimisticUpdate(): Promise<routes.lightclient.LightclientHeaderUpdate> {
async getOptimisticUpdate(): Promise<routes.lightclient.LightclientOptimisticHeaderUpdate> {
if (this.latestHeadUpdate === null) {
throw Error("No latest header update available");
}
Expand Down Expand Up @@ -452,7 +452,7 @@ export class LightClientServer {
throw new Error("attested data period different than signature period");
}

const headerUpdate: routes.lightclient.LightclientHeaderUpdate = {
const headerUpdate: routes.lightclient.LightclientOptimisticHeaderUpdate = {
attestedHeader: attestedData.attestedHeader,
syncAggregate,
};
Expand Down

0 comments on commit ba36147

Please sign in to comment.