From 87d8be615e42fef0ae122a29b83cd1974e4ee1a7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 16 Sep 2023 11:51:30 -0400 Subject: [PATCH] feat: add method to reset the client --- src/client/client.ts | 7 +++++++ src/interfaces.ts | 1 + src/store.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/client/client.ts b/src/client/client.ts index 11cf3fc..a8ae6af 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -46,6 +46,13 @@ export default class Client extends BaseClient { } } + public reset() { + this._latestPeriod = 0; + this.latestCommittee = undefined; + this.booted = false; + this.store.clear(); + } + public async syncFromCheckpoint(checkpoint: LightClientUpdate) { this._latestPeriod = computeSyncPeriodAtSlot( checkpoint.attestedHeader.beacon.slot, diff --git a/src/interfaces.ts b/src/interfaces.ts index 69959f7..90053c9 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -17,6 +17,7 @@ export interface IStore extends EventEmitter { addUpdate(period: number, update: LightClientUpdate): void; getUpdate(period: number): Uint8Array; hasUpdate(period: number): boolean; + clear(): void; } export interface IVerifyingProvider { diff --git a/src/store.ts b/src/store.ts index fda3f63..94c0ade 100644 --- a/src/store.ts +++ b/src/store.ts @@ -21,6 +21,10 @@ export default class Store extends EventEmitter implements IStore { this.store.options.stdTTL = 0; } + clear(): void { + this.store.flushAll(); + } + addUpdate(period: number, update: LightClientUpdate) { try { const serialized = capella.ssz.LightClientUpdate.serialize(update);