From 61f253a8a96aaf3aa38904aa5f78f1600650639c Mon Sep 17 00:00:00 2001 From: saul Date: Mon, 4 Dec 2023 10:10:49 +1300 Subject: [PATCH] fix: resolve the validation promise if the remote validates first. --- src/utils/heads-exchange.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/heads-exchange.ts b/src/utils/heads-exchange.ts index 53ecd227..a87d179e 100644 --- a/src/utils/heads-exchange.ts +++ b/src/utils/heads-exchange.ts @@ -249,10 +249,15 @@ export class HeadsExchange { const localHash = await hashHeads(this.heads) const remoteHash = CID.decode(message.hash) + const match = localHash.equals(remoteHash) - return { - match: localHash.equals(remoteHash) + if (this.verifyPromise == null) { + this.verifyPromise = new DeferredPromise(resolve => { resolve(match) }) + } else { + this.verifyPromise?.resolve(match) } + + return { match } } private handleVerifyResponse (message: Message): void {