Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store/v2): build the migration manager in the root store factory #22336

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6362846
confgi the migration manager in root factory
cool-develope Oct 22, 2024
e7bd885
minor fix
cool-develope Oct 22, 2024
3bb541b
add simple test
cool-develope Oct 23, 2024
1e6e4f1
small fix
cool-develope Oct 24, 2024
cb86a77
Merge branch 'main' into store/factory_migration
cool-develope Oct 24, 2024
31eb8fd
fix migration
cool-develope Oct 25, 2024
79d978b
Merge branch 'main' into store/factory_migration
cool-develope Oct 25, 2024
eb8029c
fix db close
cool-develope Oct 28, 2024
01a470e
Merge branch 'main' into store/factory_migration
cool-develope Oct 29, 2024
f3091f5
Merge branch 'main' into store/factory_migration
tac0turtle Dec 9, 2024
19c6da3
go mod change
tac0turtle Dec 9, 2024
f58431a
fix diff
tac0turtle Dec 9, 2024
4ef10b7
fix factory
tac0turtle Dec 9, 2024
b854054
Merge branch 'main' into store/factory_migration
tac0turtle Jan 2, 2025
ddaf4da
return error when version is not present
tac0turtle Jan 2, 2025
1b93050
Merge branch 'main' into store/factory_migration
tac0turtle Jan 5, 2025
03fdd2a
Merge branch 'main' into store/factory_migration
tac0turtle Jan 6, 2025
ae75111
fix build
tac0turtle Jan 6, 2025
a10a72f
minor touch up of build
tac0turtle Jan 6, 2025
5f2cb83
fixes
tac0turtle Jan 6, 2025
99a813a
refactor(store/v2): compatible with storev1 (#23201)
tac0turtle Jan 7, 2025
2e13d91
Merge branch 'main' into store/factory_migration
tac0turtle Jan 7, 2025
2b9419e
lint fixes
tac0turtle Jan 7, 2025
2106a3b
fix cometbft tests
tac0turtle Jan 8, 2025
010bc58
Merge branch 'main' into store/factory_migration
tac0turtle Jan 8, 2025
31a4aed
fix simapp tests
tac0turtle Jan 8, 2025
6ee0260
store fix
tac0turtle Jan 8, 2025
ba62dd5
revert make file changes
tac0turtle Jan 8, 2025
cb687e2
revert build file changes
tac0turtle Jan 8, 2025
e04b614
drop convert function
tac0turtle Jan 8, 2025
759cb53
fix lint
tac0turtle Jan 8, 2025
1c5b07d
Merge branch 'main' into store/factory_migration
tac0turtle Jan 8, 2025
76aeebe
fix bank failing test
tac0turtle Jan 8, 2025
f9da53b
fix store tests
tac0turtle Jan 8, 2025
4f8ca79
Merge branch 'main' into store/factory_migration
tac0turtle Jan 8, 2025
9a55795
Merge branch 'main' into store/factory_migration
tac0turtle Jan 9, 2025
b5b2fa0
fix go mod
tac0turtle Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions store/v2/commitment/iavl/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ func (e *Exporter) Close() error {

return nil
}

// EmptyExporter is a Exporter for an empty tree.
type EmptyExporter struct{}

// Next returns ExportDone.
func (e *EmptyExporter) Next() (*snapshotstypes.SnapshotIAVLItem, error) {
return nil, commitment.ErrorExportDone
}

// Close does nothing.
func (e *EmptyExporter) Close() error {
return nil
}
17 changes: 17 additions & 0 deletions store/v2/commitment/iavl/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (
// IavlTree is a wrapper around iavl.MutableTree.
type IavlTree struct {
tree *iavl.MutableTree
// it is only used for new store key during the migration process.
initialVersion uint64
}

// NewIavlTree creates a new IavlTree instance.
Expand Down Expand Up @@ -58,6 +60,17 @@ func (t *IavlTree) WorkingHash() []byte {

// LoadVersion loads the state at the given version.
func (t *IavlTree) LoadVersion(version uint64) error {
if t.initialVersion > 0 {
// If the initial version is set and the tree is empty,
// we don't need to load the version.
latestVersion, err := t.tree.GetLatestVersion()
if err != nil {
return err
}
if latestVersion == 0 {
return nil
}
}
return t.tree.LoadVersionForOverwriting(int64(version))
}

Expand Down Expand Up @@ -106,6 +119,7 @@ func (t *IavlTree) GetLatestVersion() (uint64, error) {
// SetInitialVersion sets the initial version of the database.
func (t *IavlTree) SetInitialVersion(version uint64) error {
t.tree.SetInitialVersion(version)
t.initialVersion = version
return nil
}

Expand All @@ -125,6 +139,9 @@ func (t *IavlTree) PausePruning(pause bool) {

// Export exports the tree exporter at the given version.
func (t *IavlTree) Export(version uint64) (commitment.Exporter, error) {
if version < t.initialVersion {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return &EmptyExporter{}, nil
}
tree, err := t.tree.GetImmutable(int64(version))
if err != nil {
return nil, err
Expand Down
11 changes: 7 additions & 4 deletions store/v2/commitment/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

const (
commitInfoKeyFmt = "c/%d" // c/<version>
latestVersionKey = "c/latest"
removedStoreKeyPrefix = "c/removed/" // c/removed/<version>/<store-name>
commitInfoKeyFmt = "s/%d" // c/<version>
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
latestVersionKey = "s/latest"
removedStoreKeyPrefix = "s/removed/" // c/removed/<version>/<store-name>
)

// MetadataStore is a store for metadata related to the commitment store.
Expand Down Expand Up @@ -69,7 +69,10 @@ func (m *MetadataStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)

cInfo := &proof.CommitInfo{}
if err := cInfo.Unmarshal(value); err != nil {
return nil, err
cInfo, err = proof.ConvertV1CommitInfo(value)
if err != nil {
return nil, err
}
}

return cInfo, nil
Expand Down
2 changes: 1 addition & 1 deletion store/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
go.uber.org/mock v0.5.0
golang.org/x/sync v0.8.0
google.golang.org/protobuf v1.35.1
)

require (
Expand Down Expand Up @@ -61,6 +62,5 @@ require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 1 addition & 4 deletions store/v2/migration/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,8 @@ func (m *Manager) Sync() error {
}

// Close closes the manager. It should be called after the migration is done.
// It will close the db and notify the snapshotsManager that the migration is done.
// It will notify the snapshotsManager that the migration is done.
func (m *Manager) Close() error {
if err := m.db.Close(); err != nil {
return fmt.Errorf("failed to close db: %w", err)
}
if m.stateCommitment != nil {
m.snapshotsManager.EndMigration(m.stateCommitment)
}
Expand Down
28 changes: 28 additions & 0 deletions store/v2/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

errors "cosmossdk.io/errors/v2"
storeerrors "cosmossdk.io/store/v2/errors"
v1types "cosmossdk.io/store/v2/proof/v1/types"
)

// Proof operation types
Expand Down Expand Up @@ -228,3 +229,30 @@ func InnerHash(left, right []byte) []byte {
h := sha256.Sum256(data)
return h[:]
}

func ConvertV1CommitInfo(value []byte) (*CommitInfo, error) {
v1CommitInfo := &v1types.CommitInfo{}
if err := v1CommitInfo.Unmarshal(value); err != nil {
return nil, err
}
cInfo := &CommitInfo{
Version: uint64(v1CommitInfo.Version),
StoreInfos: make([]StoreInfo, len(v1CommitInfo.StoreInfos)),
Timestamp: v1CommitInfo.Timestamp,
}
for i, v1StoreInfo := range v1CommitInfo.StoreInfos {
cInfo.StoreInfos[i] = StoreInfo{
Name: []byte(v1StoreInfo.Name),
CommitID: CommitID{
Version: uint64(v1StoreInfo.CommitId.Version),
Hash: v1StoreInfo.CommitId.Hash,
},
Structure: "iavl",
}
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
}

var err error
cInfo.CommitHash, _, err = cInfo.GetStoreProof([]byte{})

return cInfo, err
}
Loading
Loading