Skip to content

Commit 4b033ba

Browse files
committed
cloud_functions: getQuorum-ishHeight
1 parent 5bc668a commit 4b033ba

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cloud_functions/src/getQuorumHeight.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ interface HeartbeatNetwork {
2828

2929
const isTestnet = assertEnvironmentVariable('NETWORK') === 'TESTNET';
3030

31+
/**
32+
* Wormhole Foundation requested an additional buffer to increase the likelihood of success in
33+
* the event that a guardian is tracking a height but not properly handling requests.
34+
*/
35+
const QUORUM_BUFFER = 1;
36+
3137
export function getQuorumCount(numGuardians: number): number {
32-
return isTestnet ? 1 : Math.floor((numGuardians * 2) / 3 + 1);
38+
return isTestnet ? 1 : Math.floor((numGuardians * 2) / 3 + 1) + QUORUM_BUFFER;
3339
}
3440

3541
async function getHeartbeats_() {
@@ -106,7 +112,10 @@ export async function getQuorumHeight(req: any, res: any) {
106112
latestHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0));
107113
safeHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0));
108114
finalizedHeights.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0));
109-
const quorumIdx = getQuorumCount(latestHeights.length) - 1;
115+
const quorumIdx = Math.min(
116+
getQuorumCount(latestHeights.length) - 1,
117+
latestHeights.length - 1
118+
);
110119
res.status(200).send(
111120
JSON.stringify({
112121
latest: latestHeights[quorumIdx].toString(),

0 commit comments

Comments
 (0)