Skip to content

Commit

Permalink
feat: use required round when calculating
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Oct 31, 2023
1 parent 47e0cdb commit 791b3d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions pkg/types/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
func ValidatorsFromTendermintResponse(
consensus *ConsensusStateResponse,
tendermintValidators []TendermintValidator,
round int64,
) (Validators, error) {
validators := make(Validators, len(consensus.Result.RoundState.HeightVoteSet[0].Prevotes))
lastHeightVoteSet := consensus.Result.RoundState.HeightVoteSet[round]
validators := make(Validators, len(lastHeightVoteSet.Prevotes))

for index, prevote := range consensus.Result.RoundState.HeightVoteSet[0].Prevotes {
precommit := consensus.Result.RoundState.HeightVoteSet[0].Precommits[index]
for index, prevote := range lastHeightVoteSet.Prevotes {
precommit := lastHeightVoteSet.Precommits[index]
validator := tendermintValidators[index]

vp := new(big.Int)
Expand Down
13 changes: 7 additions & 6 deletions pkg/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ func (s *State) SetTendermintResponse(
consensus *ConsensusStateResponse,
tendermintValidators []TendermintValidator,
) error {
validators, err := ValidatorsFromTendermintResponse(consensus, tendermintValidators)
if err != nil {
return err
}

hrsSplit := strings.Split(consensus.Result.RoundState.HeightRoundStep, "/")

s.Validators = &validators
s.Height = utils.MustParseInt64(hrsSplit[0])
s.Round = utils.MustParseInt64(hrsSplit[1])
s.Step = utils.MustParseInt64(hrsSplit[2])
s.StartTime = consensus.Result.RoundState.StartTime

validators, err := ValidatorsFromTendermintResponse(consensus, tendermintValidators, s.Round)
if err != nil {
return err
}

s.Validators = &validators

return nil
}

Expand Down

0 comments on commit 791b3d6

Please sign in to comment.