Skip to content

Commit

Permalink
change initial version to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed May 31, 2024
1 parent ac49374 commit 214605b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion store/v2/commitment/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions store/v2/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion store/v2/root/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 214605b

Please sign in to comment.