feat: add method to reset the client

This commit is contained in:
Derrick Hammer 2023-09-16 11:51:30 -04:00
parent 5a5c320a25
commit 87d8be615e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 12 additions and 0 deletions

View File

@ -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) { public async syncFromCheckpoint(checkpoint: LightClientUpdate) {
this._latestPeriod = computeSyncPeriodAtSlot( this._latestPeriod = computeSyncPeriodAtSlot(
checkpoint.attestedHeader.beacon.slot, checkpoint.attestedHeader.beacon.slot,

View File

@ -17,6 +17,7 @@ export interface IStore extends EventEmitter {
addUpdate(period: number, update: LightClientUpdate): void; addUpdate(period: number, update: LightClientUpdate): void;
getUpdate(period: number): Uint8Array; getUpdate(period: number): Uint8Array;
hasUpdate(period: number): boolean; hasUpdate(period: number): boolean;
clear(): void;
} }
export interface IVerifyingProvider { export interface IVerifyingProvider {

View File

@ -21,6 +21,10 @@ export default class Store extends EventEmitter implements IStore {
this.store.options.stdTTL = 0; this.store.options.stdTTL = 0;
} }
clear(): void {
this.store.flushAll();
}
addUpdate(period: number, update: LightClientUpdate) { addUpdate(period: number, update: LightClientUpdate) {
try { try {
const serialized = capella.ssz.LightClientUpdate.serialize(update); const serialized = capella.ssz.LightClientUpdate.serialize(update);