move avm cache puts after error checking and catch err on status unmarshalling

This commit is contained in:
bb-2 2020-05-06 08:49:44 -04:00
parent c8a025e1d6
commit d35834c4e5
1 changed files with 6 additions and 5 deletions

View File

@ -90,7 +90,9 @@ func (s *State) Status(id ids.ID) (choices.Status, error) {
}
var status choices.Status
s.Codec.Unmarshal(bytes, &status)
if err := s.Codec.Unmarshal(bytes, &status); err != nil {
return choices.Unknown, err
}
s.Cache.Put(id, status)
return status, nil
@ -103,12 +105,12 @@ func (s *State) SetStatus(id ids.ID, status choices.Status) error {
return s.DB.Delete(id.Bytes())
}
s.Cache.Put(id, status)
bytes, err := s.Codec.Marshal(status)
if err != nil {
return err
}
s.Cache.Put(id, status)
return s.DB.Put(id.Bytes(), bytes)
}
@ -142,12 +144,11 @@ func (s *State) SetIDs(id ids.ID, idSlice []ids.ID) error {
return s.DB.Delete(id.Bytes())
}
s.Cache.Put(id, idSlice)
bytes, err := s.Codec.Marshal(idSlice)
if err != nil {
return err
}
s.Cache.Put(id, idSlice)
return s.DB.Put(id.Bytes(), bytes)
}