Skip to content

Commit

Permalink
Align with ValidatorSet on PruneStates() (#525)
Browse files Browse the repository at this point in the history
* Align with ValidatorSet on `PruneStates()`

* Revert removing defer in the loop
  • Loading branch information
tnasu authored Dec 9, 2022
1 parent a25ada8 commit 7ba5191
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 8 additions & 10 deletions state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ func (store dbStore) PruneStates(from int64, to int64) error {
if err != nil {
return err
}
err = batch.Delete(calcVoterParamsKey(h))
if err != nil {
return err
}
err = batch.Delete(calcProofHashKey(h))
if err != nil {
return err
}
}

if keepParams[h] {
Expand Down Expand Up @@ -343,16 +351,6 @@ func (store dbStore) PruneStates(from int64, to int64) error {
}
}

err = batch.Delete(calcVoterParamsKey(h))
if err != nil {
return err
}

err = batch.Delete(calcProofHashKey(h))
if err != nil {
return err
}

err = batch.Delete(calcABCIResponsesKey(h))
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions state/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ func TestPruneStates(t *testing.T) {
require.Error(t, err, "abci height %v", h)
require.Equal(t, sm.ErrNoABCIResponsesForHeight{Height: h}, err)
}
_, voters, voterParams, proof, err := stateStore.LoadVoters(h, nil)
if expectVals[h] {
require.NotNil(t, voters)
require.NotNil(t, voterParams)
require.NotNil(t, proof)
} else {
require.Error(t, err, "validators height %v", h)
require.Equal(t, sm.ErrNoValSetForHeight{Height: h}, err)
}
}
})
}
Expand Down

0 comments on commit 7ba5191

Please sign in to comment.