From 7075966227515151490639b0f22a804d6e3b2583 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 24 Jul 2023 20:07:04 -0400 Subject: [PATCH] fix: add try/catch with mutex release on optimisticUpdateCallback --- src/baseClient.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/baseClient.ts b/src/baseClient.ts index da8897d..c1336b2 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -86,6 +86,7 @@ export default abstract class BaseClient extends EventEmitter { public getCurrentBlock(): number { return getCurrentSlot(this.config.chainConfig, this.genesisTime); } + public getLastBlock(): number | null { if (this._latestOptimisticUpdate) { return capella.ssz.LightClientOptimisticUpdate.deserialize( @@ -227,7 +228,13 @@ export default abstract class BaseClient extends EventEmitter { } await this.optimisticMutex.acquire(); - const update = await this.options.optimisticUpdateCallback(); + let update: OptimisticUpdate; + try { + update = await this.options.optimisticUpdateCallback(); + } catch (e) { + this.optimisticMutex.release(); + throw e; + } const verify = await optimisticUpdateVerify( this.latestCommittee as Uint8Array[],