2022-10-21 10:32:24 -07:00
|
|
|
package vaa
|
2020-10-28 14:41:33 -07:00
|
|
|
|
2020-10-29 02:13:15 -07:00
|
|
|
// CalculateQuorum returns the minimum number of guardians that need to sign a VAA for a given guardian set.
|
2020-10-28 14:41:33 -07:00
|
|
|
//
|
|
|
|
// The canonical source is the calculation in the contracts (solana/bridge/src/processor.rs and
|
|
|
|
// ethereum/contracts/Wormhole.sol), and this needs to match the implementation in the contracts.
|
|
|
|
func CalculateQuorum(numGuardians int) int {
|
2023-05-30 13:46:51 -07:00
|
|
|
// A safety check to avoid caller from ever supplying a negative
|
|
|
|
// number, because we're dealing with signed integers
|
2023-05-09 08:45:10 -07:00
|
|
|
if numGuardians < 0 {
|
|
|
|
panic("Invalid numGuardians is less than zero")
|
|
|
|
}
|
2023-05-30 13:46:51 -07:00
|
|
|
|
|
|
|
// The goal here is to acheive a 2/3 quorum, but since we're
|
|
|
|
// dividing on int, we need to +1 to avoid the rounding down
|
|
|
|
// effect of integer division
|
|
|
|
//
|
|
|
|
// For example sake, 5 / 2 == 2, but really that's not an
|
|
|
|
// effective 2/3 quorum, so we add 1 for safety to get to 3
|
|
|
|
//
|
2022-12-27 10:27:47 -08:00
|
|
|
return ((numGuardians * 2) / 3) + 1
|
2020-10-28 14:41:33 -07:00
|
|
|
}
|