From b3f703663fe63b47ec725eb3fe5ab8459f1feaca Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Tue, 18 Mar 2025 13:34:08 -0400 Subject: [PATCH] cloud_functions: getQuorum-ishHeight --- cloud_functions/src/getQuorumHeight.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cloud_functions/src/getQuorumHeight.ts b/cloud_functions/src/getQuorumHeight.ts index 8095a446..0e96c490 100644 --- a/cloud_functions/src/getQuorumHeight.ts +++ b/cloud_functions/src/getQuorumHeight.ts @@ -28,8 +28,14 @@ interface HeartbeatNetwork { const isTestnet = assertEnvironmentVariable('NETWORK') === 'TESTNET'; +/** + * Wormhole Foundation requested an additional buffer to increase the likelihood of success in + * the event that a guardian is tracking a height but not properly handling requests. + */ +const QUORUM_BUFFER = 1; + export function getQuorumCount(numGuardians: number): number { - return isTestnet ? 1 : Math.floor((numGuardians * 2) / 3 + 1); + return isTestnet ? 1 : Math.floor((numGuardians * 2) / 3 + 1) + QUORUM_BUFFER; } async function getHeartbeats_() { @@ -106,7 +112,10 @@ export async function getQuorumHeight(req: any, res: any) { latestHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0)); safeHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0)); finalizedHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0)); - const quorumIdx = getQuorumCount(latestHeights.length) - 1; + const quorumIdx = Math.min( + getQuorumCount(latestHeights.length) - 1, + latestHeights.length - 1 + ); res.status(200).send( JSON.stringify({ latest: latestHeights[quorumIdx].toString(),