Compare commits

...

2 Commits

3 changed files with 40 additions and 70 deletions

8
npm-shrinkwrap.json generated
View File

@ -10,7 +10,7 @@
"hasInstallScript": true,
"dependencies": {
"@lumeweb/interface-relay": "^0.0.2-develop.1",
"@lumeweb/libethsync": "^0.1.0-develop.17",
"@lumeweb/libethsync": "^0.1.0-develop.38",
"axios": "^1.4.0"
},
"devDependencies": {
@ -4123,9 +4123,9 @@
}
},
"node_modules/@lumeweb/libethsync": {
"version": "0.1.0-develop.25",
"resolved": "https://registry.npmjs.org/@lumeweb/libethsync/-/libethsync-0.1.0-develop.25.tgz",
"integrity": "sha512-yn3uzWCg1kAWWLyhlbrAKEAydhh3IB4aFE2Y2Yz0cpgQgfnsXLQwFF35VmCIIye908yLYc9aGmCgVvPqRkEz5Q==",
"version": "0.1.0-develop.38",
"resolved": "https://registry.npmjs.org/@lumeweb/libethsync/-/libethsync-0.1.0-develop.38.tgz",
"integrity": "sha512-ja91WvW8X+2hA1k221TKdoDVj6MV5ZTMj1/HfFUvOpba0b2gnvDtqN0MrlQ8sOojr3CVxXQ2hqVOBIfRFw9pmA==",
"dependencies": {
"@chainsafe/as-sha256": "^0.3.1",
"@chainsafe/bls": "7.1.1",

View File

@ -15,7 +15,7 @@
},
"dependencies": {
"@lumeweb/interface-relay": "^0.0.2-develop.1",
"@lumeweb/libethsync": "^0.1.0-develop.17",
"@lumeweb/libethsync": "^0.1.0-develop.38",
"axios": "^1.4.0"
}
}

View File

@ -1,15 +1,12 @@
import type { Plugin, PluginAPI } from "@lumeweb/interface-relay";
import {
ConsensusCommitteeHashesRequest,
ConsensusCommitteePeriodRequest,
ConsensusCommitteeUpdateRequest,
createDefaultClient,
getConsensusOptimisticUpdate,
} from "@lumeweb/libethsync/node";
import { RPCRequestRaw } from "@lumeweb/libethsync/client";
import axios from "axios";
const EXECUTION_RPC_URL =
"https://solemn-small-frost.discover.quiknode.pro/dbbe3dc75a8b828611df3f12722de5cc88214947/";
const EXECUTION_RPC_URL = "https://rpc.ankr.com/eth";
const CONSENSUS_RPC_URL = "https://www.lightclientdata.org";
@ -26,70 +23,55 @@ const plugin: Plugin = {
const client = createDefaultClient(CONSENSUS_RPC_URL);
await client.sync();
api.registerMethod("consensus_committee_hashes", {
api.registerMethod("consensus_updates", {
cacheable: false,
async handler(
request: ConsensusCommitteeHashesRequest,
): Promise<Uint8Array> {
request: ConsensusCommitteeUpdateRequest,
): Promise<Uint8Array[]> {
if (!(request?.start && typeof request.start === "number")) {
throw new Error('start required and must be a number"');
throw new Error("start required and must be a number");
}
if (!(request?.count && typeof request.count === "number")) {
throw new Error('count required and must be a number"');
throw new Error("count required and must be a number");
}
for (let i = 0; i < 4; i++) {
try {
return await client.store.getCommitteeHashes(
request.start,
request.count,
);
} catch (e) {
if (i === 3) {
return e;
}
await client.sync();
}
}
return new Uint8Array();
},
});
api.registerMethod("consensus_committee_period", {
cacheable: false,
async handler(
request: ConsensusCommitteePeriodRequest,
): Promise<Uint8Array> {
if (
!(
request?.period &&
(typeof request.period == "number" || request.period === "latest")
)
) {
throw new Error('period required and must be a number or "latest"');
}
request.count = Math.min(request.count, 5);
if (!client.isSynced) {
await client.sync();
}
for (let i = 0; i < 4; i++) {
try {
return await client.store.getCommittee(
request.period === "latest"
? client.latestPeriod
: request.period,
const updates: Uint8Array[] = [];
for (let i = 0; i < request.count; i++) {
const period = request?.start + i;
if (!client.store.hasUpdate(period)) {
throw new Error(
`update at period ${request?.start} does not exist`,
);
} catch (e) {
if (i === 3) {
return e;
}
await client.sync();
}
updates.push(client.store.getUpdate(period));
}
return new Uint8Array();
return updates;
},
});
api.registerMethod("consensus_optimistic_update", {
cacheable: false,
async handler(): Promise<Uint8Array> {
if (!client.isSynced) {
await client.sync();
}
let execInfo = await client.getLatestExecution();
if (!execInfo) {
throw new Error("optimistic update not ready");
}
return client.latestOptimisticUpdate;
},
});
@ -100,18 +82,6 @@ const plugin: Plugin = {
return { ...ret, id: request.id ?? ret.id };
},
});
api.registerMethod("consensus_optimistic_update", {
cacheable: false,
async handler(): Promise<object> {
console.log("consensus_optimistic_update request received");
if (!client.latestOptimisticUpdate) {
throw new Error("optimistic update not ready");
}
return client.latestOptimisticUpdate;
},
});
},
};