Make it fail to set empty validator
revokeValidator may empty validator list. It causes system failure.
So, this keep it from system failure.
@@ -975,9 +975,13 @@ func (s *ChainScore) Ex_revokeValidator(address module.Address) error {
return scoreresult.New(StatusIllegalArgument, "AddressIsContract")
}
if v, err := state.ValidatorFromAddress(address); err == nil {
- if ok := s.cc.GetValidatorState().Remove(v); !ok {
+ vl := s.cc.GetValidatorState()
+ if ok := vl.Remove(v); !ok {
return scoreresult.New(StatusNotFound, "NotFound")
}
+ if vl.Len() == 0 {
+ return scoreresult.New(StatusIllegalArgument, "OnlyValidator")
+ }
return nil
} else {
return err
