Skip to content

Commit f458040

Browse files
authored
fix(tests): correct committee lookback index calculation in GetCommittee (#995)
* fix: Correct committee lookback index calculation in GetCommittee Signed-off-by: Jakub Sztandera <[email protected]> * add extra check Signed-off-by: Jakub Sztandera <[email protected]> * add note that certchain is testing utility to avoid further reports Signed-off-by: Jakub Sztandera <[email protected]> --------- Signed-off-by: Jakub Sztandera <[email protected]>
1 parent ffd3c2f commit f458040

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

certchain/certchain.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// certchain package is a testing utility for generating and validating
2+
// finality certificates.
3+
// It has no effect on the consensus protocol.
14
package certchain
25

36
import (
@@ -50,7 +53,10 @@ func (cc *CertChain) GetCommittee(ctx context.Context, instance uint64) (*gpbft.
5053
if instance < cc.m.InitialInstance+cc.m.CommitteeLookback {
5154
committeeEpoch = cc.m.BootstrapEpoch - cc.m.EC.Finality
5255
} else {
53-
lookbackIndex := instance - cc.m.CommitteeLookback + 1
56+
lookbackIndex := instance - cc.m.CommitteeLookback - cc.m.InitialInstance + 1
57+
if lookbackIndex >= uint64(len(cc.certificates)) {
58+
return nil, fmt.Errorf("no prior finality certificate to get committee at instance %d", instance)
59+
}
5460
certAtLookback := cc.certificates[lookbackIndex]
5561
committeeEpoch = certAtLookback.ECChain.Head().Epoch
5662
}

certchain/certchain_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestCertChain_GenerateAndVerify(t *testing.T) {
2424

2525
ctx, clk := clock.WithMockClock(context.Background())
2626
m := manifest.LocalDevnetManifest()
27+
m.InitialInstance = 100
2728
signVerifier := signing.NewFakeBackend()
2829
rng := rand.New(rand.NewSource(seed * 23))
2930
generatePublicKey := func(id gpbft.ActorID) gpbft.PubKey {

0 commit comments

Comments
 (0)