Skip to content

Commit 8705f83

Browse files
committed
feat(core): fetch validators in multiple rounds
1 parent f5a2217 commit 8705f83

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

core/fetcher.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,27 @@ func (f *BlockFetcher) Commit(ctx context.Context, height *int64) (*types.Commit
6868
return res.Commit, nil
6969
}
7070

71-
// maxValidators is a maximum amount of validators
72-
// Should be in sync with network params and paging provided by Client
73-
const maxValidators = 100
74-
7571
// ValidatorSet queries Core for the ValidatorSet from the
7672
// block at the given height.
7773
func (f *BlockFetcher) ValidatorSet(ctx context.Context, height *int64) (*types.ValidatorSet, error) {
78-
// FIXME: The ugliness of passing pointers for integers in this case can't be explained with words
79-
maxVals := maxValidators
80-
res, err := f.client.Validators(ctx, height, nil, &maxVals)
81-
if err != nil {
82-
return nil, err
83-
}
74+
var perPage = 100
75+
76+
vals, total := make([]*types.Validator, 0), -1
77+
for page := 1; len(vals) != total; page++ {
78+
res, err := f.client.Validators(ctx, height, &page, &perPage)
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
if res != nil && len(res.Validators) == 0 {
84+
return nil, fmt.Errorf("core/fetcher: validators not found")
85+
}
8486

85-
if res != nil && res.Validators == nil {
86-
return nil, fmt.Errorf("core/fetcher: validators not found")
87+
total = res.Total
88+
vals = append(vals, res.Validators...)
8789
}
8890

89-
return types.NewValidatorSet(res.Validators), nil
91+
return types.NewValidatorSet(vals), nil
9092
}
9193

9294
// SubscribeNewBlockEvent subscribes to new block events from Core, returning

0 commit comments

Comments
 (0)