quorum.go 886 B

12345678910111213141516171819202122
  1. package vaa
  2. // CalculateQuorum returns the minimum number of guardians that need to sign a VAA for a given guardian set.
  3. //
  4. // The canonical source is the calculation in the contracts (solana/bridge/src/processor.rs and
  5. // ethereum/contracts/Wormhole.sol), and this needs to match the implementation in the contracts.
  6. func CalculateQuorum(numGuardians int) int {
  7. // A safety check to avoid caller from ever supplying a negative
  8. // number, because we're dealing with signed integers
  9. if numGuardians < 0 {
  10. panic("Invalid numGuardians is less than zero")
  11. }
  12. // The goal here is to achieve a 2/3 quorum, but since we're
  13. // dividing on int, we need to +1 to avoid the rounding down
  14. // effect of integer division
  15. //
  16. // For example sake, 5 / 2 == 2, but really that's not an
  17. // effective 2/3 quorum, so we add 1 for safety to get to 3
  18. //
  19. return ((numGuardians * 2) / 3) + 1
  20. }