From 214605bec151f1145fe9b3c8e21432f7e84cf725 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 31 May 2024 18:33:42 +0700 Subject: [PATCH] change initial version to 0 --- store/v2/commitment/store.go | 2 +- store/v2/root/store.go | 13 +++++++++---- store/v2/root/store_test.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/store/v2/commitment/store.go b/store/v2/commitment/store.go index e9cf2c0c6375..8aa527d5ecac 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -202,7 +202,7 @@ func (c *CommitStore) Commit(version uint64) (*proof.CommitInfo, error) { // will be larger than the RMS's metadata, when the block is replayed, we // should avoid committing that iavl store again. var commitID proof.CommitID - if tree.GetLatestVersion() >= version { + if tree.GetLatestVersion() >= version && version > 0 { commitID.Version = version commitID.Hash = tree.Hash() } else { diff --git a/store/v2/root/store.go b/store/v2/root/store.go index 8c77cd0d7570..43d0c9e6bf48 100644 --- a/store/v2/root/store.go +++ b/store/v2/root/store.go @@ -72,7 +72,7 @@ func New( ) (store.RootStore, error) { return &Store{ logger: logger.With("module", "root_store"), - initialVersion: 1, + initialVersion: 0, stateStorage: ss, stateCommitment: sc, pruningManager: pm, @@ -389,7 +389,7 @@ func (s *Store) writeSC(cs *corestore.Changeset) error { } var previousHeight, version uint64 - if s.lastCommitInfo.GetVersion() == 0 && s.initialVersion > 1 { + if s.lastCommitInfo.GetVersion() == 0 && s.initialVersion > 0 { // This case means that no commit has been made in the store, we // start from initialVersion. version = s.initialVersion @@ -399,11 +399,16 @@ func (s *Store) writeSC(cs *corestore.Changeset) error { // 1. There was already a previous commit in the store, in which case we // increment the version from there. // 2. There was no previous commit, and initial version was not set, in which - // case we start at version 1. + // case we start at version 0. previousHeight = s.lastCommitInfo.GetVersion() - version = previousHeight + 1 + if previousHeight == 0 { + version = previousHeight + } else { + version = previousHeight + 1 + } } + fmt.Println(version) s.lastCommitInfo = s.stateCommitment.WorkingCommitInfo(version) return nil diff --git a/store/v2/root/store_test.go b/store/v2/root/store_test.go index a0766c249561..46e867a7d17a 100644 --- a/store/v2/root/store_test.go +++ b/store/v2/root/store_test.go @@ -251,7 +251,7 @@ func (s *RootStoreTestSuite) TestCommit() { // ensure latest version is updated lv, err = s.rootStore.GetLatestVersion() s.Require().NoError(err) - s.Require().Equal(uint64(1), lv) + s.Require().Equal(uint64(0), lv) // perform reads on the updated root store _, ro, err := s.rootStore.StateLatest()