fix: add try/catch with mutex release on optimisticUpdateCallback

This commit is contained in:
Derrick Hammer 2023-07-24 20:07:04 -04:00
parent 72a4975ba9
commit 7075966227
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 1 deletions

View File

@ -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[],