This commit is contained in:
Callum Waters
2022-11-17 18:28:55 +01:00
parent 94aa1ca3ed
commit d0377e83a3
10 changed files with 41 additions and 41 deletions
+13 -6
View File
@@ -135,7 +135,7 @@ func (lss *FilePVLastSignState) CheckHRS(height int64, round int32, step int8) (
func (lss *FilePVLastSignState) Save() error {
outFile := lss.filePath
if outFile == "" {
panic("cannot save FilePVLastSignState: filePath not set")
return errors.New("cannot save FilePVLastSignState: filePath not set")
}
jsonBytes, err := tmjson.MarshalIndent(lss, "", " ")
if err != nil {
@@ -237,7 +237,9 @@ func LoadOrGenFilePV(keyFilePath, stateFilePath string) *FilePV {
pv = LoadFilePV(keyFilePath, stateFilePath)
} else {
pv = GenFilePV(keyFilePath, stateFilePath)
pv.Save()
if err := pv.Save(); err != nil {
panic(err)
}
}
return pv
}
@@ -273,16 +275,19 @@ func (pv *FilePV) SignProposal(chainID string, proposal *tmproto.Proposal) error
}
// Save persists the FilePV to disk.
func (pv *FilePV) Save() {
func (pv *FilePV) Save() error {
pv.Key.Save()
pv.LastSignState.Save()
return pv.LastSignState.Save()
}
// Reset resets all fields in the FilePV.
// NOTE: Unsafe!
func (pv *FilePV) Reset() {
pv.LastSignState.reset()
pv.Save()
err := pv.Save()
if err != nil {
panic(err)
}
}
// String returns a string representation of the FilePV.
@@ -411,7 +416,9 @@ func (pv *FilePV) signProposal(chainID string, proposal *tmproto.Proposal) error
if err != nil {
return err
}
pv.saveSigned(height, round, step, signBytes, sig)
if err := pv.saveSigned(height, round, step, signBytes, sig); err != nil {
return err
}
proposal.Signature = sig
return nil
}
+1 -1
View File
@@ -31,7 +31,7 @@ func TestGenLoadValidator(t *testing.T) {
height := int64(100)
privVal.LastSignState.Height = height
privVal.Save()
require.NoError(t, privVal.Save())
addr := privVal.GetAddress()
privVal = LoadFilePV(tempKeyFile.Name(), tempStateFile.Name())