refactor: getLatestExecution needs to actually call optimistic update, but add a callback in the client options to avoid creating a subclass
This commit is contained in:
parent
5aa37d4a61
commit
51d6d23942
|
@ -8,13 +8,18 @@ import {
|
||||||
import bls, { init } from "@chainsafe/bls/switchable";
|
import bls, { init } from "@chainsafe/bls/switchable";
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import { fromHexString, toHexString } from "@chainsafe/ssz";
|
import { fromHexString, toHexString } from "@chainsafe/ssz";
|
||||||
import { deserializePubkeys, getDefaultClientConfig } from "#util.js";
|
import {
|
||||||
import { capella, LightClientUpdate } from "#types.js";
|
deserializePubkeys,
|
||||||
|
getDefaultClientConfig,
|
||||||
|
optimisticUpdateVerify,
|
||||||
|
} from "#util.js";
|
||||||
|
import { capella, LightClientUpdate, OptimisticUpdate } from "#types.js";
|
||||||
import { assertValidLightClientUpdate } from "@lodestar/light-client/validation";
|
import { assertValidLightClientUpdate } from "@lodestar/light-client/validation";
|
||||||
|
|
||||||
export interface BaseClientOptions {
|
export interface BaseClientOptions {
|
||||||
prover: IProver;
|
prover: IProver;
|
||||||
store: IStore;
|
store: IStore;
|
||||||
|
optimisticUpdateCallback: () => Promise<OptimisticUpdate>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default abstract class BaseClient {
|
export default abstract class BaseClient {
|
||||||
|
@ -106,8 +111,19 @@ export default abstract class BaseClient {
|
||||||
|
|
||||||
protected async getLatestExecution(): Promise<ExecutionInfo | null> {
|
protected async getLatestExecution(): Promise<ExecutionInfo | null> {
|
||||||
await this._sync();
|
await this._sync();
|
||||||
const update = capella.ssz.LightClientUpdate.deserialize(
|
const update = await this.options.optimisticUpdateCallback();
|
||||||
this.store.getUpdate(this.latestPeriod),
|
|
||||||
|
const verify = await optimisticUpdateVerify(
|
||||||
|
this.latestCommittee as Uint8Array[],
|
||||||
|
update,
|
||||||
|
);
|
||||||
|
// TODO: check the update agains the latest sync commttee
|
||||||
|
if (!verify.correct) {
|
||||||
|
console.error(`Invalid Optimistic Update: ${verify.reason}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`Optimistic update verified for slot ${update.attestedHeader.beacon.slot}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue