Compare commits
No commits in common. "v0.1.0-develop.30" and "v0.1.0-develop.29" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,5 +1,3 @@
|
|||
# [0.1.0-develop.30](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.29...v0.1.0-develop.30) (2023-07-13)
|
||||
|
||||
# [0.1.0-develop.29](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.28...v0.1.0-develop.29) (2023-07-13)
|
||||
|
||||
# [0.1.0-develop.28](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.27...v0.1.0-develop.28) (2023-07-13)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@lumeweb/libethclient",
|
||||
"version": "0.1.0-develop.30",
|
||||
"version": "0.1.0-develop.29",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lumeweb/libethclient",
|
||||
"version": "0.1.0-develop.30",
|
||||
"version": "0.1.0-develop.29",
|
||||
"dependencies": {
|
||||
"@chainsafe/as-sha256": "^0.3.1",
|
||||
"@chainsafe/bls": "7.1.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/libethsync",
|
||||
"version": "0.1.0-develop.30",
|
||||
"version": "0.1.0-develop.29",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -13,11 +13,7 @@ import {
|
|||
getDefaultClientConfig,
|
||||
optimisticUpdateVerify,
|
||||
} from "#util.js";
|
||||
import {
|
||||
LightClientUpdate,
|
||||
OptimisticUpdate,
|
||||
OptimisticUpdateCallback,
|
||||
} from "#types.js";
|
||||
import { LightClientUpdate, OptimisticUpdateCallback } from "#types.js";
|
||||
import { assertValidLightClientUpdate } from "@lodestar/light-client/validation";
|
||||
import * as capella from "@lodestar/types/capella";
|
||||
|
||||
|
@ -39,7 +35,6 @@ export default abstract class BaseClient {
|
|||
protected options: BaseClientOptions;
|
||||
private genesisTime = this.config.genesis.time;
|
||||
private syncMutex = new Mutex();
|
||||
private optimisticMutex = new Mutex();
|
||||
|
||||
constructor(options: BaseClientOptions) {
|
||||
this.options = options;
|
||||
|
@ -106,6 +101,10 @@ export default abstract class BaseClient {
|
|||
const curPeriod = startPeriod + i;
|
||||
const update = updates[i];
|
||||
|
||||
const updatePeriod = computeSyncPeriodAtSlot(
|
||||
update.attestedHeader.beacon.slot,
|
||||
);
|
||||
|
||||
const validOrCommittee = await this.syncUpdateVerifyGetCommittee(
|
||||
startCommittee,
|
||||
curPeriod,
|
||||
|
@ -173,39 +172,14 @@ export default abstract class BaseClient {
|
|||
|
||||
protected async getLatestExecution(): Promise<ExecutionInfo | null> {
|
||||
await this._sync();
|
||||
|
||||
const getExecInfo = (u: OptimisticUpdate) => {
|
||||
return {
|
||||
blockHash: toHexString(u.attestedHeader.execution.blockHash),
|
||||
blockNumber: u.attestedHeader.execution.blockNumber,
|
||||
};
|
||||
};
|
||||
|
||||
if (this._latestOptimisticUpdate) {
|
||||
const update = capella.ssz.LightClientOptimisticUpdate.deserialize(
|
||||
this._latestOptimisticUpdate,
|
||||
);
|
||||
const diffInSeconds = Date.now() / 1000 - this.genesisTime;
|
||||
const currentSlot = Math.floor(
|
||||
diffInSeconds / this.config.chainConfig.SECONDS_PER_SLOT,
|
||||
);
|
||||
if (currentSlot <= update.attestedHeader.beacon.slot) {
|
||||
this.optimisticMutex.release();
|
||||
return getExecInfo(update);
|
||||
}
|
||||
}
|
||||
|
||||
await this.optimisticMutex.acquire();
|
||||
const update = await this.options.optimisticUpdateCallback();
|
||||
|
||||
const verify = await optimisticUpdateVerify(
|
||||
this.latestCommittee as Uint8Array[],
|
||||
update,
|
||||
);
|
||||
|
||||
// TODO: check the update against the latest sync committee
|
||||
if (!verify.correct) {
|
||||
this.optimisticMutex.release();
|
||||
console.error(`Invalid Optimistic Update: ${verify.reason}`);
|
||||
return null;
|
||||
}
|
||||
|
@ -217,9 +191,10 @@ export default abstract class BaseClient {
|
|||
`Optimistic update verified for slot ${update.attestedHeader.beacon.slot}`,
|
||||
);
|
||||
|
||||
this.optimisticMutex.release();
|
||||
|
||||
return getExecInfo(update);
|
||||
return {
|
||||
blockHash: toHexString(update.attestedHeader.execution.blockHash),
|
||||
blockNumber: update.attestedHeader.execution.blockNumber,
|
||||
};
|
||||
}
|
||||
|
||||
protected async syncUpdateVerifyGetCommittee(
|
||||
|
|
|
@ -25,4 +25,10 @@ export default class Client extends BaseClient {
|
|||
this.beaconUrl = config.beaconUrl;
|
||||
this.http.defaults.baseURL = this.beaconUrl;
|
||||
}
|
||||
|
||||
async sync(): Promise<void> {
|
||||
await super.sync();
|
||||
|
||||
this.subscribe();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue