diff --git a/store/commitment/iavl/tree.go b/store/commitment/iavl/tree.go index c9e804f43aae..dc559152c171 100644 --- a/store/commitment/iavl/tree.go +++ b/store/commitment/iavl/tree.go @@ -75,6 +75,12 @@ func (t *IavlTree) GetLatestVersion() uint64 { return uint64(t.tree.Version()) } +// SetInitialVersion sets the initial version of the database. +func (t *IavlTree) SetInitialVersion(version uint64) error { + t.tree.SetInitialVersion(version) + return nil +} + // Prune prunes all versions up to and including the provided version. func (t *IavlTree) Prune(version uint64) error { return t.tree.DeleteVersionsTo(int64(version)) diff --git a/store/commitment/store.go b/store/commitment/store.go index ad391b1df3a2..1a716ac15f43 100644 --- a/store/commitment/store.go +++ b/store/commitment/store.go @@ -116,6 +116,16 @@ func (c *CommitStore) Commit() ([]store.StoreInfo, error) { return storeInfos, nil } +func (c *CommitStore) SetInitialVersion(version uint64) error { + for _, tree := range c.multiTrees { + if err := tree.SetInitialVersion(version); err != nil { + return err + } + } + + return nil +} + func (c *CommitStore) GetProof(storeKey string, version uint64, key []byte) (*ics23.CommitmentProof, error) { tree, ok := c.multiTrees[storeKey] if !ok { diff --git a/store/commitment/tree.go b/store/commitment/tree.go index 67acffdf3099..7e41e03e5baa 100644 --- a/store/commitment/tree.go +++ b/store/commitment/tree.go @@ -20,6 +20,7 @@ type Tree interface { WorkingHash() []byte LoadVersion(version uint64) error Commit() ([]byte, error) + SetInitialVersion(version uint64) error GetProof(version uint64, key []byte) (*ics23.CommitmentProof, error) Prune(version uint64) error Export(version uint64) (Exporter, error) diff --git a/store/database.go b/store/database.go index 498e815a8a6d..992dd3db4684 100644 --- a/store/database.go +++ b/store/database.go @@ -72,6 +72,7 @@ type Committer interface { GetLatestVersion() (uint64, error) LoadVersion(targetVersion uint64) error Commit() ([]StoreInfo, error) + SetInitialVersion(version uint64) error GetProof(storeKey string, version uint64, key []byte) (*ics23.CommitmentProof, error) // Prune attempts to prune all versions up to and including the provided diff --git a/store/root/store.go b/store/root/store.go index 453b81b0a0a9..17397af684fd 100644 --- a/store/root/store.go +++ b/store/root/store.go @@ -116,11 +116,7 @@ func (s *Store) SetMetrics(m metrics.Metrics) { func (s *Store) SetInitialVersion(v uint64) error { s.initialVersion = v - // TODO(bez): Call SetInitialVersion on s.stateCommitment. - // - // Ref: https://github.com/cosmos/cosmos-sdk/issues/18597 - - return nil + return s.stateCommitment.SetInitialVersion(v) } // GetSCStore returns the store's state commitment (SC) backend.