From 929803d6ccbbb25b05dd605ca50f3ea06905e359 Mon Sep 17 00:00:00 2001 From: cool-developer <51834436+cool-develope@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:55:55 -0400 Subject: [PATCH] chore(store/v2): load the CommitID when LoadVersion (#20776) --- store/v2/root/store.go | 6 +++++- store/v2/root/store_test.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/store/v2/root/store.go b/store/v2/root/store.go index e5543a91a2..ca02afdf32 100644 --- a/store/v2/root/store.go +++ b/store/v2/root/store.go @@ -243,7 +243,11 @@ func (s *Store) loadVersion(v uint64) error { s.commitHeader = nil // set lastCommitInfo explicitly s.t. Commit commits the correct version, i.e. v+1 - s.lastCommitInfo = &proof.CommitInfo{Version: v} + var err error + s.lastCommitInfo, err = s.stateCommitment.GetCommitInfo(v) + if err != nil { + return fmt.Errorf("failed to get commit info for version %d: %w", v, err) + } // if we're migrating, we need to start the migration process if s.isMigrating { diff --git a/store/v2/root/store_test.go b/store/v2/root/store_test.go index 3e50987ded..23e87cce53 100644 --- a/store/v2/root/store_test.go +++ b/store/v2/root/store_test.go @@ -459,7 +459,7 @@ func (s *RootStoreTestSuite) TestMultiStore_Pruning_SameHeightsTwice() { for v := uint64(1); v < numVersions-keepRecent; v++ { var err error checkErr := func() bool { - if err = s.rootStore.LoadVersion(v); err != nil { + if _, err = s.rootStore.StateAt(v); err != nil { return true } return false @@ -469,7 +469,7 @@ func (s *RootStoreTestSuite) TestMultiStore_Pruning_SameHeightsTwice() { } for v := (numVersions - keepRecent); v < numVersions; v++ { - err := s.rootStore.LoadVersion(v) + _, err := s.rootStore.StateAt(v) s.Require().NoError(err, "expected no error when loading height: %d", v) } @@ -710,7 +710,7 @@ func (s *RootStoreTestSuite) TestMultiStoreRestart() { s.Require().Equal([]byte(fmt.Sprintf("val%03d_%03d", 4, 3)), result, "value should be equal") } -func (s *RootStoreTestSuite) TestHashStableWithEmptyCommit() { +func (s *RootStoreTestSuite) TestHashStableWithEmptyCommitAndRestart() { err := s.rootStore.LoadLatestVersion() s.Require().Nil(err) @@ -739,4 +739,10 @@ func (s *RootStoreTestSuite) TestHashStableWithEmptyCommit() { s.Require().Nil(err) s.Require().Equal(uint64(2), latestVersion) s.Require().Equal(hash, cHash) + + // reload the store + s.Require().NoError(s.rootStore.LoadLatestVersion()) + lastCommitID, err = s.rootStore.LastCommitID() + s.Require().NoError(err) + s.Require().Equal(lastCommitID.Hash, hash) }