From 4836ddb32e62200114bcd0a1d9cc638753a3828b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 13 Jul 2023 03:14:06 -0400 Subject: [PATCH] style: reformat --- src/baseClient.ts | 99 ++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/src/baseClient.ts b/src/baseClient.ts index a06bc4c..a9c0449 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -86,6 +86,56 @@ export default abstract class BaseClient { return this.getNextValidExecutionInfo(retry - 1); } + async syncProver( + startPeriod: number, + currentPeriod: number, + startCommittee: Uint8Array[], + ): Promise<{ syncCommittee: Uint8Array[]; period: number }> { + try { + const updates = await this.options.prover.getSyncUpdate( + startPeriod, + currentPeriod - startPeriod, + ); + + for (let i = 0; i < updates.length; i++) { + const curPeriod = startPeriod + i; + const update = updates[i]; + + const updatePeriod = computeSyncPeriodAtSlot( + update.attestedHeader.beacon.slot, + ); + + const validOrCommittee = await this.syncUpdateVerifyGetCommittee( + startCommittee, + curPeriod, + update, + ); + + if (!(validOrCommittee as boolean)) { + console.log(`Found invalid update at period(${curPeriod})`); + return { + syncCommittee: startCommittee, + period: curPeriod, + }; + } + + await this.options.store.addUpdate(curPeriod, update); + + startCommittee = validOrCommittee as Uint8Array[]; + } + } catch (e) { + console.error(`failed to fetch sync update for period(${startPeriod})`); + return { + syncCommittee: startCommittee, + period: startPeriod, + }; + } + return { + syncCommittee: startCommittee, + period: currentPeriod, + }; + } + protected async _sync() { await this.syncMutex.acquire(); @@ -142,55 +192,6 @@ export default abstract class BaseClient { blockNumber: update.attestedHeader.execution.blockNumber, }; } - async syncProver( - startPeriod: number, - currentPeriod: number, - startCommittee: Uint8Array[], - ): Promise<{ syncCommittee: Uint8Array[]; period: number }> { - try { - const updates = await this.options.prover.getSyncUpdate( - startPeriod, - currentPeriod - startPeriod, - ); - - for (let i = 0; i < updates.length; i++) { - const curPeriod = startPeriod + i; - const update = updates[i]; - - const updatePeriod = computeSyncPeriodAtSlot( - update.attestedHeader.beacon.slot, - ); - - const validOrCommittee = await this.syncUpdateVerifyGetCommittee( - startCommittee, - curPeriod, - update, - ); - - if (!(validOrCommittee as boolean)) { - console.log(`Found invalid update at period(${curPeriod})`); - return { - syncCommittee: startCommittee, - period: curPeriod, - }; - } - - await this.options.store.addUpdate(curPeriod, update); - - startCommittee = validOrCommittee as Uint8Array[]; - } - } catch (e) { - console.error(`failed to fetch sync update for period(${startPeriod})`); - return { - syncCommittee: startCommittee, - period: startPeriod, - }; - } - return { - syncCommittee: startCommittee, - period: currentPeriod, - }; - } protected async syncUpdateVerifyGetCommittee( prevCommittee: Uint8Array[],