refactor: don't use un-needed for loop
This commit is contained in:
parent
17cb00231c
commit
5aa37d4a61
|
@ -5,13 +5,12 @@ import {
|
|||
getCurrentSlot,
|
||||
deserializeSyncCommittee,
|
||||
} from "@lodestar/light-client/utils";
|
||||
import { init } from "@chainsafe/bls/switchable";
|
||||
import bls, { init } from "@chainsafe/bls/switchable";
|
||||
import { Mutex } from "async-mutex";
|
||||
import { fromHexString, toHexString } from "@chainsafe/ssz";
|
||||
import { deserializePubkeys, getDefaultClientConfig } from "#util.js";
|
||||
import { capella, LightClientUpdate } from "#types.js";
|
||||
import bls from "@chainsafe/bls/switchable.js";
|
||||
import { assertValidLightClientUpdate } from "@lodestar/light-client/validation.js";
|
||||
import { assertValidLightClientUpdate } from "@lodestar/light-client/validation";
|
||||
|
||||
export interface BaseClientOptions {
|
||||
prover: IProver;
|
||||
|
@ -121,17 +120,20 @@ export default abstract class BaseClient {
|
|||
currentPeriod: number,
|
||||
startCommittee: Uint8Array[],
|
||||
): Promise<{ syncCommittee: Uint8Array[]; period: number }> {
|
||||
for (let period = startPeriod; period < currentPeriod; period += 1) {
|
||||
try {
|
||||
const updates = await this.options.prover.getSyncUpdate(
|
||||
period,
|
||||
currentPeriod,
|
||||
startPeriod,
|
||||
currentPeriod - startPeriod,
|
||||
);
|
||||
|
||||
for (let i = 0; i < updates.length; i++) {
|
||||
const curPeriod = period + i;
|
||||
const curPeriod = startPeriod + i;
|
||||
const update = updates[i];
|
||||
|
||||
const updatePeriod = computeSyncPeriodAtSlot(
|
||||
update.attestedHeader.beacon.slot,
|
||||
);
|
||||
|
||||
const validOrCommittee = await this.syncUpdateVerifyGetCommittee(
|
||||
startCommittee,
|
||||
curPeriod,
|
||||
|
@ -146,19 +148,17 @@ export default abstract class BaseClient {
|
|||
};
|
||||
}
|
||||
|
||||
await this.options.store.addUpdate(period, update);
|
||||
await this.options.store.addUpdate(curPeriod, update);
|
||||
|
||||
startCommittee = validOrCommittee as Uint8Array[];
|
||||
period = curPeriod;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`failed to fetch sync update for period(${period})`);
|
||||
console.error(`failed to fetch sync update for period(${startPeriod})`);
|
||||
return {
|
||||
syncCommittee: startCommittee,
|
||||
period,
|
||||
period: startPeriod,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
syncCommittee: startCommittee,
|
||||
period: currentPeriod,
|
||||
|
|
Loading…
Reference in New Issue