github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/committees/threshold.go (about) 1 package committees 2 3 // WeightThresholdToBuildQC returns the weight (sum of unique, valid votes for this view) 4 // that is minimally required for a supermajority. 5 func WeightThresholdToBuildQC(totalWeight uint64) uint64 { 6 // Given totalWeight, we need the smallest integer t such that 2 * totalWeight / 3 < t 7 // Formally, the minimally required weight is: 2 * Floor(totalWeight/3) + max(1, totalWeight mod 3) 8 floorOneThird := totalWeight / 3 // integer division, includes floor 9 res := 2 * floorOneThird 10 divRemainder := totalWeight % 3 11 if divRemainder <= 1 { 12 res = res + 1 13 } else { 14 res += divRemainder 15 } 16 return res 17 } 18 19 // WeightThresholdToTimeout returns the weight (sum of unique, valid timeout objects for this view) 20 // that is minimally required to immediately timeout and build a TO. 21 func WeightThresholdToTimeout(totalWeight uint64) uint64 { 22 // Given totalWeight, we need the smallest integer t such that totalWeight / 3 < t 23 // Formally, the minimally required weight is: Floor(totalWeight/3) + 1 24 return totalWeight/3 + 1 25 }