|
@ -822,6 +822,24 @@ func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Comm |
|
|
return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded} |
|
|
return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// findPreviousProposer reverses the compare proposer priority function to find the validator
|
|
|
|
|
|
// with the lowest proposer priority which would have been the previous proposer.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Is used when recreating a validator set from an existing array of validators.
|
|
|
|
|
|
func (vals *ValidatorSet) findPreviousProposer() *Validator { |
|
|
|
|
|
var previousProposer *Validator |
|
|
|
|
|
for _, val := range vals.Validators { |
|
|
|
|
|
if previousProposer == nil { |
|
|
|
|
|
previousProposer = val |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if previousProposer == previousProposer.CompareProposerPriority(val) { |
|
|
|
|
|
previousProposer = val |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return previousProposer |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//-----------------
|
|
|
//-----------------
|
|
|
|
|
|
|
|
|
// IsErrNotEnoughVotingPowerSigned returns true if err is
|
|
|
// IsErrNotEnoughVotingPowerSigned returns true if err is
|
|
@ -966,6 +984,21 @@ func ValidatorSetFromProto(vp *tmproto.ValidatorSet) (*ValidatorSet, error) { |
|
|
return vals, vals.ValidateBasic() |
|
|
return vals, vals.ValidateBasic() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ValidatorSetFromExistingValidators takes an existing array of validators and rebuilds
|
|
|
|
|
|
// the exact same validator set that corresponds to it without changing the proposer priority or power
|
|
|
|
|
|
func ValidatorSetFromExistingValidators(valz []*Validator) (*ValidatorSet, error) { |
|
|
|
|
|
if len(valz) == 0 { |
|
|
|
|
|
return nil, errors.New("no validators given") |
|
|
|
|
|
} |
|
|
|
|
|
vals := &ValidatorSet{ |
|
|
|
|
|
Validators: valz, |
|
|
|
|
|
} |
|
|
|
|
|
vals.Proposer = vals.findPreviousProposer() |
|
|
|
|
|
vals.updateTotalVotingPower() |
|
|
|
|
|
sort.Sort(ValidatorsByVotingPower(vals.Validators)) |
|
|
|
|
|
return vals, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
|
// RandValidatorSet returns a randomized validator set (size: +numValidators+),
|
|
|
// RandValidatorSet returns a randomized validator set (size: +numValidators+),
|
|
|