-
Notifications
You must be signed in to change notification settings - Fork 178
/
threshold.go
25 lines (23 loc) · 1.02 KB
/
threshold.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package committees
// WeightThresholdToBuildQC returns the weight (sum of unique, valid votes for this view)
// that is minimally required for a supermajority.
func WeightThresholdToBuildQC(totalWeight uint64) uint64 {
// Given totalWeight, we need the smallest integer t such that 2 * totalWeight / 3 < t
// Formally, the minimally required weight is: 2 * Floor(totalWeight/3) + max(1, totalWeight mod 3)
floorOneThird := totalWeight / 3 // integer division, includes floor
res := 2 * floorOneThird
divRemainder := totalWeight % 3
if divRemainder <= 1 {
res = res + 1
} else {
res += divRemainder
}
return res
}
// WeightThresholdToTimeout returns the weight (sum of unique, valid timeout objects for this view)
// that is minimally required to immediately timeout and build a TO.
func WeightThresholdToTimeout(totalWeight uint64) uint64 {
// Given totalWeight, we need the smallest integer t such that totalWeight / 3 < t
// Formally, the minimally required weight is: Floor(totalWeight/3) + 1
return totalWeight/3 + 1
}