From 5b62578193ec1d3fe56c46e91aa7b770e12cec24 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 17 Nov 2022 11:27:46 +0530 Subject: [PATCH 1/5] fix: return err instead of empty values when pruned height is queried --- store/iavl/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/iavl/store.go b/store/iavl/store.go index 4b15cf73ea1..df93a998888 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -89,7 +89,7 @@ func UnsafeNewStore(tree *iavl.MutableTree) *Store { // Any mutable operations executed will result in a panic. func (st *Store) GetImmutable(version int64) (*Store, error) { if !st.VersionExists(version) { - return &Store{tree: &immutableTree{&iavl.ImmutableTree{}}}, nil + return &Store{tree: &immutableTree{&iavl.ImmutableTree{}}}, fmt.Errorf("version mismatch on immutable IAVL tree; version does not exist. Version has either been pruned, or is for a future block height") } iTree, err := st.tree.GetImmutable(version) From 2c10d80890ac2b4b18eef403fbe90fe071d01239 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 17 Nov 2022 11:33:14 +0530 Subject: [PATCH 2/5] fix tests --- store/iavl/store_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index b9c9e25ad43..a2613aaef83 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -119,7 +119,7 @@ func TestGetImmutable(t *testing.T) { require.Nil(t, err) _, err = store.GetImmutable(cID.Version + 1) - require.NoError(t, err) + require.Error(t, err) newStore, err := store.GetImmutable(cID.Version - 1) require.NoError(t, err) @@ -284,7 +284,7 @@ func TestIAVLReverseIterator(t *testing.T) { iavlStore.Set([]byte{0x00, 0x02}, []byte("0 2")) iavlStore.Set([]byte{0x01}, []byte("1")) - var testReverseIterator = func(t *testing.T, start []byte, end []byte, expected []string) { + testReverseIterator := func(t *testing.T, start []byte, end []byte, expected []string) { iter := iavlStore.ReverseIterator(start, end) var i int for i = 0; iter.Valid(); iter.Next() { From f84dc3635d36a7b5732d5da522630b8800d4fa70 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 17 Nov 2022 13:37:50 +0530 Subject: [PATCH 3/5] fix more tests --- baseapp/baseapp_test.go | 3 +-- store/rootmulti/store_test.go | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index df891e13693..3a64ef93346 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -431,7 +431,7 @@ func TestLoadVersionPruning(t *testing.T) { for _, v := range []int64{1, 2, 4} { _, err = app.cms.CacheMultiStoreWithVersion(v) - require.NoError(t, err) + require.Error(t, err) } for _, v := range []int64{3, 5, 6, 7} { @@ -1292,7 +1292,6 @@ func TestTxGasLimits(t *testing.T) { return newCtx, nil }) - } routerOpt := func(bapp *BaseApp) { diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index e2fe5835727..e754b3b4df4 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -84,9 +84,9 @@ func TestCacheMultiStoreWithVersion(t *testing.T) { cID := ms.Commit() require.Equal(t, int64(1), cID.Version) - // require no failure when given an invalid or pruned version + // require error when given an invalid or pruned version _, err = ms.CacheMultiStoreWithVersion(cID.Version + 1) - require.NoError(t, err) + require.Error(t, err) // require a valid version can be cache-loaded cms, err := ms.CacheMultiStoreWithVersion(cID.Version) @@ -314,7 +314,6 @@ func TestParsePath(t *testing.T) { require.NoError(t, err) require.Equal(t, substore, "bang") require.Equal(t, subsubpath, "/baz") - } func TestMultiStoreRestart(t *testing.T) { @@ -479,7 +478,7 @@ func TestMultiStore_Pruning(t *testing.T) { saved []int64 }{ {"prune nothing", 10, types.PruneNothing, nil, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, - {"prune everything", 10, types.PruneEverything, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{10}}, + {"prune everything", 10, types.PruneEverything, []int64{1, 2, 3, 4, 5, 6, 7}, []int64{8, 9, 10}}, {"prune some; no batch", 10, types.NewPruningOptions(2, 3, 1), []int64{1, 2, 4, 5, 7}, []int64{3, 6, 8, 9, 10}}, {"prune some; small batch", 10, types.NewPruningOptions(2, 3, 3), []int64{1, 2, 4, 5}, []int64{3, 6, 7, 8, 9, 10}}, {"prune some; large batch", 10, types.NewPruningOptions(2, 3, 11), nil, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, @@ -499,12 +498,12 @@ func TestMultiStore_Pruning(t *testing.T) { for _, v := range tc.saved { _, err := ms.CacheMultiStoreWithVersion(v) - require.NoError(t, err, "expected error when loading height: %d", v) + require.NoError(t, err, "expected no error when loading height: %d", v) } for _, v := range tc.deleted { _, err := ms.CacheMultiStoreWithVersion(v) - require.NoError(t, err, "expected error when loading height: %d", v) + require.Error(t, err, "expected error when loading height: %d", v) } }) } From 33e7ce3b63e523ea8c27329c7bcb9a6811d41a29 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 17 Nov 2022 14:05:26 +0530 Subject: [PATCH 4/5] final fixes --- store/rootmulti/store_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index a3cd9a83313..3bb00601976 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -560,7 +560,7 @@ func TestMultiStore_PruningRestart(t *testing.T) { for _, v := range pruneHeights { _, err := ms.CacheMultiStoreWithVersion(v) - require.NoError(t, err, "expected error when loading height: %d", v) + require.Error(t, err, "expected error when loading height: %d", v) } } From 8c354680753ced2ae5fdc512db7fd59fb6a3b1c4 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 17 Nov 2022 14:10:34 +0530 Subject: [PATCH 5/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 627045e2f2f..85e695a3500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#13896](https://github.com/cosmos/cosmos-sdk/pull/13896) Queries on pruned height returns error instead of empty values. * (deps) Bump Tendermint version to [v0.34.23](https://github.com/tendermint/tendermint/releases/tag/v0.34.23). * (deps) Bump IAVL version to [v0.19.4](https://github.com/cosmos/iavl/releases/tag/v0.19.4).