Skip to content

Commit 209f487

Browse files
committed
feat: update PredepositGuarantee abi and implement node syncing status
1 parent b75fc0a commit 209f487

File tree

8 files changed

+136
-6
lines changed

8 files changed

+136
-6
lines changed

abi/PredepositGuarantee.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ export const PredepositGuaranteeErrorsAbi = [
4747
name: 'InputHasInfinityPoints',
4848
type: 'error',
4949
},
50+
{
51+
inputs: [
52+
{
53+
internalType: 'enum BLS12_381.Component',
54+
name: 'component',
55+
type: 'uint8',
56+
},
57+
],
58+
name: 'InvalidCompressedComponent',
59+
type: 'error',
60+
},
61+
{
62+
inputs: [
63+
{
64+
internalType: 'enum BLS12_381.Component',
65+
name: 'component',
66+
type: 'uint8',
67+
},
68+
],
69+
name: 'InvalidCompressedComponentSignBit',
70+
type: 'error',
71+
},
72+
{
73+
inputs: [],
74+
name: 'InvalidDepositAmount',
75+
type: 'error',
76+
},
5077
{
5178
inputs: [],
5279
name: 'InvalidDepositYLength',
@@ -67,6 +94,11 @@ export const PredepositGuaranteeErrorsAbi = [
6794
name: 'InvalidSignature',
6895
type: 'error',
6996
},
97+
{
98+
inputs: [],
99+
name: 'InvalidSignatureLength',
100+
type: 'error',
101+
},
70102
{
71103
inputs: [],
72104
name: 'InvalidSlot',

programs/contracts/pdg/write.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
stringToNumberArray,
2929
parseValidatorTopUpArray,
3030
etherToWeiArray,
31+
fetchNodeSyncingStatus,
32+
fetchBeaconHeader,
3133
} from 'utils';
3234
import { Deposit, ValidatorTopUp } from 'types';
3335

@@ -72,6 +74,19 @@ pdgWrite
7274
) => {
7375
const pdgContract = await getPredepositGuaranteeContract();
7476

77+
const nodeStatus = await fetchNodeSyncingStatus();
78+
const beaconHeaderJson = await fetchBeaconHeader('finalized');
79+
80+
logInfo('Node syncing status');
81+
logTable({
82+
data: [
83+
['Is syncing', nodeStatus.data.is_syncing],
84+
['Sync distance', nodeStatus.data.sync_distance],
85+
['Head slot', nodeStatus.data.head_slot],
86+
['Finalized slot', beaconHeaderJson.data.header.message.slot],
87+
],
88+
});
89+
7590
const isPaused = await checkPdgIsPaused(pdgContract);
7691
if (isPaused) return;
7792

@@ -150,6 +165,18 @@ pdgWrite
150165
const validatorIndex = await confirmMakeProof(index);
151166
if (!validatorIndex) return;
152167

168+
const nodeStatus = await fetchNodeSyncingStatus();
169+
const beaconHeaderJson = await fetchBeaconHeader('finalized');
170+
171+
logInfo('Node syncing status');
172+
logTable({
173+
data: [
174+
['Is syncing', nodeStatus.data.is_syncing],
175+
['Sync distance', nodeStatus.data.sync_distance],
176+
['Head slot', nodeStatus.data.head_slot],
177+
['Finalized slot', beaconHeaderJson.data.header.message.slot],
178+
],
179+
});
153180
const hideSpinner = showSpinner({
154181
type: 'bouncingBar',
155182
message: 'Making proof...',

programs/pdg-helpers.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
callReadMethodSilent,
2929
stringToNumber,
3030
fetchValidatorsInfo,
31+
fetchNodeSyncingStatus,
32+
fetchBeaconHeader,
3133
} from 'utils';
3234
import { checkPdgIsPaused } from 'features';
3335

@@ -53,6 +55,18 @@ predepositGuaranteeHelpers
5355
if (!validatorIndex) return;
5456

5557
const pdgContract = await getPredepositGuaranteeContract();
58+
const nodeStatus = await fetchNodeSyncingStatus();
59+
const beaconHeaderJson = await fetchBeaconHeader('finalized');
60+
61+
logInfo('Node syncing status');
62+
logTable({
63+
data: [
64+
['Is syncing', nodeStatus.data.is_syncing],
65+
['Sync distance', nodeStatus.data.sync_distance],
66+
['Head slot', nodeStatus.data.head_slot],
67+
['Finalized slot', beaconHeaderJson.data.header.message.slot],
68+
],
69+
});
5670

5771
const hideSpinner = showSpinner();
5872
try {
@@ -115,6 +129,19 @@ predepositGuaranteeHelpers
115129
const validatorIndex = await confirmMakeProof(index);
116130
if (!validatorIndex) return;
117131

132+
const nodeStatus = await fetchNodeSyncingStatus();
133+
const beaconHeaderJson = await fetchBeaconHeader('finalized');
134+
135+
logInfo('Node syncing status');
136+
logTable({
137+
data: [
138+
['Is syncing', nodeStatus.data.is_syncing],
139+
['Sync distance', nodeStatus.data.sync_distance],
140+
['Head slot', nodeStatus.data.head_slot],
141+
['Finalized slot', beaconHeaderJson.data.header.message.slot],
142+
],
143+
});
144+
118145
const hideSpinner = showSpinner();
119146
try {
120147
const packageProof = await createPDGProof(Number(validatorIndex));

providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./wallet.js";
1+
export * from './wallet.js';

scripts/updateVersion.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const path = require("path");
2-
const { readJsonSync, writeFileSync } = require("fs-extra");
1+
const path = require('path');
2+
const { readJsonSync, writeFileSync } = require('fs-extra');
33

44
const esmVersionFilePath = path.join(__dirname, '../dist/version/index.js');
55
const packageJsonPath = path.join(__dirname, '../package.json');

types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./config.js";
2-
export * from "./common.js";
1+
export * from './config.js';
2+
export * from './common.js';

utils/fetchCL.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ type FinalityCheckpoints = {
5656
};
5757
};
5858

59+
export type NodeSyncingStatus = {
60+
data: {
61+
head_slot: string;
62+
sync_distance: string;
63+
is_syncing: boolean;
64+
is_optimistic: boolean;
65+
el_offline: boolean;
66+
};
67+
};
68+
5969
const isFinalityCheckpoints = (
6070
obj: FinalityCheckpoints,
6171
): obj is FinalityCheckpoints => {
@@ -156,6 +166,7 @@ const endpoints = {
156166
state: (stateId: StateId): string => `eth/v2/debug/beacon/states/${stateId}`,
157167
validatorsInfo: (validatorsPubkeys: string): string =>
158168
`eth/v1/beacon/states/head/validators${validatorsPubkeys}`,
169+
nodeSyncing: 'eth/v1/node/syncing',
159170
};
160171

161172
export const finalityCheckpoints = async (
@@ -335,3 +346,36 @@ export const fetchValidatorsInfo = async (
335346
throw error;
336347
}
337348
};
349+
350+
export const fetchNodeSyncingStatus = async (
351+
clURL?: string,
352+
): Promise<NodeSyncingStatus> => {
353+
const url = clURL || getConfig().CL_URL;
354+
355+
if (!url) {
356+
throw new Error(
357+
'CL_URL is not set. CL_URL is required for checking node syncing status',
358+
);
359+
}
360+
361+
try {
362+
const syncingResp = await fetch(
363+
`${url.endsWith('/') ? url : url + '/'}${endpoints.nodeSyncing}`,
364+
);
365+
366+
if (!syncingResp.ok) {
367+
throw new Error(
368+
`HTTP ${syncingResp.status} ${syncingResp.statusText}. URL: ${url}\n`,
369+
);
370+
}
371+
372+
const body: NodeSyncingStatus = await syncingResp.json();
373+
return body;
374+
} catch (error) {
375+
printError(
376+
error,
377+
`Error fetching node syncing status. Used URL: ${url}. Please check if the CL_URL environment variable is correct or try to use another CL.`,
378+
);
379+
throw error;
380+
}
381+
};

utils/sleep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const sleep = (ms: number) => {
22
return new Promise((resolve) => setTimeout(resolve, ms));
3-
}
3+
};

0 commit comments

Comments
 (0)