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);