Skip to content

Commit 793b7d2

Browse files
authored
fix(tests): correctly calculate signing power threshold with rounding (#997)
Resolves #996 Signed-off-by: Jakub Sztandera <[email protected]>
1 parent f458040 commit 793b7d2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

certchain/certchain.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10+
"math"
1011
"math/rand"
1112
"slices"
1213

@@ -159,7 +160,7 @@ func (cc *CertChain) signProportionally(ctx context.Context, committee *gpbft.Co
159160
// range of 66% to 100% of total power.
160161
const minimumPower = 2.0 / 3.0
161162
targetPowerPortion := minimumPower + cc.rng.Float64()*(1.0-minimumPower)
162-
signingPowerThreshold := int64(float64(committee.PowerTable.ScaledTotal) * targetPowerPortion)
163+
signingPowerThreshold := int64(math.Ceil(float64(committee.PowerTable.ScaledTotal) * targetPowerPortion))
163164

164165
var signingPowerSoFar int64
165166
type signatureAt struct {
@@ -217,7 +218,7 @@ func (cc *CertChain) signProportionally(ctx context.Context, committee *gpbft.Co
217218

218219
func (cc *CertChain) sign(ctx context.Context, committee *gpbft.Committee, payload *gpbft.Payload, signers *bitfield.BitField) ([]byte, error) {
219220
const minimumPower = 2.0 / 3.0
220-
minSigningPower := int64(float64(committee.PowerTable.ScaledTotal) * minimumPower)
221+
minSigningPower := int64(math.Ceil(float64(committee.PowerTable.ScaledTotal) * minimumPower))
221222

222223
var signingPowerSoFar int64
223224
var signatures [][]byte

0 commit comments

Comments
 (0)